[checkmk-commits] Check_MK Git: check_mk: Small update for lantime checks

Mathias Kettner mk at mathias-kettner.de
Wed Feb 4 17:16:28 CET 2015


Module: check_mk
Branch: master
Commit: fce48dad55d49c6e365b9103b5203de351fd8a89
URL:    http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=fce48dad55d49c6e365b9103b5203de351fd8a89

Author: Mathias Kettner <mk at mathias-kettner.de>
Date:   Wed Feb  4 17:16:25 2015 +0100

Small update for lantime checks

---

 checks/mbg_lantime.include  |   34 ++++++++++++++++++++++------------
 checks/mbg_lantime_ng_state |   31 +++++++++++++------------------
 checks/mbg_lantime_state    |   38 +++++++++++++++++---------------------
 3 files changed, 52 insertions(+), 51 deletions(-)

diff --git a/checks/mbg_lantime.include b/checks/mbg_lantime.include
index bda2881..1a94b86 100644
--- a/checks/mbg_lantime.include
+++ b/checks/mbg_lantime.include
@@ -24,45 +24,55 @@
 # to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
 # Boston, MA 02110-1301 USA.
 
+
+factory_settings['mbg_lantime_state_default_levels'] = {
+     "stratum" : (1,   1),
+     "offset"  : (500, 1000), # ms
+}
+
+
 def inventory_mbg_lantime_state_common(info):
     return [(None, {})]
 
+
 def check_mbg_lantime_state_common(states, _no_item, params, info):
     ntp_state, stratum, refclock_name, refclock_offset = info[0]
     if type(params) != dict:
         params = {
              'stratum' : (params[0], params[1]),
-             'offset' : (params[2], params[3]),
+             'offset'  : (params[2], params[3]),
         }
 
     # Handle State
     yield states[ntp_state][0], "State: " + states[ntp_state][1]
 
-    # handle the reported stratum
+    # Check the reported stratum
     state = 0
-    levels = ""
+    levels_text = ""
     warn, crit = params['stratum']
     if int(stratum) > crit:
         state = 2
     elif int(stratum) > warn:
         state = 1
     if state != 0:
-        levels = " (Warn/Crit at %s/%s)" % (warn, crit)
-    yield state, "Stratum: %s%s" % (stratum, levels)
+        levels_text = " (warn/crit at %d/%d)" % (warn, crit)
+    yield state, "Stratum: %s%s" % (stratum, levels_text)
 
     # Add refclock information
-    yield 0, 'Refclock: ' + refclock_name
+    yield 0, 'Reference clock: ' + refclock_name
 
+    # Check offset
     state = 0
-    levels = ""
+    levels_text = ""
     warn, crit = params['offset']
-    pos_refclock_offset = abs(float(refclock_offset))
-    if pos_refclock_offset > crit:
+    refclock_offset = float(refclock_offset)
+    pos_refclock_offset = abs(refclock_offset)
+    if pos_refclock_offset >= crit:
         state = 2
-    elif pos_refclock_offset > warn:
+    elif pos_refclock_offset >= warn:
         state = 1
     if state != 0:
-        levels = " (Warn/Crit at %d/%d ms)"
+        levels_text = " (warn/crit at %d/%d ms)" % (warn, crit)
     perfdata = [('offset', refclock_offset, warn, crit )]
-    yield state, 'Refclock Offset: %0.4f ms%s' % (float(refclock_offset) / 1000, levels), perfdata
+    yield state, 'Reference clock offset: %g us%s' % (refclock_offset, levels_text), perfdata
 
diff --git a/checks/mbg_lantime_ng_state b/checks/mbg_lantime_ng_state
index d12f433..9445b5f 100644
--- a/checks/mbg_lantime_ng_state
+++ b/checks/mbg_lantime_ng_state
@@ -24,34 +24,29 @@
 # to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
 # Boston, MA 02110-1301 USA.
 
-factory_settings['mbg_lantime_ng_state'] = {
-     "stratum" : ( 2, 3 ),
-     "offset" : ( 500, 1000),
-}
-
-mbg_lantime_ng_states = {
-          '0': (2,  'notAvailable'),
-          '1': (2,  'notSynchronized'),
-          '2': (0,  'synchronized'),
-}
+def check_mbg_lantime_nb_state(_no_item, params, info):
+    states = {
+        '0': (2, 'not aailable'),
+        '1': (2, 'not synchronized'),
+        '2': (0, 'synchronized'),
+    }
+    return check_mbg_lantime_state_common(states, _no_item, params, info)
 
 
 check_info["mbg_lantime_ng_state"] = {
-    'check_function'            : lambda item, params, info: \
-        check_mbg_lantime_state_common(mbg_lantime_ng_states, item, params, info),
+    'check_function'            : check_mbg_lantime_nb_state,
     'inventory_function'        : inventory_mbg_lantime_state_common,
     'service_description'       : 'LANTIME State',
     'has_perfdata'              : True,
-    'default_levels_variable'   : "mbg_lantime_ng_state",
+    'default_levels_variable'   : "mbg_lantime_state_default_levels",
     'group'                     : 'mbg_lantime_state',
-    'includes'                  : ["mbg_lantime.include"],
     'snmp_info'                 : ('.1.3.6.1.4.1.5597.30.0.2', [
-                                    1, # MBG-SNMP-LTNG-MIB::mbgLtNgNtpCurrentState 
+                                    1, # MBG-SNMP-LTNG-MIB::mbgLtNgNtpCurrentState
                                     2, # MBG-SNMP-LTNG-MIB::mbgLtNgNtpStratum
                                     3, # MBG-SNMP-LTNG-MIB::mbgLtNgNtpRefclockName
                                     4, # MBG-SNMP-LTNG-MIB::mbgLtNgNtpRefclockOffset
                                   ]),
-    'snmp_scan_function'        : \
-          lambda oid: oid(".1.3.6.1.2.1.1.2.0") == ".1.3.6.1.4.1.5597.3" and \
-          oid(".1.3.6.1.4.1.5597.30.0.2.*"),
+    'snmp_scan_function'        : lambda oid: (oid(".1.3.6.1.2.1.1.2.0") == ".1.3.6.1.4.1.5597.3" and \
+                                               oid(".1.3.6.1.4.1.5597.30.0.2.*")),
+    'includes'                  : ["mbg_lantime.include"],
 }
diff --git a/checks/mbg_lantime_state b/checks/mbg_lantime_state
index 12c3468..bee78ea 100644
--- a/checks/mbg_lantime_state
+++ b/checks/mbg_lantime_state
@@ -24,36 +24,32 @@
 # to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
 # Boston, MA 02110-1301 USA.
 
-factory_settings['mbg_lantime_state_default_levels'] = {
-     "stratum" : ( 0, 0 ),
-     "offset" : ( 500, 1000),
-}
+def check_mbg_lantime_state(_no_item, params, info):
+    states = {
+      '0': (2 ,'not synchronized'                 ),
+      '1': (2 ,'no good reference clock'          ),
+      '2': (0 ,'sync to external reference clock' ),
+      '3': (0 ,'sync to serial refernce clock'    ),
+      '4': (0 ,'normal operation PPS'             ),
+      '5': (0 ,'normal operation reference clock' ),
+    }
+    return check_mbg_lantime_state_common(states, _no_item, params, info)
 
-mbg_lantime_states = {
-  '0': (2 ,'notSynchronized'),
-  '1': (2 ,'noGoodRefclock'),
-  '2': (0 ,'syncToExtRefclock'),
-  '3': (0 ,'syncToSerialRefclock'),
-  '4': (0 ,'normalOperationPPS'),
-  '5': (0 ,'normalOperationRefclock'),
-}
 
 check_info["mbg_lantime_state"] = {
-    'check_function'            : lambda item, params, info: \
-        check_mbg_lantime_state_common(mbg_lantime_states, item, params, info),
+    'check_function'            : check_mbg_lantime_state,
     'inventory_function'        : inventory_mbg_lantime_state_common,
     'service_description'       : 'LANTIME State',
-    'has_perfdata':            True,
+    'has_perfdata'              : True,
     'group'                     : 'mbg_lantime_state',
     'default_levels_variable'   : "mbg_lantime_state_default_levels",
-    'includes'                  : ["mbg_lantime.include"],
-    'snmp_info':               ('.1.3.6.1.4.1.5597.3.1', [
+    'snmp_info'                 : ('.1.3.6.1.4.1.5597.3.1', [
                                     2, # MBG-SNMP-MIB::mbgLtNtpCurrentStateVal
                                     3, # MBG-SNMP-MIB::mbgLtNtpNtpStratum
                                     5, # MBG-SNMP-MIB::mbgLtNtpActiveRefclockName
                                     7, # MBG-SNMP-MIB::mbgLtNtpActiveRefclockOffsetVal
-                                ]),
-    'snmp_scan_function':      \
-          lambda oid: oid(".1.3.6.1.2.1.1.2.0") == ".1.3.6.1.4.1.5597.3" and not \
-              oid(".1.3.6.1.4.1.5597.30.0.2.*"),
+                                  ]),
+    'snmp_scan_function'        : lambda oid: (oid(".1.3.6.1.2.1.1.2.0") == ".1.3.6.1.4.1.5597.3" and not \
+                                              oid(".1.3.6.1.4.1.5597.30.0.2.*")),
+    'includes'                  : ["mbg_lantime.include"],
 }



More information about the checkmk-commits mailing list