[checkmk-commits] Check_MK Git: check_mk: #2196 winperf_if: for Windows interfaces show original Windows state names

Mathias Kettner mk at mathias-kettner.de
Fri Apr 10 11:10:43 CEST 2015


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

Author: Mathias Kettner <mk at mathias-kettner.de>
Date:   Fri Apr 10 11:10:29 2015 +0200

#2196 winperf_if: for Windows interfaces show original Windows state names

---

 .werks/2196       |    9 +++++++
 ChangeLog         |    1 +
 checks/if.include |   29 ++++++++++++++++++-----
 checks/winperf_if |   68 +++++++++++++++++++++++------------------------------
 4 files changed, 63 insertions(+), 44 deletions(-)

diff --git a/.werks/2196 b/.werks/2196
new file mode 100644
index 0000000..05c2ce2
--- /dev/null
+++ b/.werks/2196
@@ -0,0 +1,9 @@
+Title: winperf_if: for Windows interfaces show original Windows state names
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.2.7i1
+Date: 1428657010
+Class: feature
+
+
diff --git a/ChangeLog b/ChangeLog
index 55b998a..2c789bf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -157,6 +157,7 @@
     * 2185 canon_pages: added support for b/w A4 and color A4/A3 counters
     * 2186 check_mk_agent.aix: use GNU df in order to exclude NFS for filesystem monitoring...
     * 2112 hitachi_hnas_bossock: new check to monitor number of running Bossock Fibers
+    * 2196 winperf_if: for Windows interfaces show original Windows state names
     * 1457 FIX: logins: new check renamed from "users" check...
             NOTE: Please refer to the migration notes!
     * 1762 FIX: lnx_thermal: Now ignoring trip points with level 0...
diff --git a/checks/if.include b/checks/if.include
index 4bc7a38..1a2f694 100644
--- a/checks/if.include
+++ b/checks/if.include
@@ -247,6 +247,11 @@ def inventory_if_common(info, has_nodeinfo = False):
             outucast, outmcast, outbcast, ifOutDiscards, ifOutErrors, \
             ifOutQLen, ifAlias, ifPhysAddress = line
 
+        # Windows NICs sends pairs of ifOperStatus and its Windows-Name instead
+        # of just the ifOperStatus
+        if type(ifOperStatus) == tuple:
+            ifOperStatus = ifOperStatus[0]
+
         ifGroup = None
         if type(ifIndex) == tuple:
             ifGroup, ifIndex = ifIndex
@@ -403,12 +408,19 @@ def check_if_common(item, params, info, has_nodeinfo = False, group_name = "Grou
                 outucast, outmcast, outbcast, ifOutDiscards, ifOutErrors, \
                 ifOutQLen, ifAlias, ifPhysAddress = line
 
+            # Windows NICs sends pairs of ifOperStatus and its Windows-Name instead
+            # of just the ifOperStatus
+            if type(ifOperStatus) == tuple:
+                ifOperStatus, ifOperStatusName = ifOperStatus
+            else:
+                ifOperStatusName = if_statename(ifOperStatus)
+
             ifGroup = None
             if type(ifIndex) == tuple:
                 ifGroup, ifIndex = ifIndex
 
             if_item = get_interface_item(element)
-            group_members.append({"name": if_item, "state": ifOperStatus})
+            group_members.append({"name": if_item, "state": ifOperStatus, "state_name" : ifOperStatusName})
             perfdata = []
 
             # Only these values are packed into counters
@@ -535,6 +547,13 @@ def check_if_common_single(item, params, info, force_counter_wrap = False,
             outucast, outmcast, outbcast, ifOutDiscards, ifOutErrors, \
             ifOutQLen, ifAlias, ifPhysAddress = line
 
+        # Windows NICs sends pairs of ifOperStatus and its Windows-Name instead
+        # of just the ifOperStatus
+        if type(ifOperStatus) == tuple:
+            ifOperStatus, ifOperStatusName = ifOperStatus
+        else:
+            ifOperStatusName = if_statename(ifOperStatus)
+
         ifGroup = None
         if type(ifIndex) == tuple:
             ifGroup, ifIndex = ifIndex
@@ -567,22 +586,20 @@ def check_if_common_single(item, params, info, force_counter_wrap = False,
 
             state = 0
 
-            operstatus = if_statename(str(ifOperStatus))
             if targetstate and  \
                 (ifOperStatus != targetstate
                 and not (type(targetstate) in [ list, tuple ] and ifOperStatus in targetstate)):
                 state = 2
-                infotext += "(%s)(!!) " % operstatus
+                infotext += "(%s)(!!) " % ifOperStatusName
             else:
-                infotext += "(%s) " % operstatus
+                infotext += "(%s) " % ifOperStatusName
 
             if group_members:
                 infotext = infotext[:-1] # remove last space
                 extra_info = ", Members: "
                 member_info = []
                 for member in group_members:
-                    member_operstatus = if_statename(str(member["state"]))
-                    member_info.append("%s (%s)" % (member["name"], member_operstatus))
+                    member_info.append("%s (%s)" % (member["name"], member["state_name"]))
                 infotext += extra_info + "[%s] " % ", ".join(member_info)
 
             # prepare reference speed for computing relative bandwidth usage
diff --git a/checks/winperf_if b/checks/winperf_if
index a25fcee..105fad8 100644
--- a/checks/winperf_if
+++ b/checks/winperf_if
@@ -208,19 +208,21 @@ def convert_winperf_if(info):
         connection_status = nic.get('NetConnectionStatus', '2')
 
         # Windows NetConnectionStatus Table
-        # 0 Disconnected
-        # 1 Connecting
-        # 2 Connected
-        # 3 Disconnecting
-        # 4 Hardware not present
-        # 5 Hardware disabled
-        # 6 Hardware malfunction
-        # 7 Media disconnected
-        # 8 Authenticating
-        # 9 Authentication succeeded
-        # 10 Authentication failed
-        # 11 Invalid address
-        # 12 Credentials required
+        connection_states = {
+            '0':  ('2', 'Disconnected'),
+            '1':  ('2', 'Connecting'),
+            '2':  ('1', 'Connected'),
+            '3':  ('2', 'Disconnecting'),
+            '4':  ('2', 'Hardware not present'),
+            '5':  ('2', 'Hardware disabled'),
+            '6':  ('2', 'Hardware malfunction'),
+            '7':  ('7', 'Media disconnected'),
+            '8':  ('2', 'Authenticating'),
+            '9':  ('2', 'Authentication succeeded'),
+            '10': ('2', 'Authentication failed'),
+            '11': ('2', 'Invalid address'),
+            '12': ('2', 'Credentials required'),
+        }
 
         # ifOperStatus Table
         # 1 up
@@ -231,37 +233,27 @@ def convert_winperf_if(info):
         # 6 notPresent
         # 7 lowerLayerDown
 
-        # NetConnectionStatus           : ifOperStatus
-        # 2 (Connected)                 : 1 (up)
-        # 7 (Media disconnected)        : 7 (lowerLayerDown)
-        # *                             : 2 (down)
-
-        if connection_status == '2':
-            ifoperstatus = '1'
-        elif connection_status == '7':
-            ifoperstatus = '7'
-        else:
-            ifoperstatus = '2'
+        ifoperstatus_annotated = connection_states[connection_status]
 
         converted.append((
            index_info,
            nic_name,
            "loopback" in nic_name.lower() and '24' or '6',
-           bandwidth or nic[10], # Bandwidth
-           ifoperstatus, # ifOperStatus
-           nic[-246], # ifInOctets,
-           nic[14], # inucast
-           0,       # inmcast
-           nic[16], # non-unicast empfangen
-           nic[18], # ifInDiscards
-           nic[20], # ifInErrors
-           nic[-4], # ifOutOctets (Bytes gesendet)
-           nic[26], # outucast
+           bandwidth or nic[10],   # Bandwidth
+           ifoperstatus_annotated, # ifOperStatus
+           nic[-246],              # ifInOctets,
+           nic[14],                # inucast
+           0,                      # inmcast
+           nic[16],                # non-unicast empfangen
+           nic[18],                # ifInDiscards
+           nic[20],                # ifInErrors
+           nic[-4],                # ifOutOctets (Bytes gesendet)
+           nic[26],                # outucast
            0,
-           nic[28], # outnonucast
-           nic[30], # ifOutDiscards
-           nic[32], # ifOutErrors
-           nic[34], # ifOutQLen
+           nic[28],                # outnonucast
+           nic[30],                # ifOutDiscards
+           nic[32],                # ifOutErrors
+           nic[34],                # ifOutQLen
            nic.get('NetConnectionID', nic_name),
            mac,
         ))



More information about the checkmk-commits mailing list