mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* 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:
@@ -557,15 +557,16 @@ function isSNMPable($device)
|
|||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
$pos = snmp_get($device, "sysObjectID.0", "-Oqv", "SNMPv2-MIB");
|
$pos = snmp_check($device);
|
||||||
if (empty($pos)) {
|
if ($pos === true) {
|
||||||
// Support for Hikvision
|
|
||||||
$pos = snmp_get($device, "SNMPv2-SMI::enterprises.39165.1.1.0", "-Oqv", "SNMPv2-MIB");
|
|
||||||
}
|
|
||||||
if ($pos === '' || $pos === false) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
$pos = snmp_get($device, "sysObjectID.0", "-Oqv", "SNMPv2-MIB");
|
||||||
|
if ($pos === '' || $pos === false) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -257,6 +257,27 @@ function snmp_get($device, $oid, $options = null, $mib = null, $mibdir = null)
|
|||||||
}
|
}
|
||||||
}//end snmp_get()
|
}//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)
|
function snmp_walk($device, $oid, $options = null, $mib = null, $mibdir = null)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user