From 427c4f07c65a5a548e80654329f2b3d9662cb130 Mon Sep 17 00:00:00 2001 From: laf Date: Mon, 25 Jan 2016 22:37:38 +0000 Subject: [PATCH 1/3] Added ability to ignore device sensors from entity mib --- includes/discovery/functions.inc.php | 28 +++++++++++++++++++ .../discovery/sensors/entity-sensor.inc.php | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index b03ac9048b..755f5b5e7c 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -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; +} diff --git a/includes/discovery/sensors/entity-sensor.inc.php b/includes/discovery/sensors/entity-sensor.inc.php index b81c997849..edf621b33c 100644 --- a/includes/discovery/sensors/entity-sensor.inc.php +++ b/includes/discovery/sensors/entity-sensor.inc.php @@ -50,7 +50,7 @@ if (is_array($oids)) { $descr = rewrite_entity_descr($descr); } - $thisisnotbullshit = true; + $thisisnotbullshit = check_entity_sensor($descr, $device); $type = $entitysensor[$entry['entPhySensorType']]; From d8c4916f6be3c1a1a5a6ce9470d2fe19222eebeb Mon Sep 17 00:00:00 2001 From: laf Date: Mon, 25 Jan 2016 22:59:11 +0000 Subject: [PATCH 2/3] Added docs information on using the new config options --- doc/Support/Configuration.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/doc/Support/Configuration.md b/doc/Support/Configuration.md index 15be9ed6c3..17248c0b46 100644 --- a/doc/Support/Configuration.md +++ b/doc/Support/Configuration.md @@ -406,6 +406,17 @@ Entries defined in `rewrite_if` are being replaced completely. Entries defined in `rewrite_if_regexp` only replace the match. Matches are compared case-insensitive. +#### Entity sensors to be ignored + +Some devices register bogus sensors as they are returned via SNMP but either don't exist or just don't return data. +This allows you to ignore those based on the descr field in the database. You can either ignore globally or on a per +os basis. + +```php +$config['bad_entity_sensor_regex'][] = '/Physical id [0-9]+/'; +$config['os']['cisco']['bad_entity_sensor_regex'] = '/Physical id [0-9]+/'; +``` + #### Storage configuration ```php From 3560a39b5249629b4135ad92b5b662f4f479a9da Mon Sep 17 00:00:00 2001 From: laf Date: Thu, 28 Jan 2016 09:38:31 +0000 Subject: [PATCH 3/3] Updated thisisnotbullshit variable --- includes/discovery/sensors/entity-sensor.inc.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/discovery/sensors/entity-sensor.inc.php b/includes/discovery/sensors/entity-sensor.inc.php index edf621b33c..3a7de2e6a4 100644 --- a/includes/discovery/sensors/entity-sensor.inc.php +++ b/includes/discovery/sensors/entity-sensor.inc.php @@ -50,7 +50,7 @@ if (is_array($oids)) { $descr = rewrite_entity_descr($descr); } - $thisisnotbullshit = check_entity_sensor($descr, $device); + $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); }