feature: Implement snmp_getnext() (#7678)

find correct path to snmpgetnext (will do the same for others later)
fix undefined index in get_mib_dir()
This commit is contained in:
Tony Murray
2017-11-08 09:15:49 -06:00
committed by Neil Lathwood
parent 24a0ee97a7
commit acb1de5772
3 changed files with 45 additions and 9 deletions

View File

@@ -2003,6 +2003,8 @@ function initStats()
$snmp_stats = array(
'snmpget' => 0,
'snmpget_sec' => 0.0,
'snmpgetnext' => 0,
'snmpgetnext_sec' => 0.0,
'snmpwalk' => 0,
'snmpwalk_sec' => 0.0,
);
@@ -2036,9 +2038,11 @@ function printStats()
global $snmp_stats, $db_stats;
printf(
"SNMP: Get[%d/%.2fs] Walk [%d/%.2fs]\n",
"SNMP: Get[%d/%.2fs] Getnext [%d/%.2fs] Walk [%d/%.2fs]\n",
$snmp_stats['snmpget'],
$snmp_stats['snmpget_sec'],
$snmp_stats['snmpgetnext'],
$snmp_stats['snmpgetnext_sec'],
$snmp_stats['snmpwalk'],
$snmp_stats['snmpwalk_sec']
);

View File

@@ -46,7 +46,7 @@ if ($config['rrdgraph_real_95th']) {
}
// make sure we have full path to binaries in case PATH isn't set
foreach (array('fping', 'fping6') as $bin) {
foreach (array('fping', 'fping6', 'snmpgetnext') as $bin) {
if (!is_executable(Config::get($bin))) {
Config::set($bin, locate_binary($bin), true, $bin, "Path to $bin", 'external', 'paths');
}

View File

@@ -15,6 +15,7 @@
* the source code distribution for details.
*/
use LibreNMS\Config;
use LibreNMS\RRD\RrdDefinition;
function string_to_oid($string)
@@ -52,14 +53,16 @@ function get_mib_dir($device)
$extra[] = $config['mib_dir'] . '/' . $device['os'];
}
if (isset($device['os_group']) && file_exists($config['mib_dir'] . '/' . $device['os_group'])) {
$extra[] = $config['mib_dir'] . '/' . $device['os_group'];
}
if (isset($device['os_group'])) {
if (file_exists($config['mib_dir'] . '/' . $device['os_group'])) {
$extra[] = $config['mib_dir'] . '/' . $device['os_group'];
}
if (isset($config['os_groups'][$device['os_group']]['mib_dir'])) {
if (is_array($config['os_groups'][$device['os_group']]['mib_dir'])) {
foreach ($config['os_groups'][$device['os_group']]['mib_dir'] as $k => $dir) {
$extra[] = $config['mib_dir'] . '/' . $dir;
if (isset($config['os_groups'][$device['os_group']]['mib_dir'])) {
if (is_array($config['os_groups'][$device['os_group']]['mib_dir'])) {
foreach ($config['os_groups'][$device['os_group']]['mib_dir'] as $k => $dir) {
$extra[] = $config['mib_dir'] . '/' . $dir;
}
}
}
}
@@ -275,6 +278,35 @@ function snmp_get($device, $oid, $options = null, $mib = null, $mibdir = null)
}
}//end snmp_get()
/**
* Calls snmpgetnext. Getnext returns the next oid after the specified oid.
* For example instead of get sysName.0, you can getnext sysName to get the .0 value.
*
* @param array $device Target device
* @param string $oid The oid to getnext
* @param string $options Options to pass to snmpgetnext (-Oqv for example)
* @param string $mib The MIB to use
* @param string $mibdir Optional mib directory to search
* @return string|false the output or false if the data could not be fetched
*/
function snmp_getnext($device, $oid, $options = null, $mib = null, $mibdir = null)
{
$time_start = microtime(true);
$snmpcmd = Config::get('snmpgetnext');
$cmd = gen_snmp_cmd($snmpcmd, $device, $oid, $options, $mib, $mibdir);
$data = trim(external_exec($cmd), "\" \n\r");
recordSnmpStatistic('snmpgetnext', $time_start);
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;
}
return false;
}
/**
* @param $device
* @return bool