From 3720f0e776474ef8e2bac4c3d320902064d8be3d Mon Sep 17 00:00:00 2001 From: "Chris A. Evans" Date: Tue, 28 Nov 2017 20:30:24 -0600 Subject: [PATCH] feature: Implement dynamic temperature scale detection and value conversion for siteboss (#7734) * added comments describing changes needed to be implemented * Added patch by laf to update the underlying function, modified OID value in yaml to poll string instead of integer * Second patch to discovery function peer laf/murrant --- includes/definitions/discovery/siteboss.yaml | 6 +++--- includes/discovery/functions.inc.php | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/includes/definitions/discovery/siteboss.yaml b/includes/definitions/discovery/siteboss.yaml index f593525edd..c6a8ad1467 100644 --- a/includes/definitions/discovery/siteboss.yaml +++ b/includes/definitions/discovery/siteboss.yaml @@ -5,11 +5,11 @@ modules: data: - oid: esPointTable - value: esPointValueInt - num_oid: .1.3.6.1.4.1.3052.12.1.1.1.1.6. + value: esPointValueStr + num_oid: .1.3.6.1.4.1.3052.12.1.1.1.1.7. descr: esPointName skip_values: - oid: esIndexPC op: '!=' - value: 1 \ No newline at end of file + value: 1 diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index 0b0d222955..ddf0d954b9 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -980,11 +980,21 @@ function discovery_process(&$valid, $device, $sensor_type, $pre_cache) d_echo($raw_data); foreach ($raw_data as $index => $snmp_data) { + $user_function = null; + if (isset($data['user_function'])) { + $user_function = $data['user_function']; + } // get the value for this sensor, check 'value' and 'oid', if state string, translate to a number $data_name = isset($data['value']) ? $data['value'] : $data['oid']; // fallback to oid if value is not set $tmp_value = $snmp_data[$data_name]; if (!is_numeric($tmp_value)) { + if ($sensor_type === 'temperature') { + // For temp sensors, try and detect fahrenheit values + if (ends_with($tmp_value, 'f', true)) { + $user_function = 'fahrenheit_to_celsius'; + } + } preg_match('/-?\d*\.?\d+/', $tmp_value, $temp_response); if (!empty($temp_response[0])) { $tmp_value = $temp_response[0]; @@ -1027,6 +1037,11 @@ function discovery_process(&$valid, $device, $sensor_type, $pre_cache) $high_limit = is_numeric($data['high_limit']) ? $data['high_limit'] : dynamic_discovery_get_value('high_limit', $index, $data, $pre_cache, 'null'); $sensor_name = $device['os']; + + if (isset($user_function) && function_exists($user_function)) { + $value = $user_function($value); + } + if ($sensor_type === 'state') { $sensor_name = $data['state_name'] ?: $data['oid']; create_state_index($sensor_name, $data['states']); @@ -1040,7 +1055,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); + 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); if ($sensor_type === 'state') { create_sensor_to_state_index($device, $sensor_name, $uindex);