refactor: Collection and output of db and snmp stats (#5049)

This commit is contained in:
Tony Murray
2016-11-23 00:57:19 -06:00
committed by Neil Lathwood
parent 6708c7cb81
commit db240cb4eb
10 changed files with 162 additions and 108 deletions

View File

@@ -192,7 +192,7 @@ function gen_snmp_cmd($cmd, $device, $oids, $options = null, $mib = null, $mibdi
function snmp_get_multi($device, $oids, $options = '-OQUs', $mib = null, $mibdir = null)
{
global $runtime_stats;
$time_start = microtime(true);
if (is_array($oids)) {
$oids = implode(' ', $oids);
@@ -201,7 +201,7 @@ function snmp_get_multi($device, $oids, $options = '-OQUs', $mib = null, $mibdir
$cmd = gen_snmpget_cmd($device, $oids, $options, $mib, $mibdir);
$data = trim(external_exec($cmd));
$runtime_stats['snmpget']++;
$array = array();
foreach (explode("\n", $data) as $entry) {
list($oid,$value) = explode('=', $entry, 2);
@@ -213,12 +213,13 @@ function snmp_get_multi($device, $oids, $options = '-OQUs', $mib = null, $mibdir
}
}
recordSnmpStatistic('snmpget', $time_start);
return $array;
}//end snmp_get_multi()
function snmp_get_multi_oid($device, $oids, $options = '-OUQn', $mib = null, $mibdir = null)
{
global $runtime_stats;
$time_start = microtime(true);
if (is_array($oids)) {
$oids = implode(' ', $oids);
@@ -227,7 +228,6 @@ function snmp_get_multi_oid($device, $oids, $options = '-OUQn', $mib = null, $mi
$cmd = gen_snmpget_cmd($device, $oids, $options, $mib, $mibdir);
$data = trim(external_exec($cmd));
$runtime_stats['snmpget']++;
$array = array();
foreach (explode("\n", $data) as $entry) {
list($oid,$value) = explode('=', $entry, 2);
@@ -238,12 +238,13 @@ function snmp_get_multi_oid($device, $oids, $options = '-OUQn', $mib = null, $mi
}
}
recordSnmpStatistic('snmpget', $time_start);
return $array;
}//end snmp_get_multi_oid()
function snmp_get($device, $oid, $options = null, $mib = null, $mibdir = null)
{
global $runtime_stats;
$time_start = microtime(true);
if (strstr($oid, ' ')) {
echo report_this_text("snmp_get called for multiple OIDs: $oid");
@@ -252,8 +253,7 @@ 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));
$runtime_stats['snmpget']++;
recordSnmpStatistic('snmpget', $time_start);
if (is_string($data) && (preg_match('/(No Such Instance|No Such Object|No more variables left|Authentication failure)/i', $data))) {
return false;
} elseif ($data || $data === '0') {
@@ -266,7 +266,7 @@ function snmp_get($device, $oid, $options = null, $mib = null, $mibdir = null)
function snmp_walk($device, $oid, $options = null, $mib = null, $mibdir = null)
{
global $runtime_stats;
$time_start = microtime(true);
$cmd = gen_snmpwalk_cmd($device, $oid, $options, $mib, $mibdir);
$data = trim(external_exec($cmd));
@@ -285,8 +285,7 @@ function snmp_walk($device, $oid, $options = null, $mib = null, $mibdir = null)
}
}
$runtime_stats['snmpwalk']++;
recordSnmpStatistic('snmpwalk', $time_start);
return $data;
}//end snmp_walk()