Module: check_mk
Branch: master
Commit: 250af3c3f07b0c1c3ef784db6a9f376784ac0f97
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=250af3c3f07b0c…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Fri Sep 28 11:25:45 2018 +0200
6789 esx_vsphere_sensors: List sensors in long output
Also major cleanup and some tests.
Change-Id: I97417ea1068e4c6157184849407013c3b8159c9c
---
.werks/6789 | 9 ++++
checks/esx_vsphere_sensors | 57 ++++++++++------------
.../generictests/datasets/esx_vsphere_sensors_1.py | 35 +++++++++++++
.../generictests/datasets/esx_vsphere_sensors_2.py | 16 ++++++
4 files changed, 86 insertions(+), 31 deletions(-)
diff --git a/.werks/6789 b/.werks/6789
new file mode 100644
index 0000000..5f875c1
--- /dev/null
+++ b/.werks/6789
@@ -0,0 +1,9 @@
+Title: esx_vsphere_sensors: List sensors in long output
+Level: 1
+Component: checks
+Compatible: comp
+Edition: cre
+Version: 1.6.0i1
+Date: 1538126830
+Class: feature
+
diff --git a/checks/esx_vsphere_sensors b/checks/esx_vsphere_sensors
index 7fb855b..d7f69db 100644
--- a/checks/esx_vsphere_sensors
+++ b/checks/esx_vsphere_sensors
@@ -35,46 +35,41 @@
# Power Domain 1 Power Unit 0 - Redundancy lost;;0;power;0;;yellow;Yellow;Sensor is
operating under conditions that are non-critical
# Power Supply 2 Power Supply 2 0: Power Supply AC lost -
Assert;;0;power;0;;red;Red;Sensor is operating under critical conditions
+
def inventory_esx_vsphere_sensors(info):
- return [(None, [])]
+ yield None, []
+
def check_esx_vsphere_sensors(_no_item, params, info):
- state = 0
- infos = []
- sensor_state_modified = False
+ mulitline = ["All sensors are in normal state", "Sensors operating
normal are:"]
+ mod_msg = " (Alert state has been modified by Check_MK rule)"
- for name, _base_units, _current_reading, _sensor_type, _unit_modifier, _rate_units,
health_key, health_label, health_summary in info:
- health_key = health_key.lower()
- if health_key == "green":
- continue # usually not output by agent anyway
+ for name, _base_units, _current_reading, _sensor_type, _unit_modifier, \
+ _rate_units, health_key, health_label, health_summary in info:
- infos.append("%s: %s (%s)" % (name, health_label, health_summary))
- sensor_state = 0
- if health_key == "yellow":
- sensor_state = 1
- elif health_key == "unknown":
- sensor_state = 3
- else:
- sensor_state = 2
+ sensor_state = {
+ "green": 0,
+ "yellow": 1,
+ "red": 2,
+ "unknown": 3
+ }.get(health_key.lower(), 2)
+ txt = "%s: %s (%s)" % (name, health_label, health_summary)
- extra_info = ""
- if params:
- for entry in params:
- if name.startswith(entry.get("name")):
- new_state = entry.get("states").get(str(sensor_state))
- if new_state != None:
- sensor_state = new_state
- extra_info = "(Alert state has been modified by
Check_MK rule)"
- sensor_state_modified = True
+ for entry in params:
+ if name.startswith(entry.get("name", "")):
+ new_state = entry.get("states", {}).get(str(sensor_state))
+ if new_state is not None:
+ sensor_state = new_state
+ txt += mod_msg
+ break
+ if sensor_state > 0 or txt.endswith(mod_msg):
+ yield sensor_state, txt
+ mulitline[:2] = "", "At least one sensor reported. Sensors
readings are:"
+ mulitline.append(txt)
- state = max(state, sensor_state)
- infos[-1] += ["", "(!)", "(!!)",
"(?)"][state]
- infos[-1] += extra_info
+ yield 0, '\n'.join(mulitline)
- if state > 0 or sensor_state_modified:
- return state, ", ".join(infos)
- return 0, "All sensors are in normal state"
check_info['esx_vsphere_sensors'] = {
"inventory_function" : inventory_esx_vsphere_sensors,
diff --git a/tests/unit/checks/generictests/datasets/esx_vsphere_sensors_1.py
b/tests/unit/checks/generictests/datasets/esx_vsphere_sensors_1.py
new file mode 100644
index 0000000..64b7983
--- /dev/null
+++ b/tests/unit/checks/generictests/datasets/esx_vsphere_sensors_1.py
@@ -0,0 +1,35 @@
+
+
+checkname = 'esx_vsphere_sensors'
+
+
+info = [
+ ['VMware Rollup Health State', '', '0', 'system',
'0', '', 'red', 'Red',
+ 'Sensor is operating under critical conditions'],
+ ['Power Domain 1 Power Unit 0 - Redundancy lost', '', '0',
'power', '0', '',
+ 'yellow', 'Yellow', 'Sensor is operating under conditions that
are non-critical'],
+ ['Power Supply 2 Power Supply 2 0: Power Supply AC lost - Assert',
'', '0', 'power',
+ '0', '', 'red', 'Red', 'Sensor is operating
under critical conditions'],
+ ['Dummy sensor', '', '', '', '', '',
'green', 'all is good', 'the sun is shining']
+]
+
+
+discovery = {'': [(None, [])]}
+
+
+checks = {
+ '': [(None, 'default', [
+ (2, 'VMware Rollup Health State: Red (Sensor is operating under critical
'
+ 'conditions)', []),
+ (1, 'Power Domain 1 Power Unit 0 - Redundancy lost: Yellow '
+ '(Sensor is operating under conditions that are non-critical)',
[]),
+ (2, 'Power Supply 2 Power Supply 2 0: Power Supply AC lost - Assert: Red
'
+ '(Sensor is operating under critical conditions)', []),
+ (0, ('\nAt least one sensor reported. Sensors readings are:\n'
+ 'VMware Rollup Health State: Red (Sensor is operating under critical
conditions)\n'
+ 'Power Domain 1 Power Unit 0 - Redundancy lost: Yellow (Sensor is
operating under conditions that are non-critical)\n'
+ 'Power Supply 2 Power Supply 2 0: Power Supply AC lost - Assert: Red
(Sensor is operating under critical conditions)\n'
+ 'Dummy sensor: all is good (the sun is shining)'), [])]
+ ),
+ ],
+}
diff --git a/tests/unit/checks/generictests/datasets/esx_vsphere_sensors_2.py
b/tests/unit/checks/generictests/datasets/esx_vsphere_sensors_2.py
new file mode 100644
index 0000000..a2ed95d
--- /dev/null
+++ b/tests/unit/checks/generictests/datasets/esx_vsphere_sensors_2.py
@@ -0,0 +1,16 @@
+
+
+checkname = 'esx_vsphere_sensors'
+
+
+info = [
+ ['Dummy sensor', '', '', '', '', '',
'green', 'all is good', 'the sun is shining']
+]
+
+
+discovery = {'': [(None, [])]}
+
+
+checks = {'': [(None, 'default', [(0, ('All sensors are in normal
state\n'
+ 'Sensors operating normal are:\n'
+ 'Dummy sensor: all is good (the sun is
shining)'), [])])]}