feature: Added snmp_check() to decide if a device is up/down for snmp #5946 (#5948)

* feature: Added snmp_check() to decide if a device is up/down for snmp #5946

* added missing line

* Update snmp.inc.php
This commit is contained in:
Neil Lathwood
2017-02-23 22:47:18 +00:00
committed by GitHub
parent fad5aca1b7
commit 92433f3511
2 changed files with 30 additions and 8 deletions

View File

@ -557,15 +557,16 @@ function isSNMPable($device)
{
global $config;
$pos = snmp_get($device, "sysObjectID.0", "-Oqv", "SNMPv2-MIB");
if (empty($pos)) {
// Support for Hikvision
$pos = snmp_get($device, "SNMPv2-SMI::enterprises.39165.1.1.0", "-Oqv", "SNMPv2-MIB");
}
if ($pos === '' || $pos === false) {
return false;
} else {
$pos = snmp_check($device);
if ($pos === true) {
return true;
} else {
$pos = snmp_get($device, "sysObjectID.0", "-Oqv", "SNMPv2-MIB");
if ($pos === '' || $pos === false) {
return false;
} else {
return true;
}
}
}

View File

@ -257,6 +257,27 @@ function snmp_get($device, $oid, $options = null, $mib = null, $mibdir = null)
}
}//end snmp_get()
/**
* @param $device
* @return bool
*/
function snmp_check($device)
{
$time_start = microtime(true);
$oid = '.1.3.6.1.2.1.1.2.0';
$options = '-Oqvn';
$cmd = gen_snmpget_cmd($device, $oid, $options);
exec($cmd, $data, $code);
d_echo("SNMP Check response code: $code".PHP_EOL);
recordSnmpStatistic('snmpget', $time_start);
if ($code === 0) {
return true;
}
return false;
}//end snmp_check()
function snmp_walk($device, $oid, $options = null, $mib = null, $mibdir = null)
{