mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
refactor: Use one snmpget during os discovery (#7566)
Use only one snmpget to fetch sysObjectId and sysDescr fix multiline data in snmp_get_multi_oid() add snmp_get_multi_oid() to mock.snmp.inc.php
This commit is contained in:
committed by
Neil Lathwood
parent
090157779d
commit
a93bb6635d
@@ -227,6 +227,36 @@ function snmp_get($device, $oid, $options = null, $mib = null, $mibdir = null)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function snmp_get_multi_oid($device, $oids, $options = '-OUQn', $mib = null, $mibdir = null)
|
||||
{
|
||||
if (!is_array($oids)) {
|
||||
$oids = explode(' ', $oids);
|
||||
}
|
||||
|
||||
$data = array();
|
||||
foreach ($oids as $index => $oid) {
|
||||
if (str_contains($options, 'n')) {
|
||||
$oid_name = '.' . snmp_translate_number($oid, $mib, $mibdir);
|
||||
$val = snmp_get($device, $oid_name, $options, $mib, $mibdir);
|
||||
} elseif (str_contains($options, 's')
|
||||
&& str_contains($oid, '::')) {
|
||||
$tmp = explode('::', $oid);
|
||||
$oid_name = $tmp[1];
|
||||
$val = snmp_get($device, $oid, $options, $mib, $mibdir);
|
||||
} else {
|
||||
$oid_name = $oid;
|
||||
$val = snmp_get($device, $oid, $options, $mib, $mibdir);
|
||||
}
|
||||
|
||||
if ($val !== false) {
|
||||
$data[$oid_name] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
function snmp_walk($device, $oid, $options = null, $mib = null, $mibdir = null)
|
||||
{
|
||||
$community = $device['community'];
|
||||
|
Reference in New Issue
Block a user