Module: check_mk
Branch: master
Commit: 2bd37776d6336a88efaaace98606f3a9fa56b4ae
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2bd37776d6336a…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Jan 19 12:15:05 2012 +0100
if64: Fetching and displaying MAC address information now
---
checks/if.include | 14 ++++++++++----
checks/if64 | 1 +
modules/snmp.py | 11 +++++++++++
3 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/checks/if.include b/checks/if.include
index 1c96cbc..a003d2a 100644
--- a/checks/if.include
+++ b/checks/if.include
@@ -85,15 +85,17 @@ def if_pad_with_zeroes(info, ifIndex):
def inventory_if_common(info):
- if len(info) == 0 or len(info[0]) != 19:
+ if len(info) == 0 or len(info[0]) != 20:
return []
pre_inventory = []
seen_items = set([])
duplicate = set([])
- for ifIndex, ifDescr, ifType, ifSpeed, ifOperStatus, ifInOctets, inucast, inmcast,
inbcast, ifInDiscards, \
- ifInErrors, ifOutOctets, outucast, outmcast, outbcast, ifOutDiscards,
ifOutErrors, ifOutQLen, ifAlias in info:
+ for ifIndex, ifDescr, ifType, ifSpeed, ifOperStatus, ifInOctets, \
+ inucast, inmcast, inbcast, ifInDiscards, ifInErrors, ifOutOctets, \
+ outucast, outmcast, outbcast, ifOutDiscards, ifOutErrors, \
+ ifOutQLen, ifAlias, ifPhysAddress in info:
ifDescr = cleanup_if_strings(ifDescr)
ifAlias = cleanup_if_strings(ifAlias)
@@ -156,7 +158,7 @@ def check_if_common(item, params, info):
for ifIndex, ifDescr, ifType, ifSpeed, ifOperStatus, ifInOctets, \
inucast, inmcast, inbcast, ifInDiscards, ifInErrors, ifOutOctets, \
outucast, outmcast, outbcast, ifOutDiscards, ifOutErrors, \
- ifOutQLen, ifAlias in info:
+ ifOutQLen, ifAlias, ifPhysAddress in info:
ifDescr = cleanup_if_strings(ifDescr)
ifAlias = cleanup_if_strings(ifAlias)
@@ -202,6 +204,10 @@ def check_if_common(item, params, info):
else:
ref_speed = None
+ if ifPhysAddress:
+ ifPhysAddress = ':'.join(convert_to_hex(ifPhysAddress).strip().split('
'))
+ infotext += 'MAC: %s, ' % ifPhysAddress
+
# Check speed settings of interface, but only if speed information
# is available. This is not always the case.
if speed:
diff --git a/checks/if64 b/checks/if64
index b1ea658..175d98b 100644
--- a/checks/if64
+++ b/checks/if64
@@ -56,6 +56,7 @@ snmp_info['if64'] = \
"2.2.1.20", # ifOutErrors 16
"2.2.1.21", # ifOutQLen 17
"31.1.1.1.18", # ifAlias 18
+ "2.2.1.6", # ifPhysAddress 19
] )
# check if number of network interfaces (IF-MIB::ifNumber.0) is at least 2
diff --git a/modules/snmp.py b/modules/snmp.py
index 73e9d36..8e17c11 100644
--- a/modules/snmp.py
+++ b/modules/snmp.py
@@ -66,6 +66,17 @@ def convert_from_hex(value):
r += chr(int(hx, 16))
return r
+# Converts back the values converted by the snmp code of Check_MK.
+# e.g. In case of MAC addresses it is not ok to convert the value.
+# Though we need the original value back.
+def convert_to_hex(value):
+ r = ''
+ for c in value:
+ h = hex(ord(c)).replace('0x', '')
+ if len(h) == 1:
+ h = '0' + h
+ r += h + ' '
+ return r + ' '
def oid_to_bin(oid):
return u"".join([ unichr(int(p)) for p in
oid.strip(".").split(".") ])