mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
improved ENTITY-MIB poller
git-svn-id: http://www.observium.org/svn/observer/trunk@509 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@ -1,24 +1,6 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
ini_set('log_errors', 1);
|
||||
ini_set('error_reporting', E_WARNING);
|
||||
|
||||
include("config.php");
|
||||
include("includes/functions.php");
|
||||
include("includes/functions-poller.inc.php");
|
||||
#include("includes/cdp.inc.php");
|
||||
|
||||
if($argv[1] == "--device" && $argv[2]) {
|
||||
$where = "AND `device_id` = '".$argv[2]."'";
|
||||
}
|
||||
|
||||
|
||||
$device_query = mysql_query("SELECT * FROM `devices` WHERE (`os` = 'IOS' OR `os` = 'IOS XE') $where ORDER BY `device_id` DESC");
|
||||
while ($device = mysql_fetch_array($device_query)) {
|
||||
|
||||
$community = $device['community'];
|
||||
|
||||
echo("CISCO-CDP-MIB: ");
|
||||
@ -89,28 +71,4 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
echo("\n");
|
||||
}
|
||||
|
||||
echo("\n");
|
||||
|
||||
echo(count($linkalive) . " Entries\n");
|
||||
|
||||
$query = mysql_query("SELECT * FROM `links`");
|
||||
while($entry = mysql_fetch_array($query)) {
|
||||
$i = 0;
|
||||
unset($alive);
|
||||
while ($i < count($linkalive) && !$alive) {
|
||||
list($src_if_id,$dst_if_id) = explode(",", $linkalive[$i]);
|
||||
$thislink = $entry['src_if'] . "," . $entry['dst_if'];
|
||||
if ($thislink == $linkalive[$i]) {
|
||||
$alive = "yes";
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
if (!$alive) {
|
||||
mysql_query("DELETE FROM `links` WHERE `src_if` = '$entry[src_if]' AND `dst_if` = '$entry[dst_if]'");
|
||||
# echo("$src_if_id -> $dst_if_id REMOVED \n");
|
||||
} else {
|
||||
# echo("$src_if_id -> $dst_if_id VALID \n");
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
include("config.php");
|
||||
include("includes/functions.php");
|
||||
include("includes/functions-poller.inc.php");
|
||||
|
||||
$start = utime();
|
||||
|
||||
@ -80,6 +81,7 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
include("includes/discovery/cisco-processors.php");
|
||||
include("includes/discovery/cemp-mib.php");
|
||||
include("includes/discovery/cmp-mib.php");
|
||||
include("includes/discovery/cisco-cdp.inc.php");
|
||||
}
|
||||
|
||||
echo("\n"); $devices_discovered++;
|
||||
|
@ -6,36 +6,33 @@
|
||||
|
||||
if($config['enable_inventory']) {
|
||||
|
||||
$ents_cmd = $config['snmpbulkwalk'] . " -m ENTITY-MIB -O qn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['$port'] . " ";
|
||||
$ents_cmd .= "1.3.6.1.2.1.47.1.1.1.1.2 | sed s/.1.3.6.1.2.1.47.1.1.1.1.2.//g | grep -v OID | cut -f 1 -d\" \"";
|
||||
$empty = array();
|
||||
$entity_array = snmpwalk_cache_oid("entityPhysical", $device, $empty, "ENTITY-MIB");
|
||||
$entity_array = snmpwalk_cache_oid("entSensorValues", $device, $entity_array, "CISCO-ENTITY-SENSOR-MIB");
|
||||
|
||||
$ents = trim(`$ents_cmd | grep -v o`);
|
||||
print_r($entity_array);
|
||||
|
||||
foreach(explode("\n", $ents) as $entPhysicalIndex) {
|
||||
foreach($entity_array[$device[device_id]] as $entPhysicalIndex => $entry) {
|
||||
|
||||
$ent_data = $config['snmpget'] . " -m ENTITY-MIB:IF-MIB -Ovqs -";
|
||||
$entPhysicalDescr = $entry['entPhysicalDescr'];
|
||||
$entPhysicalContainedIn = $entry['entPhysicalContainedIn'];
|
||||
$entPhysicalClass = $entry['entPhysicalClass'];
|
||||
$entPhysicalName = $entry['entPhysicalName'];
|
||||
$entPhysicalSerialNum = $entry['entPhysicalSerialNum'];
|
||||
$entPhysicalModelName = $entry['entPhysicalModelName'];
|
||||
$entPhysicalMfgName = $entry['entPhysicalMfgName'];
|
||||
$entPhysicalVendorType = $entry['entPhysicalVendorType'];
|
||||
$entPhysicalParentRelPos = $entry['entPhysicalParentRelPos'];
|
||||
|
||||
$ent_data = $config['snmpget'] . " -m ENTITY-MIB:IF-MIB -Ovqs -";
|
||||
$ent_data .= $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] .":".$device['port'];
|
||||
$ent_data .= " entPhysicalDescr." . $entPhysicalIndex;
|
||||
$ent_data .= " entPhysicalContainedIn." . $entPhysicalIndex;
|
||||
$ent_data .= " entPhysicalClass." . $entPhysicalIndex;
|
||||
$ent_data .= " entPhysicalName." . $entPhysicalIndex;
|
||||
$ent_data .= " entPhysicalSerialNum." . $entPhysicalIndex;
|
||||
$ent_data .= " entPhysicalModelName." . $entPhysicalIndex;
|
||||
$ent_data .= " entPhysicalMfgName." . $entPhysicalIndex;
|
||||
$ent_data .= " entPhysicalVendorType." . $entPhysicalIndex;
|
||||
$ent_data .= " entPhysicalParentRelPos." . $entPhysicalIndex;
|
||||
$ent_data .= " entAliasMappingIdentifier." . $entPhysicalIndex. ".0";
|
||||
|
||||
list($entPhysicalDescr,$entPhysicalContainedIn,$entPhysicalClass,$entPhysicalName,$entPhysicalSerialNum,$entPhysicalModelName,$entPhysicalMfgName,$entPhysicalVendorType,$entPhysicalParentRelPos, $ifIndex) = explode("\n", `$ent_data`);
|
||||
$ifIndex = shell_exec($ent_data);
|
||||
|
||||
if(!strpos($ifIndex, "fIndex") || $ifIndex == "") { unset($ifIndex); }
|
||||
list(,$ifIndex) = explode(".", $ifIndex);
|
||||
|
||||
$entPhysicalModelName = trim($entPhysicalModelName);
|
||||
$entPhysicalSerialNum = trim($entPhysicalSerialNum);
|
||||
$entPhysicalMfgName = trim($entPhysicalMfgName);
|
||||
$entPhysicalVendorType = trim($entPhysicalVendorType);
|
||||
|
||||
if ($entPhysicalVendorTypes[$entPhysicalVendorType] && !$entPhysicalModelName) {
|
||||
$entPhysicalModelName = $entPhysicalVendorTypes[$entPhysicalVendorType];
|
||||
}
|
||||
@ -59,14 +56,20 @@
|
||||
}
|
||||
|
||||
if($entPhysicalClass == "sensor") {
|
||||
$sensor_cmd = $config['snmpget'] . " -m CISCO-ENTITY-SENSOR-MIB -O Uqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'];
|
||||
$sensor_cmd .= " entSensorType.$entPhysicalIndex entSensorScale.$entPhysicalIndex entSensorPrecision.$entPhysicalIndex";
|
||||
$sensor_cmd .= " entSensorValueUpdateRate.$entPhysicalIndex entSensorMeasuredEntity.$entPhysicalIndex";
|
||||
$sensor_data = shell_exec($sensor_cmd);
|
||||
list($entSensorType,$entSensorScale,$entSensorPrecision,$entSensorValueUpdateRate,$entSensorMeasuredEntity) = explode("\n", $sensor_data);
|
||||
if($entSensorMeasuredEntity) {
|
||||
#echo("M:$entSensorMeasuredEntity");
|
||||
}
|
||||
|
||||
# $sensor_cmd = $config['snmpget'] . " -m CISCO-ENTITY-SENSOR-MIB -O Uqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'];
|
||||
# $sensor_cmd .= " entSensorType.$entPhysicalIndex entSensorScale.$entPhysicalIndex entSensorPrecision.$entPhysicalIndex";
|
||||
# $sensor_cmd .= " entSensorValueUpdateRate.$entPhysicalIndex entSensorMeasuredEntity.$entPhysicalIndex";
|
||||
# $sensor_data = shell_exec($sensor_cmd);
|
||||
# list($entSensorType,$entSensorScale,$entSensorPrecision,$entSensorValueUpdateRate,$entSensorMeasuredEntity) = explode("\n", $sensor_data);
|
||||
|
||||
$entSensorType = $entry['entSensorType'];
|
||||
$entSensorScale = $entry['entSensorScale'];
|
||||
$entSensorPrecision = $entry['entSensorPrecision'];
|
||||
$entSensorValueUpdateRate = $entry['entSensorValueUpdateRate'];
|
||||
$entSensorMeasuredEntity = $entry['entSensorMeasuredEntity'];
|
||||
|
||||
|
||||
if($config['allow_entity_sensor'][$entSensorType]) {
|
||||
$sql = "UPDATE `entPhysical` SET entSensorType = '$entSensorType', entSensorScale = '$entSensorScale', entSensorPrecision = '$entSensorPrecision', ";
|
||||
$sql .= " entSensorMeasuredEntity = '$entSensorMeasuredEntity'";
|
||||
@ -76,7 +79,7 @@
|
||||
$sql = "UPDATE `entPhysical` SET entSensorType = '', entSensorScale = '', entSensorPrecision = '', entSensorMeasuredEntity = ''";
|
||||
$sql .= " WHERE device_id = '".$device['device_id']."' AND entPhysicalIndex = '$entPhysicalIndex'";
|
||||
}
|
||||
|
||||
echo("$sql\n");
|
||||
mysql_query($sql);
|
||||
}
|
||||
$valid[$entPhysicalIndex] = 1;
|
||||
|
@ -50,6 +50,25 @@ global $config;
|
||||
return $array;
|
||||
}
|
||||
|
||||
function snmpwalk_cache_oid($oid, $device, $array, $mib = 0) {
|
||||
global $config;
|
||||
$cmd = $config['snmpbulkwalk'] . " -O Qs -" . $device['snmpver'] . " -c " . $device['community'] . " " .
|
||||
$device['hostname'].":".$device['port'] . " ";
|
||||
if($mib) { $cmd .= "-m $mib "; }
|
||||
$cmd .= $oid;
|
||||
$data = trim(shell_exec($cmd));
|
||||
$device_id = $device['device_id'];
|
||||
foreach(explode("\n", $data) as $entry) {
|
||||
list($oid,$value) = explode("=", $entry);
|
||||
$oid = trim($oid); $value = trim($value);
|
||||
list($oid, $index) = explode(".", $oid);
|
||||
if (!strstr($this_value, "No Such Instance currently exists at this OID") && $oid && $index) {
|
||||
$array[$device_id][$index][$oid] = $value;
|
||||
}
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
function snmpwalk_cache_twopart_oid($oid, $device, $array, $mib = 0) {
|
||||
global $config;
|
||||
$cmd = $config['snmpbulkwalk'] . " -O Qs -" . $device['snmpver'] . " -c " . $device['community'] . " " .
|
||||
|
Reference in New Issue
Block a user