SnmpQuery numeric accept a boolean (#14565)

This commit is contained in:
Tony Murray
2022-11-02 18:50:46 -05:00
committed by GitHub
parent bd4c2d70fb
commit 0c365d08e3
4 changed files with 9 additions and 11 deletions

View File

@@ -188,9 +188,11 @@ class NetSnmpQuery implements SnmpQueryInterface
/**
* Output all OIDs numerically
*/
public function numeric(): SnmpQueryInterface
public function numeric(bool $numeric = true): SnmpQueryInterface
{
$this->options = array_merge($this->options, ['-On']);
$this->options = $numeric
? array_merge($this->options, ['-On'])
: array_diff($this->options, ['-On']);
return $this;
}

View File

@@ -73,7 +73,7 @@ interface SnmpQueryInterface
/**
* Output all OIDs numerically
*/
public function numeric(): SnmpQueryInterface;
public function numeric(bool $numeric = true): SnmpQueryInterface;
/**
* Hide MIB in output

View File

@@ -65,13 +65,9 @@ class SnmpFetch extends LnmsCommand
$output = $this->option('output')
?: ($type == 'walk' ? 'table' : 'value');
$query = SnmpQuery::make();
if ($this->option('numeric')) {
$query->numeric();
}
/** @var \LibreNMS\Data\Source\SnmpResponse $res */
$res = $query->$type($this->argument('oid'));
$res = SnmpQuery::numeric($this->option('numeric'))
->$type($this->argument('oid'));
if (! $res->isValid()) {
$this->warn(trans('commands.snmp:fetch.failed'));

View File

@@ -130,9 +130,9 @@ class SnmpQueryMock implements SnmpQueryInterface
return $this;
}
public function numeric(): SnmpQueryInterface
public function numeric(bool $numeric = true): SnmpQueryInterface
{
$this->numeric = true;
$this->numeric = $numeric;
return $this;
}