From 5357dd951517caeed3dc642bee9fa1b45182bb14 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Sat, 2 Dec 2017 22:56:57 +0000 Subject: [PATCH] feature: Added support for entity values in sensors (#7805) * Added info on using OIDs in skip_values for sensors * added more docs + entity support * remove whitespace --- doc/Developing/os/Health-Information.md | 19 ++++++++++++++++--- includes/discovery/functions.inc.php | 5 ++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/doc/Developing/os/Health-Information.md b/doc/Developing/os/Health-Information.md index f201b83c4c..3ec34ed5c4 100644 --- a/doc/Developing/os/Health-Information.md +++ b/doc/Developing/os/Health-Information.md @@ -75,18 +75,31 @@ The only sensor we have defined here is airflow. The available options are as fo - `high_limit` (optional): This is the critical high threshold that `value` should be (used in alerting). - `descr` (required): The visible label for this sensor. It can be a key with in the table or a static string, optionally using `{{ index }}` - `index` (optional): This is the index value we use to uniquely identify this sensor. `{{ $index }}` will be replaced by the `index` from the snmp walk. - - `skip_values` (optional): This is an array of values we should skip over. + - `skip_values` (optional): This is an array of values we should skip over (see note below). - `skip_value_lt` (optional): If sensor value is less than this, skip the discovery. - `skip_value_gt` (optional): If sensor value is greater than this, skip the discovery. + - `entPhysicalIndex` (optional): If the sensor belongs to a physical entity then you can specify the index here. + - `entPhysicalIndex_measured` (optional): If the sensor belongs to a physical entity then you can specify the entity type here. + - `user_func` (optional): You can provide a function name for the sensors value to be processed through (i.e. Convert fahrenheit to celsius use `fahrenheit_to_celsius`) For `options:` you have the following available: - `divisor`: This is the divisor to use against the returned `value`. - `multiplier`: This is the multiplier to use against the returned `value`. - - `skip_values`: This is an array of values we should skip over. + - `skip_values`: This is an array of values we should skip over (see note below). - `skip_value_lt`: If sensor value is less than this, skip the discovery. - `skip_value_gt`: If sensor value is greater than this, skip the discovery. +> `skip_values` can also compare items within the OID table against values. One example of this is: + +```yaml + skip_values: + - + oid: sensUnit + op: '!=' + value: 4 +``` + If you aren't able to use yaml to perform the sensor discovery, you will most likely need to use Advanced health discovery. #### Advanced health discovery @@ -122,4 +135,4 @@ For the majority of devices, this is all that's required to add support for a se If custom polling is needed then the file format is similar to discovery: `includes/polling/sensors/$class/$os.inc.php`. Whilst it's possible to perform additional snmp queries within polling this should be avoided where possible. The value for the OID is already available as `$sensor_value`. -Graphing is performed automatically for sensors, no custom graphing is required or supported. \ No newline at end of file +Graphing is performed automatically for sensors, no custom graphing is required or supported. diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index fe3a90bea0..0a3df2e95f 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -1037,6 +1037,9 @@ function discovery_process(&$valid, $device, $sensor_type, $pre_cache) $warn_limit = is_numeric($data['warn_limit']) ? $data['warn_limit'] : dynamic_discovery_get_value('warn_limit', $index, $data, $pre_cache, 'null'); $high_limit = is_numeric($data['high_limit']) ? $data['high_limit'] : dynamic_discovery_get_value('high_limit', $index, $data, $pre_cache, 'null'); + $entPhysicalIndex = str_replace('{{ $index }}', $index, $data['entPhysicalIndex']) ?: null; + $entPhysicalIndex_measured = isset($data['entPhysicalIndex_measured']) ? $data['entPhysicalIndex_measured'] : null; + $sensor_name = $device['os']; if (isset($user_function) && function_exists($user_function)) { @@ -1056,7 +1059,7 @@ function discovery_process(&$valid, $device, $sensor_type, $pre_cache) } $uindex = str_replace('{{ $index }}', $index, $data['index'] ?: $index); - discover_sensor($valid['sensor'], $sensor_type, $device, $oid, $uindex, $sensor_name, $descr, $divisor, $multiplier, $low_limit, $low_warn_limit, $warn_limit, $high_limit, $value, 'snmp', null, null, $user_function); + discover_sensor($valid['sensor'], $sensor_type, $device, $oid, $uindex, $sensor_name, $descr, $divisor, $multiplier, $low_limit, $low_warn_limit, $warn_limit, $high_limit, $value, 'snmp', $entPhysicalIndex, $entPhysicalIndex_measured, $user_function); if ($sensor_type === 'state') { create_sensor_to_state_index($device, $sensor_name, $uindex);