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:
Tony Murray 2022-06-07 02:04:32 -05:00 committed by GitHub
parent 53a892acad
commit 82be234bae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -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);

View File

@ -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;
}
}