fix: Apply divisor / multiplier to high/low limits in sensors (#8427)

* fix: Apply divisor / multiplier to high/low limits in sensors

* Updated test data for airos

* updated sensors test data

* Updated test data

* Updated test files

* updated dell-rpdu tests

* Updated to do division / multiply after check for value
This commit is contained in:
Neil Lathwood 2018-04-14 03:43:40 +01:00 committed by Tony Murray
parent 90bfce1193
commit 1c94cddd70
7 changed files with 85 additions and 46 deletions

View File

@ -75,10 +75,10 @@ The only sensor we have defined here is airflow. The available options are as fo
- `num_oid` (required): This is the numerical OID that contains `value`. This should always be without the appended `index`.
- `divisor` (optional): This is the divisor to use against the returned `value`.
- `multiplier` (optional): This is the multiplier to use against the returned `value`.
- `low_limit` (optional): This is the critical low threshold that `value` should be (used in alerting).
- `low_warn_limit` (optional): This is the warning low threshold that `value` should be (used in alerting).
- `warn_limit` (optional): This is the warning high threshold that `value` should be (used in alerting).
- `high_limit` (optional): This is the critical high threshold that `value` should be (used in alerting).
- `low_limit` (optional): This is the critical low threshold that `value` should be (used in alerting). If an OID is specified then divisor / multiplier are used.
- `low_warn_limit` (optional): This is the warning low threshold that `value` should be (used in alerting). If an OID is specified then divisor / multiplier are used.
- `warn_limit` (optional): This is the warning high threshold that `value` should be (used in alerting). If an OID is specified then divisor / multiplier are used.
- `high_limit` (optional): This is the critical high threshold that `value` should be (used in alerting). If an OID is specified then divisor / multiplier are used.
- `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 (see note below).

View File

@ -28,8 +28,8 @@ modules:
descr: atEnvMonv2VoltageDescription
index: 'atEnvMonv2VoltageIndex.{{ $index }}'
divisor: 1000
# low_limit: atEnvMonv2VoltageLowerThreshold
# high_limit: atEnvMonv2VoltageUpperThreshold
low_limit: atEnvMonv2VoltageLowerThreshold
high_limit: atEnvMonv2VoltageUpperThreshold
temperature:
options:
skip_values: 128

View File

@ -21,8 +21,8 @@ modules:
divisor: 10
index: 'mpduOutputPercentLoad.{{ $index }}'
descr: 'MPDU #{{ $mpduOutputIndex }} Load'
warn_limit: mpduOutputWarningThreshold
high_limit: mpduOutputCriticalThreshold
warn_limit: 80
high_limit: 90
power:
data:
-

View File

@ -1044,11 +1044,16 @@ function discovery_process(&$valid, $device, $sensor_type, $pre_cache)
$divisor = $data['divisor'] ?: ($sensor_options['divisor'] ?: 1);
$multiplier = $data['multiplier'] ?: ($sensor_options['multiplier'] ?: 1);
$low_limit = is_numeric($data['low_limit']) ? $data['low_limit'] : dynamic_discovery_get_value('low_limit', $index, $data, $pre_cache, 'null');
$low_warn_limit = is_numeric($data['low_warn_limit']) ? $data['low_warn_limit'] : dynamic_discovery_get_value('low_warn_limit', $index, $data, $pre_cache, 'null');
$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');
$limits = ['low_limit', 'low_warn_limit', 'warn_limit', 'high_limit'];
foreach ($limits as $limit) {
$$limit = is_numeric($data[$limit]) ? $data[$limit] : dynamic_discovery_get_value($limit, $index, $data, $pre_cache, 'null');
if (is_numeric($$limit)) {
$$limit = ($$limit / $divisor) * $multiplier;
}
}
echo "Cur $value, Low: $low_limit, Low Warn: $low_warn_limit, Warn: $warn_limit, High: $high_limit".PHP_EOL;
$entPhysicalIndex = str_replace('{{ $index }}', $index, $data['entPhysicalIndex']) ?: null;
$entPhysicalIndex_measured = isset($data['entPhysicalIndex_measured']) ? $data['entPhysicalIndex_measured'] : null;
@ -1062,12 +1067,8 @@ function discovery_process(&$valid, $device, $sensor_type, $pre_cache)
$sensor_name = $data['state_name'] ?: $data['oid'];
create_state_index($sensor_name, $data['states']);
} else {
if (is_numeric($divisor)) {
$value = $value / $divisor;
}
if (is_numeric($multiplier)) {
$value = $value * $multiplier;
}
// We default to 1 for both divisors / multipler so it should be safe to do the calculation using both.
$value = ($value / $divisor) * $multiplier;
}
$uindex = str_replace('{{ $index }}', $index, $data['index'] ?: $index);

View File

@ -697,5 +697,43 @@
]
},
"poller": "matches discovery"
},
"os": {
"discovery": {
"devices": [
{
"sysName": "<private>",
"sysObjectID": ".1.3.6.1.4.1.10002.1",
"sysDescr": "Linux 2.6.32.68 #1 Fri Dec 16 15:44:21 EET 2016 mips",
"sysContact": null,
"version": null,
"hardware": "",
"features": null,
"location": null,
"os": "airos",
"type": "wireless",
"serial": null,
"icon": "ubiquiti.svg"
}
]
},
"poller": {
"devices": [
{
"sysName": "<private>",
"sysObjectID": ".1.3.6.1.4.1.10002.1",
"sysDescr": "Linux 2.6.32.68 #1 Fri Dec 16 15:44:21 EET 2016 mips",
"sysContact": "<private>",
"version": null,
"hardware": "Ubiquiti Linux 2.6.32.68 #1 Fri Dec 16 15:44:21 EET 2016 mips",
"features": null,
"location": "<private>",
"os": "airos",
"type": "wireless",
"serial": null,
"icon": "ubiquiti.svg"
}
]
}
}
}

View File

@ -12172,9 +12172,9 @@
"sensor_divisor": "1000",
"sensor_multiplier": "1",
"sensor_current": "2.487",
"sensor_limit": "2.86005",
"sensor_limit": "2.865",
"sensor_limit_warn": null,
"sensor_limit_low": "2.11395",
"sensor_limit_low": "2.344",
"sensor_limit_low_warn": null,
"sensor_alert": "1",
"sensor_custom": "No",
@ -12195,9 +12195,9 @@
"sensor_divisor": "1000",
"sensor_multiplier": "1",
"sensor_current": "3.164",
"sensor_limit": "3.6386",
"sensor_limit": "3.586",
"sensor_limit_warn": null,
"sensor_limit_low": "2.6894",
"sensor_limit_low": "2.7",
"sensor_limit_low_warn": null,
"sensor_alert": "1",
"sensor_custom": "No",
@ -12218,9 +12218,9 @@
"sensor_divisor": "1000",
"sensor_multiplier": "1",
"sensor_current": "3.317",
"sensor_limit": "3.81455",
"sensor_limit": "3.627",
"sensor_limit_warn": null,
"sensor_limit_low": "2.81945",
"sensor_limit_low": "2.973",
"sensor_limit_low_warn": null,
"sensor_alert": "1",
"sensor_custom": "No",
@ -12241,9 +12241,9 @@
"sensor_divisor": "1000",
"sensor_multiplier": "1",
"sensor_current": "12.125",
"sensor_limit": "13.9438",
"sensor_limit": "13.188",
"sensor_limit_warn": null,
"sensor_limit_low": "10.3062",
"sensor_limit_low": "10.813",
"sensor_limit_low_warn": null,
"sensor_alert": "1",
"sensor_custom": "No",
@ -12264,9 +12264,9 @@
"sensor_divisor": "1000",
"sensor_multiplier": "1",
"sensor_current": "0.998",
"sensor_limit": "1.1477",
"sensor_limit": "1.097",
"sensor_limit_warn": null,
"sensor_limit_low": "0.8483",
"sensor_limit_low": "0.9",
"sensor_limit_low_warn": null,
"sensor_alert": "1",
"sensor_custom": "No",
@ -12287,9 +12287,9 @@
"sensor_divisor": "1000",
"sensor_multiplier": "1",
"sensor_current": "2.5",
"sensor_limit": "2.875",
"sensor_limit": "2.865",
"sensor_limit_warn": null,
"sensor_limit_low": "2.125",
"sensor_limit_low": "2.344",
"sensor_limit_low_warn": null,
"sensor_alert": "1",
"sensor_custom": "No",
@ -12310,9 +12310,9 @@
"sensor_divisor": "1000",
"sensor_multiplier": "1",
"sensor_current": "3.136",
"sensor_limit": "3.6064",
"sensor_limit": "3.586",
"sensor_limit_warn": null,
"sensor_limit_low": "2.6656",
"sensor_limit_low": "2.7",
"sensor_limit_low_warn": null,
"sensor_alert": "1",
"sensor_custom": "No",
@ -12333,9 +12333,9 @@
"sensor_divisor": "1000",
"sensor_multiplier": "1",
"sensor_current": "3.317",
"sensor_limit": "3.81455",
"sensor_limit": "3.627",
"sensor_limit_warn": null,
"sensor_limit_low": "2.81945",
"sensor_limit_low": "2.973",
"sensor_limit_low_warn": null,
"sensor_alert": "1",
"sensor_custom": "No",
@ -12356,9 +12356,9 @@
"sensor_divisor": "1000",
"sensor_multiplier": "1",
"sensor_current": "12.125",
"sensor_limit": "13.9438",
"sensor_limit": "13.188",
"sensor_limit_warn": null,
"sensor_limit_low": "10.3062",
"sensor_limit_low": "10.813",
"sensor_limit_low_warn": null,
"sensor_alert": "1",
"sensor_custom": "No",
@ -12379,9 +12379,9 @@
"sensor_divisor": "1000",
"sensor_multiplier": "1",
"sensor_current": "0.998",
"sensor_limit": "1.1477",
"sensor_limit": "1.097",
"sensor_limit_warn": null,
"sensor_limit_low": "0.8483",
"sensor_limit_low": "0.9",
"sensor_limit_low_warn": null,
"sensor_alert": "1",
"sensor_custom": "No",

View File

@ -2704,10 +2704,10 @@
"sensor_divisor": "10",
"sensor_multiplier": "1",
"sensor_current": "33",
"sensor_limit": "70",
"sensor_limit_warn": "65",
"sensor_limit_low": "-40",
"sensor_limit_low_warn": "-35",
"sensor_limit": "7",
"sensor_limit_warn": "6.5",
"sensor_limit_low": "-4",
"sensor_limit_low_warn": "-3.5",
"sensor_alert": "1",
"sensor_custom": "No",
"entPhysicalIndex": null,
@ -3074,10 +3074,10 @@
"sensor_divisor": "10",
"sensor_multiplier": "1",
"sensor_current": "33",
"sensor_limit": "70",
"sensor_limit_warn": "65",
"sensor_limit_low": "-40",
"sensor_limit_low_warn": "-35",
"sensor_limit": "7",
"sensor_limit_warn": "6.5",
"sensor_limit_low": "-4",
"sensor_limit_low_warn": "-3.5",
"sensor_alert": "1",
"sensor_custom": "No",
"entPhysicalIndex": null,