mirror of
https://github.com/librenms/librenms.git
synced 2024-09-21 10:28:13 +00:00
SnmpQuery walk multiple oids (#14015)
Makes it easier to walk select oids from a large table. Walking oids with different indexes will break some logic and is undefined so far.
This commit is contained in:
parent
53a892acad
commit
82be234bae
@ -243,7 +243,7 @@ class NetSnmpQuery implements SnmpQueryInterface
|
||||
*/
|
||||
public function walk($oid): SnmpResponse
|
||||
{
|
||||
return $this->exec('snmpwalk', $this->parseOid($oid));
|
||||
return $this->execMultiple('snmpwalk', $this->parseOid($oid));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -330,6 +330,19 @@ class NetSnmpQuery implements SnmpQueryInterface
|
||||
}
|
||||
}
|
||||
|
||||
private function execMultiple(string $command, array $oids): ?SnmpResponse
|
||||
{
|
||||
$combined = null;
|
||||
|
||||
foreach ($oids as $oid) {
|
||||
$response = $this->exec($command, [$oid]);
|
||||
|
||||
$combined = $combined ? $combined->append($response) : $response;
|
||||
}
|
||||
|
||||
return $combined;
|
||||
}
|
||||
|
||||
private function exec(string $command, array $oids): SnmpResponse
|
||||
{
|
||||
$measure = Measurement::start($command);
|
||||
|
@ -232,4 +232,14 @@ class SnmpResponse
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function append(SnmpResponse $response): SnmpResponse
|
||||
{
|
||||
$this->raw .= $response->raw;
|
||||
$this->stderr .= $response->stderr;
|
||||
$this->exitCode = $this->exitCode ?: $response->exitCode;
|
||||
$this->errorMessage = $this->errorMessage ?: $response->errorMessage;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user