From 4df3310d4da3840f31c329a3baba253795dd1d7f Mon Sep 17 00:00:00 2001 From: priiduonu Date: Thu, 23 Apr 2020 05:53:27 +0300 Subject: [PATCH] Fix: Raspberry Pi frequency sensors discovery (#11460) * Fix: Raspberry Pi frequency sensors discovery * updated test data * update test data again * fixed Raspberry Pi codec states --- .../discovery/sensors/frequency/linux.inc.php | 2 +- .../discovery/sensors/state/linux.inc.php | 2 +- tests/data/linux_raspberrypi.json | 448 ++++++++++++++++-- tests/snmpsim/linux_raspberrypi.snmprec | 23 +- 4 files changed, 415 insertions(+), 60 deletions(-) diff --git a/includes/discovery/sensors/frequency/linux.inc.php b/includes/discovery/sensors/frequency/linux.inc.php index 8ca5d1c93d..673080a156 100644 --- a/includes/discovery/sensors/frequency/linux.inc.php +++ b/includes/discovery/sensors/frequency/linux.inc.php @@ -16,7 +16,7 @@ if (!empty($pre_cache['raspberry_pi_sensors'])) { $descr = "Core"; break; } - $value = isset($pre_cache['raspberry_pi_sensors']["raspberry." . $freq]); + $value = current($pre_cache['raspberry_pi_sensors']["raspberry." . $freq]); if (is_numeric($value)) { discover_sensor($valid['sensor'], 'frequency', $device, $oid . $freq, $freq, $sensor_type, $descr, 1, 1, null, null, null, null, $value); } else { diff --git a/includes/discovery/sensors/state/linux.inc.php b/includes/discovery/sensors/state/linux.inc.php index 9dfabc779c..8379260650 100644 --- a/includes/discovery/sensors/state/linux.inc.php +++ b/includes/discovery/sensors/state/linux.inc.php @@ -33,7 +33,7 @@ if (!empty($pre_cache['raspberry_pi_sensors'])) { ['value' => 2, 'generic' => 0, 'graph' => 1, 'descr' => 'enabled'], ['value' => 3, 'generic' => 2, 'graph' => 1, 'descr' => 'disabled'], ]; - create_state_index($state_name, $states); + create_state_index($state, $states); discover_sensor($valid['sensor'], 'state', $device, $oid . $codec, $codec, $state, $descr, 1, 1, null, null, null, null, $value, 'snmp', $codec); create_sensor_to_state_index($device, $state, $codec); diff --git a/tests/data/linux_raspberrypi.json b/tests/data/linux_raspberrypi.json index f0ad5b52ed..0fcdccc6a6 100644 --- a/tests/data/linux_raspberrypi.json +++ b/tests/data/linux_raspberrypi.json @@ -2,6 +2,54 @@ "sensors": { "discovery": { "sensors": [ + { + "sensor_deleted": 0, + "sensor_class": "frequency", + "poller_type": "snmp", + "sensor_oid": ".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.6", + "sensor_index": "6", + "sensor_type": "raspberry_freq", + "sensor_descr": "ARM", + "group": null, + "sensor_divisor": 1, + "sensor_multiplier": 1, + "sensor_current": 700000000, + "sensor_limit": 735000000, + "sensor_limit_warn": null, + "sensor_limit_low": 665000000, + "sensor_limit_low_warn": null, + "sensor_alert": 1, + "sensor_custom": "No", + "entPhysicalIndex": null, + "entPhysicalIndex_measured": null, + "sensor_prev": null, + "user_func": null, + "state_name": null + }, + { + "sensor_deleted": 0, + "sensor_class": "frequency", + "poller_type": "snmp", + "sensor_oid": ".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.7", + "sensor_index": "7", + "sensor_type": "raspberry_freq", + "sensor_descr": "Core", + "group": null, + "sensor_divisor": 1, + "sensor_multiplier": 1, + "sensor_current": 250000000, + "sensor_limit": 262500000, + "sensor_limit_warn": null, + "sensor_limit_low": 237500000, + "sensor_limit_low_warn": null, + "sensor_alert": 1, + "sensor_custom": "No", + "entPhysicalIndex": null, + "entPhysicalIndex_measured": null, + "sensor_prev": null, + "user_func": null, + "state_name": null + }, { "sensor_deleted": 0, "sensor_class": "state", @@ -24,7 +72,7 @@ "entPhysicalIndex_measured": null, "sensor_prev": null, "user_func": null, - "state_name": null + "state_name": "raspberry_codec" }, { "sensor_deleted": 0, @@ -48,7 +96,7 @@ "entPhysicalIndex_measured": null, "sensor_prev": null, "user_func": null, - "state_name": null + "state_name": "raspberry_codec" }, { "sensor_deleted": 0, @@ -72,7 +120,7 @@ "entPhysicalIndex_measured": null, "sensor_prev": null, "user_func": null, - "state_name": null + "state_name": "raspberry_codec" }, { "sensor_deleted": 0, @@ -96,7 +144,7 @@ "entPhysicalIndex_measured": null, "sensor_prev": null, "user_func": null, - "state_name": null + "state_name": "raspberry_codec" }, { "sensor_deleted": 0, @@ -120,7 +168,7 @@ "entPhysicalIndex_measured": null, "sensor_prev": null, "user_func": null, - "state_name": null + "state_name": "raspberry_codec" }, { "sensor_deleted": 0, @@ -144,7 +192,7 @@ "entPhysicalIndex_measured": null, "sensor_prev": null, "user_func": null, - "state_name": null + "state_name": "raspberry_codec" }, { "sensor_deleted": 0, @@ -157,10 +205,10 @@ "group": null, "sensor_divisor": 1, "sensor_multiplier": 1, - "sensor_current": 57.3, - "sensor_limit": 77.3, + "sensor_current": 22.300000000000001, + "sensor_limit": 42.299999999999997, "sensor_limit_warn": null, - "sensor_limit_low": 47.3, + "sensor_limit_low": 12.300000000000001, "sensor_limit_low_warn": null, "sensor_alert": 1, "sensor_custom": "No", @@ -182,7 +230,7 @@ "sensor_divisor": 1, "sensor_multiplier": 1, "sensor_current": 1.2, - "sensor_limit": 1.38, + "sensor_limit": 1.3799999999999999, "sensor_limit_warn": null, "sensor_limit_low": 1.02, "sensor_limit_low_warn": null, @@ -206,7 +254,7 @@ "sensor_divisor": 1, "sensor_multiplier": 1, "sensor_current": 1.2, - "sensor_limit": 1.38, + "sensor_limit": 1.3799999999999999, "sensor_limit_warn": null, "sensor_limit_low": 1.02, "sensor_limit_low_warn": null, @@ -230,7 +278,7 @@ "sensor_divisor": 1, "sensor_multiplier": 1, "sensor_current": 1.2, - "sensor_limit": 1.38, + "sensor_limit": 1.3799999999999999, "sensor_limit_warn": null, "sensor_limit_low": 1.02, "sensor_limit_low_warn": null, @@ -253,8 +301,8 @@ "group": null, "sensor_divisor": 1, "sensor_multiplier": 1, - "sensor_current": 1.225, - "sensor_limit": 1.40875, + "sensor_current": 1.2250000000000001, + "sensor_limit": 1.4087499999999999, "sensor_limit_warn": null, "sensor_limit_low": 1.04125, "sensor_limit_low_warn": null, @@ -267,44 +315,352 @@ "state_name": null } ], - "state_indexes": [] - }, - "poller": "matches discovery" - }, - "os": { - "discovery": { - "devices": [ + "state_indexes": [ { - "sysName": "", - "sysObjectID": ".1.3.6.1.4.1.8072.3.2.10", - "sysDescr": "Linux rpi 4.14.98+ #1200 Tue Feb 12 20:11:02 GMT 2019 armv6l", - "sysContact": null, - "version": null, - "hardware": null, - "features": null, - "os": "linux", - "type": "server", - "serial": null, - "icon": "linux.svg", - "location": null + "state_name": "raspberry_codec", + "state_descr": "enabled", + "state_draw_graph": 1, + "state_value": 2, + "state_generic_value": 0 + }, + { + "state_name": "raspberry_codec", + "state_descr": "disabled", + "state_draw_graph": 1, + "state_value": 3, + "state_generic_value": 2 } ] }, "poller": { - "devices": [ + "sensors": [ { - "sysName": "", - "sysObjectID": ".1.3.6.1.4.1.8072.3.2.10", - "sysDescr": "Linux rpi 4.14.98+ #1200 Tue Feb 12 20:11:02 GMT 2019 armv6l", - "sysContact": "", - "version": "4.14.98+", - "hardware": "Generic ARMv6", - "features": null, - "os": "linux", - "type": "server", - "serial": null, - "icon": "linux.svg", - "location": "" + "sensor_deleted": 0, + "sensor_class": "frequency", + "poller_type": "snmp", + "sensor_oid": ".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.6", + "sensor_index": "6", + "sensor_type": "raspberry_freq", + "sensor_descr": "ARM", + "group": null, + "sensor_divisor": 1, + "sensor_multiplier": 1, + "sensor_current": 700000000, + "sensor_limit": 735000000, + "sensor_limit_warn": null, + "sensor_limit_low": 665000000, + "sensor_limit_low_warn": null, + "sensor_alert": 1, + "sensor_custom": "No", + "entPhysicalIndex": null, + "entPhysicalIndex_measured": null, + "sensor_prev": null, + "user_func": null, + "state_name": null + }, + { + "sensor_deleted": 0, + "sensor_class": "frequency", + "poller_type": "snmp", + "sensor_oid": ".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.7", + "sensor_index": "7", + "sensor_type": "raspberry_freq", + "sensor_descr": "Core", + "group": null, + "sensor_divisor": 1, + "sensor_multiplier": 1, + "sensor_current": 250000000, + "sensor_limit": 262500000, + "sensor_limit_warn": null, + "sensor_limit_low": 237500000, + "sensor_limit_low_warn": null, + "sensor_alert": 1, + "sensor_custom": "No", + "entPhysicalIndex": null, + "entPhysicalIndex_measured": null, + "sensor_prev": null, + "user_func": null, + "state_name": null + }, + { + "sensor_deleted": 0, + "sensor_class": "state", + "poller_type": "snmp", + "sensor_oid": ".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.10", + "sensor_index": "10", + "sensor_type": "raspberry_codec", + "sensor_descr": "WVC1 codec", + "group": null, + "sensor_divisor": 1, + "sensor_multiplier": 1, + "sensor_current": 3, + "sensor_limit": null, + "sensor_limit_warn": null, + "sensor_limit_low": null, + "sensor_limit_low_warn": null, + "sensor_alert": 1, + "sensor_custom": "No", + "entPhysicalIndex": "10", + "entPhysicalIndex_measured": null, + "sensor_prev": 0, + "user_func": null, + "state_name": "raspberry_codec" + }, + { + "sensor_deleted": 0, + "sensor_class": "state", + "poller_type": "snmp", + "sensor_oid": ".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.11", + "sensor_index": "11", + "sensor_type": "raspberry_codec", + "sensor_descr": "MPG4 codec", + "group": null, + "sensor_divisor": 1, + "sensor_multiplier": 1, + "sensor_current": 2, + "sensor_limit": null, + "sensor_limit_warn": null, + "sensor_limit_low": null, + "sensor_limit_low_warn": null, + "sensor_alert": 1, + "sensor_custom": "No", + "entPhysicalIndex": "11", + "entPhysicalIndex_measured": null, + "sensor_prev": 0, + "user_func": null, + "state_name": "raspberry_codec" + }, + { + "sensor_deleted": 0, + "sensor_class": "state", + "poller_type": "snmp", + "sensor_oid": ".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.12", + "sensor_index": "12", + "sensor_type": "raspberry_codec", + "sensor_descr": "MJPG codec", + "group": null, + "sensor_divisor": 1, + "sensor_multiplier": 1, + "sensor_current": 2, + "sensor_limit": null, + "sensor_limit_warn": null, + "sensor_limit_low": null, + "sensor_limit_low_warn": null, + "sensor_alert": 1, + "sensor_custom": "No", + "entPhysicalIndex": "12", + "entPhysicalIndex_measured": null, + "sensor_prev": 0, + "user_func": null, + "state_name": "raspberry_codec" + }, + { + "sensor_deleted": 0, + "sensor_class": "state", + "poller_type": "snmp", + "sensor_oid": ".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.13", + "sensor_index": "13", + "sensor_type": "raspberry_codec", + "sensor_descr": "WMV9 codec", + "group": null, + "sensor_divisor": 1, + "sensor_multiplier": 1, + "sensor_current": 3, + "sensor_limit": null, + "sensor_limit_warn": null, + "sensor_limit_low": null, + "sensor_limit_low_warn": null, + "sensor_alert": 1, + "sensor_custom": "No", + "entPhysicalIndex": "13", + "entPhysicalIndex_measured": null, + "sensor_prev": 0, + "user_func": null, + "state_name": "raspberry_codec" + }, + { + "sensor_deleted": 0, + "sensor_class": "state", + "poller_type": "snmp", + "sensor_oid": ".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.8", + "sensor_index": "8", + "sensor_type": "raspberry_codec", + "sensor_descr": "H264 codec", + "group": null, + "sensor_divisor": 1, + "sensor_multiplier": 1, + "sensor_current": 2, + "sensor_limit": null, + "sensor_limit_warn": null, + "sensor_limit_low": null, + "sensor_limit_low_warn": null, + "sensor_alert": 1, + "sensor_custom": "No", + "entPhysicalIndex": "8", + "entPhysicalIndex_measured": null, + "sensor_prev": 0, + "user_func": null, + "state_name": "raspberry_codec" + }, + { + "sensor_deleted": 0, + "sensor_class": "state", + "poller_type": "snmp", + "sensor_oid": ".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.9", + "sensor_index": "9", + "sensor_type": "raspberry_codec", + "sensor_descr": "MPG2 codec", + "group": null, + "sensor_divisor": 1, + "sensor_multiplier": 1, + "sensor_current": 3, + "sensor_limit": null, + "sensor_limit_warn": null, + "sensor_limit_low": null, + "sensor_limit_low_warn": null, + "sensor_alert": 1, + "sensor_custom": "No", + "entPhysicalIndex": "9", + "entPhysicalIndex_measured": null, + "sensor_prev": 0, + "user_func": null, + "state_name": "raspberry_codec" + }, + { + "sensor_deleted": 0, + "sensor_class": "temperature", + "poller_type": "snmp", + "sensor_oid": ".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.1", + "sensor_index": "1", + "sensor_type": "raspberry_temp", + "sensor_descr": "CPU Temp", + "group": null, + "sensor_divisor": 1, + "sensor_multiplier": 1, + "sensor_current": 22.300000000000001, + "sensor_limit": 42.299999999999997, + "sensor_limit_warn": null, + "sensor_limit_low": 12.300000000000001, + "sensor_limit_low_warn": null, + "sensor_alert": 1, + "sensor_custom": "No", + "entPhysicalIndex": null, + "entPhysicalIndex_measured": null, + "sensor_prev": null, + "user_func": null, + "state_name": null + }, + { + "sensor_deleted": 0, + "sensor_class": "voltage", + "poller_type": "snmp", + "sensor_oid": ".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.2", + "sensor_index": "2", + "sensor_type": "raspberry_volts", + "sensor_descr": "Core", + "group": null, + "sensor_divisor": 1, + "sensor_multiplier": 1, + "sensor_current": 1.2, + "sensor_limit": 1.3799999999999999, + "sensor_limit_warn": null, + "sensor_limit_low": 1.02, + "sensor_limit_low_warn": null, + "sensor_alert": 1, + "sensor_custom": "No", + "entPhysicalIndex": null, + "entPhysicalIndex_measured": null, + "sensor_prev": null, + "user_func": null, + "state_name": null + }, + { + "sensor_deleted": 0, + "sensor_class": "voltage", + "poller_type": "snmp", + "sensor_oid": ".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.3", + "sensor_index": "3", + "sensor_type": "raspberry_volts", + "sensor_descr": "SDRAMc", + "group": null, + "sensor_divisor": 1, + "sensor_multiplier": 1, + "sensor_current": 1.2, + "sensor_limit": 1.3799999999999999, + "sensor_limit_warn": null, + "sensor_limit_low": 1.02, + "sensor_limit_low_warn": null, + "sensor_alert": 1, + "sensor_custom": "No", + "entPhysicalIndex": null, + "entPhysicalIndex_measured": null, + "sensor_prev": null, + "user_func": null, + "state_name": null + }, + { + "sensor_deleted": 0, + "sensor_class": "voltage", + "poller_type": "snmp", + "sensor_oid": ".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.4", + "sensor_index": "4", + "sensor_type": "raspberry_volts", + "sensor_descr": "SDRAMi", + "group": null, + "sensor_divisor": 1, + "sensor_multiplier": 1, + "sensor_current": 1.2, + "sensor_limit": 1.3799999999999999, + "sensor_limit_warn": null, + "sensor_limit_low": 1.02, + "sensor_limit_low_warn": null, + "sensor_alert": 1, + "sensor_custom": "No", + "entPhysicalIndex": null, + "entPhysicalIndex_measured": null, + "sensor_prev": null, + "user_func": null, + "state_name": null + }, + { + "sensor_deleted": 0, + "sensor_class": "voltage", + "poller_type": "snmp", + "sensor_oid": ".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.5", + "sensor_index": "5", + "sensor_type": "raspberry_volts", + "sensor_descr": "SDRAMp", + "group": null, + "sensor_divisor": 1, + "sensor_multiplier": 1, + "sensor_current": 1.2250000000000001, + "sensor_limit": 1.4087499999999999, + "sensor_limit_warn": null, + "sensor_limit_low": 1.04125, + "sensor_limit_low_warn": null, + "sensor_alert": 1, + "sensor_custom": "No", + "entPhysicalIndex": null, + "entPhysicalIndex_measured": null, + "sensor_prev": null, + "user_func": null, + "state_name": null + } + ], + "state_indexes": [ + { + "state_name": "raspberry_codec", + "state_descr": "enabled", + "state_draw_graph": 1, + "state_value": 2, + "state_generic_value": 0 + }, + { + "state_name": "raspberry_codec", + "state_descr": "disabled", + "state_draw_graph": 1, + "state_value": 3, + "state_generic_value": 2 } ] } diff --git a/tests/snmpsim/linux_raspberrypi.snmprec b/tests/snmpsim/linux_raspberrypi.snmprec index a52e0f7177..9d4bae3089 100644 --- a/tests/snmpsim/linux_raspberrypi.snmprec +++ b/tests/snmpsim/linux_raspberrypi.snmprec @@ -1,11 +1,11 @@ -1.3.6.1.2.1.1.1.0|4|Linux rpi 4.14.98+ #1200 Tue Feb 12 20:11:02 GMT 2019 armv6l +1.3.6.1.2.1.1.1.0|4|Linux mso 4.19.97+ #1294 Thu Jan 30 13:10:54 GMT 2020 armv6l 1.3.6.1.2.1.1.2.0|6|1.3.6.1.4.1.8072.3.2.10 -1.3.6.1.2.1.1.3.0|67|1103027 +1.3.6.1.2.1.1.3.0|67|17584469 1.3.6.1.2.1.1.4.0|4| 1.3.6.1.2.1.1.5.0|4| 1.3.6.1.2.1.1.6.0|4| -1.3.6.1.2.1.25.1.1.0|67|1106322 -1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.1|4|57.3 +1.3.6.1.2.1.25.1.1.0|67|19291215 +1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.1|4|22.3 1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.2|4|1.2000 1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.3|4|1.2000 1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.4|4|1.2000 @@ -24,11 +24,10 @@ 1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.17|4|MPG4=2 1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.18|4|MJPG=2 1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.19|4|WMV9=disabled -1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.20|4|WMV9=disabled -1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.21|4|H264=enabled -1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.22|4|MPG2=1 -1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.23|4|WVC1=1 -1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.24|4|MPG4=enabled -1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.25|4|MJPG=enabled -1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.26|4|WMV9=1 -1.3.6.1.6.3.10.2.1.3.0|2|11029 +1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.20|4|H264=enabled +1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.21|4|MPG2=1 +1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.22|4|WVC1=1 +1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.23|4|MPG4=enabled +1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.24|4|MJPG=enabled +1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.25|4|WMV9=1 +1.3.6.1.6.3.10.2.1.3.0|2|175845