mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
feature: Allow snmpget in os discovery yaml (#7587)
* feature: Allow snmpget in os discovery yaml Re-submit after release * Remove extra trim in discovery and in snmp_get. also trim() always returns a string, so is_string() check is a waste of cpu cycles.
This commit is contained in:
committed by
Neil Lathwood
parent
771ff3669c
commit
0d07f85257
@@ -231,12 +231,22 @@ function snmp_get_multi_oid($device, $oids, $options = '-OUQn', $mib = null, $mi
|
||||
$data = trim(external_exec($cmd));
|
||||
|
||||
$array = array();
|
||||
$oid = '';
|
||||
foreach (explode("\n", $data) as $entry) {
|
||||
list($oid,$value) = explode('=', $entry, 2);
|
||||
$oid = trim($oid);
|
||||
$value = trim($value, "\" \n\r");
|
||||
if (!strstr($value, 'at this OID') && isset($oid)) {
|
||||
$array[$oid] = $value;
|
||||
if (str_contains($entry, '=')) {
|
||||
list($oid,$value) = explode('=', $entry, 2);
|
||||
$oid = trim($oid);
|
||||
$value = trim($value, "\" \n\r");
|
||||
if (!strstr($value, 'at this OID') && isset($oid)) {
|
||||
$array[$oid] = $value;
|
||||
}
|
||||
} else {
|
||||
if (isset($array[$oid])) {
|
||||
// if appending, add a line return
|
||||
$array[$oid] .= PHP_EOL . $entry;
|
||||
} else {
|
||||
$array[$oid] = $entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,11 +263,10 @@ function snmp_get($device, $oid, $options = null, $mib = null, $mibdir = null)
|
||||
}
|
||||
|
||||
$cmd = gen_snmpget_cmd($device, $oid, $options, $mib, $mibdir);
|
||||
$data = trim(external_exec($cmd));
|
||||
$data = trim($data, "\" \n\r");
|
||||
$data = trim(external_exec($cmd), "\" \n\r");
|
||||
|
||||
recordSnmpStatistic('snmpget', $time_start);
|
||||
if (is_string($data) && (preg_match('/(No Such Instance|No Such Object|No more variables left|Authentication failure)/i', $data))) {
|
||||
if (preg_match('/(No Such Instance|No Such Object|No more variables left|Authentication failure)/i', $data)) {
|
||||
return false;
|
||||
} elseif ($data || $data === '0') {
|
||||
return $data;
|
||||
|
Reference in New Issue
Block a user