mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
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:
@@ -33,7 +33,7 @@ use Illuminate\Support\Str;
|
||||
use LibreNMS\Data\Source\NetSnmpQuery;
|
||||
use LibreNMS\Data\Source\SnmpQueryInterface;
|
||||
use LibreNMS\Data\Source\SnmpResponse;
|
||||
use LibreNMS\Device\YamlDiscovery;
|
||||
use LibreNMS\Util\Oid;
|
||||
use Log;
|
||||
|
||||
class SnmpQueryMock implements SnmpQueryInterface
|
||||
@@ -101,7 +101,7 @@ class SnmpQueryMock implements SnmpQueryInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function translate(string $oid, ?string $mib = null): SnmpResponse
|
||||
public function translate(string $oid, ?string $mib = null): string
|
||||
{
|
||||
// call real snmptranslate
|
||||
$options = $this->options;
|
||||
@@ -288,15 +288,15 @@ class SnmpQueryMock implements SnmpQueryInterface
|
||||
private function outputLine(string $oid, string $num_oid, string $type, string $data): string
|
||||
{
|
||||
if ($type == 6) {
|
||||
$data = $this->numeric ? ".$data" : $this->translate($data, $this->extractMib($oid))->value();
|
||||
$data = $this->numeric ? ".$data" : $this->translate($data, $this->extractMib($oid));
|
||||
}
|
||||
|
||||
if ($this->numeric) {
|
||||
return "$num_oid = $data";
|
||||
}
|
||||
|
||||
if (! empty($oid) && YamlDiscovery::oidIsNumeric($oid)) {
|
||||
$oid = $this->translate($oid)->value();
|
||||
if (! empty($oid) && Oid::isNumeric($oid)) {
|
||||
$oid = $this->translate($oid);
|
||||
}
|
||||
|
||||
return "$oid = $data";
|
||||
@@ -332,7 +332,7 @@ class SnmpQueryMock implements SnmpQueryInterface
|
||||
return '1.3.6.1.4.1.6574.1.1.0';
|
||||
}
|
||||
|
||||
if (YamlDiscovery::oidIsNumeric($oid)) {
|
||||
if (Oid::isNumeric($oid)) {
|
||||
return ltrim($oid, '.');
|
||||
}
|
||||
|
||||
@@ -342,7 +342,7 @@ class SnmpQueryMock implements SnmpQueryInterface
|
||||
}
|
||||
|
||||
$number = NetSnmpQuery::make()->mibDir($this->mibDir)
|
||||
->options(array_merge($options, $this->options))->numeric()->translate($oid)->value();
|
||||
->options(array_merge($options, $this->options))->numeric()->translate($oid);
|
||||
|
||||
if (empty($number)) {
|
||||
throw new Exception('Could not translate oid: ' . $oid . PHP_EOL);
|
||||
|
Reference in New Issue
Block a user