Add deviation power to cisco_temperature.dom

Hello,

I wrote this patch to add the power difference verification against the first reading.

I think detecting this difference is perhaps more significant than setting a simple power threshold

I hope it can be integrated into one of the next releases.

--- share/check_mk/checks/cisco_temperature.orig	2020-06-10 10:44:26.000000000 +0200
+++ share/check_mk/checks/cisco_temperature	2020-06-10 10:49:55.636245186 +0200
@@ -344,6 +344,9 @@
 #   '----------------------------------------------------------------------'

 discovery_cisco_dom_rules = []
+factory_settings['cisco_temperature_dom_default_levels'] = {
+    'deviation_levels': (1.00, 2.00),
+}


 def inventory_cisco_temperature_dom(parsed):
@@ -357,7 +360,7 @@
         dev_state = attrs.get('raw_dev_state')
         adm_state = attrs.get('admin_state')
         if dev_state == '1' and adm_state in admin_states_to_discover:
-            yield item, {}
+            yield item, {"first_reading": attrs.get('reading')}


 def _determine_levels(user_levels, device_levels):
@@ -398,10 +401,28 @@
         dsname = "signal_power_dbm"
     yield check_levels(reading, dsname, levels, unit='dBm', infoname="Signal power")

+    # Verify deviation from first reading
+    first_reading = params.get('first_reading')
+    if first_reading is not None:
+        deviation_levels_upper = params.get('deviation_levels') or (None, None)
+        # The deviation levels are absolute, but the difference can also be negative.
+        # Specular levels are created for negative deviations.
+        # 'human_readable_func = abs' is not used to have the graph with both positive and negative values.
+        if all(deviation_levels_upper):
+            deviation_levels_lower = tuple([x * -1 for x in deviation_levels_upper])
+        else:
+            deviation_levels_lower = (None,None)
+        levels = ( deviation_levels_upper + deviation_levels_lower )
+
+        deviation = reading - first_reading
+        dsname = "deviation_dbm"
+        yield check_levels(deviation, dsname, levels, unit='dBm', infoname="Deviation")
+

 check_info['cisco_temperature.dom'] = {
     "inventory_function": inventory_cisco_temperature_dom,
     "check_function": check_cisco_temperature_dom,
+    "default_levels_variable" : "cisco_temperature_dom_default_levels",
     "service_description": "DOM %s",
     "group": "cisco_dom",
     "has_perfdata": True,
--- lib/python/cmk/gui/plugins/metrics/check_mk.py.orig	2020-06-05 11:57:23.219924935 +0200
+++ lib/python/cmk/gui/plugins/metrics/check_mk.py	2020-06-19 14:27:45.010495963 +0200
@@ -1771,6 +1771,12 @@
     "color": "#2080c0",
 }

+metric_info["deviation_dbm"] = {
+    "title": _("Deviation"),
+    "unit": "dbm",
+    "color": "#b39eb5",
+}
+
 metric_info["signal_power_dbm"] = {
     "title": _("Power"),
     "unit": "dbm",
--- lib/python/cmk/gui/plugins/wato/check_parameters/cisco_dom.py.orig	2020-06-04 22:32:28.447985936 +0200
+++ lib/python/cmk/gui/plugins/wato/check_parameters/cisco_dom.py	2020-06-19 14:25:32.957293178 +0200
@@ -87,6 +87,26 @@
             ]))


+def _vs_cisco_dom_deviation():
+    return (
+        "deviation_levels",
+        Alternative(
+            title="Levels for the deviation",
+            style="dropdown",
+            elements=[
+                Tuple(title=_("Use the following levels"),
+                      elements=[
+                          Float(title=_(u"Warnig at"),   default_value=1.00, unit=_("dBm")),
+                          Float(title=_(u"Critical at"), default_value=2.00, unit=_("dBm")),
+                      ]),
+                FixedValue(
+                    False,
+                    title=_("No levels"),
+                    totext="",
+                ),
+            ]))
+
+
 def _item_spec_cisco_dom():
     return TextAscii(title=_("Sensor description if present, sensor index otherwise"))

@@ -95,6 +115,7 @@
     return Dictionary(elements=[
         (_vs_cisco_dom("upper")),
         (_vs_cisco_dom("lower")),
+        (_vs_cisco_dom_deviation()),
     ],)

Hi @Andrea_Gabellini, thanks for the feedback! Did you create a pull request on the Checkmk GitHub repo?

Hello,

I’m not very good with git, but I created this PR:

I hope it’s well done.

Andrea