Consolidate and improve snmptranslate usage (#14567)

* Consolidate and improve snmptranslate usage

* Fix style

* lint fixes

* fix typo

* allow multiple mib directories

* Only add mib if it is not already set

* oid first, in case we have key length issues

* if there is a full oid, don't add other mibs

* debug in ci

* more debug in ci

* better debug in ci

* remove debug

* Use numeric index

* revert dlink change

* Don't add -On twice

* unit tests and hopefully better heuristics

* remove dump and add one more set of tests

* style fixes

* handle bad input in old functions

* shortcut whole snmp_translate function
This commit is contained in:
Tony Murray
2022-11-07 12:00:47 -06:00
committed by GitHub
parent 70524b1e9d
commit 0801af7a81
14 changed files with 294 additions and 158 deletions

View File

@@ -56,19 +56,23 @@ class SnmpFetch extends LnmsCommand
}
$return = 0;
$type = $this->option('type');
$output = $this->option('output') ?: ($type == 'walk' ? 'table' : 'value');
foreach ($device_ids as $device_id) {
DeviceCache::setPrimary($device_id);
$this->info(DeviceCache::getPrimary()->displayName() . ':');
$type = $this->option('type');
$output = $this->option('output')
?: ($type == 'walk' ? 'table' : 'value');
/** @var \LibreNMS\Data\Source\SnmpResponse $res */
$res = SnmpQuery::numeric($this->option('numeric'))
->$type($this->argument('oid'));
if ($type == 'translate') {
$this->line($res);
return 0;
}
if (! $res->isValid()) {
$this->warn(trans('commands.snmp:fetch.failed'));
$this->line($res->getErrorMessage());