diff --git a/LibreNMS/Data/Source/NetSnmpQuery.php b/LibreNMS/Data/Source/NetSnmpQuery.php index dfa73927bb..ab94ff917c 100644 --- a/LibreNMS/Data/Source/NetSnmpQuery.php +++ b/LibreNMS/Data/Source/NetSnmpQuery.php @@ -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; } diff --git a/LibreNMS/Data/Source/SnmpQueryInterface.php b/LibreNMS/Data/Source/SnmpQueryInterface.php index fa9d8025d0..c0faaf52f1 100644 --- a/LibreNMS/Data/Source/SnmpQueryInterface.php +++ b/LibreNMS/Data/Source/SnmpQueryInterface.php @@ -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 diff --git a/app/Console/Commands/SnmpFetch.php b/app/Console/Commands/SnmpFetch.php index a836ec8937..c1763addd6 100644 --- a/app/Console/Commands/SnmpFetch.php +++ b/app/Console/Commands/SnmpFetch.php @@ -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')); diff --git a/tests/Mocks/SnmpQueryMock.php b/tests/Mocks/SnmpQueryMock.php index b208832834..646e23172d 100644 --- a/tests/Mocks/SnmpQueryMock.php +++ b/tests/Mocks/SnmpQueryMock.php @@ -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; }