Merge pull request #2862 from laf/issue-2859

Added ability to ignore device sensors from entity mib
This commit is contained in:
Paul Gear
2016-02-03 15:31:32 +10:00
3 changed files with 43 additions and 4 deletions
+28
View File
@@ -710,3 +710,31 @@ function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen
}//end if
}//end discover_process_ipv6()
/*
* Check entity sensors to be excluded
*
* @param string value to check
* @param array device
*
* @return bool true if sensor is valid
* false if sensor is invalid
*/
function check_entity_sensor($string, $device) {
global $config;
$valid = true;
$string = strtolower($string);
if (is_array($config['bad_entity_sensor_regex'])) {
$fringe = $config['bad_entity_sensor_regex'];
if (is_array($config['os'][$device['os']]['bad_entity_sensor_regex'])) {
$fringe = array_merge($config['bad_entity_sensor_regex'],$config['os'][$device['os']]['bad_entity_sensor_regex']);
}
foreach ($fringe as $bad) {
if (preg_match($bad . "i", $string)) {
$valid = false;
d_echo("Ignored entity sensor: $bad : $string");
}
}
}
return $valid;
}
@@ -50,7 +50,7 @@ if (is_array($oids)) {
$descr = rewrite_entity_descr($descr);
}
$thisisnotbullshit = true;
$valid = check_entity_sensor($descr, $device);
$type = $entitysensor[$entry['entPhySensorType']];
@@ -103,16 +103,16 @@ if (is_array($oids)) {
if ($type == 'temperature') {
if ($current > '200') {
$thisisnotbullshit = false;
$valid = false;
} $descr = preg_replace('/[T|t]emperature[|s]/', '', $descr);
}
// echo($descr . "|" . $index . "|" .$current . "|" . $multiplier . "|" . $divisor ."|" . $entry['entPhySensorScale'] . "|" . $entry['entPhySensorPrecision'] . "\n");
if ($current == '-127') {
$thisisnotbullshit = false;
$valid = false;
}
if ($thisisnotbullshit && dbFetchCell("SELECT COUNT(*) FROM `sensors` WHERE device_id = ? AND `sensor_class` = ? AND `sensor_type` = 'cisco-entity-sensor' AND `sensor_index` = ?", array($device['device_id'], $type, $index)) == '0') {
if ($valid && dbFetchCell("SELECT COUNT(*) FROM `sensors` WHERE device_id = ? AND `sensor_class` = ? AND `sensor_type` = 'cisco-entity-sensor' AND `sensor_index` = ?", array($device['device_id'], $type, $index)) == '0') {
// Check to make sure we've not already seen this sensor via cisco's entity sensor mib
discover_sensor($valid['sensor'], $type, $device, $oid, $index, 'entity-sensor', $descr, $divisor, $multiplier, null, null, null, null, $current);
}