Module: check_mk
Branch: master
Commit: d4d8baedb60b9edc4471ab524129b7270d950a7a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d4d8baedb60b9e…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Thu Mar 30 09:16:49 2017 +0200
Unified rendering MAC address in interface check and inventory plugins for SNMP devices
Change-Id: I274c2f8fb99bb87be58be4f73c037c3009d85df4
---
checks/if | 2 +-
checks/if.include | 15 +++++++++------
checks/if64_tplink | 38 +++++++++++++++++++-------------------
checks/if_brocade | 2 +-
checks/if_lancom | 2 +-
inventory/if | 8 +++-----
6 files changed, 34 insertions(+), 33 deletions(-)
diff --git a/checks/if b/checks/if
index 7867542..6832df8 100644
--- a/checks/if
+++ b/checks/if
@@ -60,7 +60,7 @@ check_info["if"] = {
19, # ifOutDiscards 13
20, # ifOutErrors 14
21, # ifOutQLen 15
- 6, # ifPhysAddress 16
+ BINARY(6), # ifPhysAddress 16
]),
# check if number of network interfaces (IF-MIB::ifNumber.0) is at least 2
# use if64 if possible and not disabled
diff --git a/checks/if.include b/checks/if.include
index 575952a..06ac2e0 100644
--- a/checks/if.include
+++ b/checks/if.include
@@ -105,6 +105,14 @@ def if_extract_node(line, has_nodeinfo):
return None, line
+def if_render_mac_address(ifPhysAddress):
+ if type(ifPhysAddress) != list:
+ mac_bytes = map(ord, ifPhysAddress)
+ else:
+ mac_bytes = ifPhysAddress
+ return (":".join(["%02s" % hex(m)[2:] for m in
mac_bytes]).replace(' ', '0')).upper()
+
+
def if_item_matches(item, ifIndex, ifAlias, ifDescr):
return item.lstrip("0") == ifIndex \
or (item == "0" * len(item) and saveint(ifIndex) == 0) \
@@ -846,12 +854,7 @@ def check_if_common_single(item, params, info, force_counter_wrap =
False,
ref_speed = None
if ifPhysAddress:
- if type(ifPhysAddress) != list:
- mac_bytes = map(ord, ifPhysAddress)
- else:
- mac_bytes = ifPhysAddress
- mac = ":".join(["%02s" % hex(m)[2:] for m in
mac_bytes]).replace(' ', '0')
- infotext += 'MAC: %s, ' % mac
+ infotext += 'MAC: %s, ' % if_render_mac_address(ifPhysAddress)
# Check speed settings of interface, but only if speed information
# is available. This is not always the case.
diff --git a/checks/if64_tplink b/checks/if64_tplink
index cc86b2a..2359d6b 100644
--- a/checks/if64_tplink
+++ b/checks/if64_tplink
@@ -42,26 +42,26 @@ check_info["if64_tplink"] = {
'has_perfdata': True,
'includes': [ 'if.include' ],
'snmp_info': ( ".1.3.6.1", [
- "2.1.2.2.1.1", # ifIndex 0
- "2.1.2.2.1.2", # ifDescr 1
- "2.1.2.2.1.3", # ifType 2
- "2.1.31.1.1.1.15", # ifHighSpeed .. 1000 means 1Gbit
- "2.1.2.2.1.8", # ifOperStatus 4
- "2.1.31.1.1.1.6", # ifHCInOctets 5
- "2.1.31.1.1.1.7", # ifHCInUcastPkts 6
- "2.1.31.1.1.1.8", # ifHCInMulticastPkts 7
- "2.1.31.1.1.1.9", # ifHCInBroadcastPkts 8
- "2.1.2.2.1.13", # ifInDiscards 9
- "2.1.2.2.1.14", # ifInErrors 10
- "2.1.31.1.1.1.10", # ifHCOutOctets 11
- "2.1.31.1.1.1.11", # ifHCOutUcastPkts 12
- "2.1.31.1.1.1.12", # ifHCOutMulticastPkts 13
- "2.1.31.1.1.1.13", # ifHCOutBroadcastPkts 14
- "2.1.2.2.1.19", # ifOutDiscards 15
- "2.1.2.2.1.20", # ifOutErrors 16
- "2.1.2.2.1.21", # ifOutQLen 17
+ "2.1.2.2.1.1", # ifIndex 0
+ "2.1.2.2.1.2", # ifDescr 1
+ "2.1.2.2.1.3", # ifType 2
+ "2.1.31.1.1.1.15", # ifHighSpeed .. 1000
means 1Gbit
+ "2.1.2.2.1.8", # ifOperStatus 4
+ "2.1.31.1.1.1.6", # ifHCInOctets 5
+ "2.1.31.1.1.1.7", # ifHCInUcastPkts 6
+ "2.1.31.1.1.1.8", # ifHCInMulticastPkts 7
+ "2.1.31.1.1.1.9", # ifHCInBroadcastPkts 8
+ "2.1.2.2.1.13", # ifInDiscards 9
+ "2.1.2.2.1.14", # ifInErrors 10
+ "2.1.31.1.1.1.10", # ifHCOutOctets 11
+ "2.1.31.1.1.1.11", # ifHCOutUcastPkts 12
+ "2.1.31.1.1.1.12", # ifHCOutMulticastPkts 13
+ "2.1.31.1.1.1.13", # ifHCOutBroadcastPkts 14
+ "2.1.2.2.1.19", # ifOutDiscards 15
+ "2.1.2.2.1.20", # ifOutErrors 16
+ "2.1.2.2.1.21", # ifOutQLen 17
"4.1.11863.1.1.3.2.1.1.1.1.2", # special for TP Link
- "2.1.2.2.1.6", # ifPhysAddress 19
+ BINARY("2.1.2.2.1.6"), # ifPhysAddress 19
]),
'snmp_scan_function': \
lambda oid: ".4.1.11863." in oid(".1.3.6.1.2.1.1.2.0") and
\
diff --git a/checks/if_brocade b/checks/if_brocade
index c6cc193..69b08cf 100644
--- a/checks/if_brocade
+++ b/checks/if_brocade
@@ -81,7 +81,7 @@ check_info["if_brocade"] = {
"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
+ BINARY("2.2.1.6"), # ifPhysAddress 19
# Used in order to ignore some logical NICs
"2.2.1.2", # ifDescr 20
]),
diff --git a/checks/if_lancom b/checks/if_lancom
index 15f3c4b..99e5e51 100644
--- a/checks/if_lancom
+++ b/checks/if_lancom
@@ -81,7 +81,7 @@ check_info["if_lancom"] = {
"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
+ BINARY("2.2.1.6"), # ifPhysAddress 19
# Used in order to ignore some logical NICs
"2.2.1.2", # ifDescr 20
]),
diff --git a/inventory/if b/inventory/if
index 7d6e182..b24bc6a 100644
--- a/inventory/if
+++ b/inventory/if
@@ -40,9 +40,6 @@ def inv_if(info, params):
[ '6', '32', '62', '117', '127',
'128', '129', '180', '181', '182', '205',
'229' ])
unused_duration = params.get("unused_duration", 30 * 86400)
- def render_mac_address(bytestring):
- return ":".join(["%02s" % hex(ord(m))[2:] for m in
bytestring]).replace(' ', '0').upper()
-
total_ethernet_ports = 0
available_ethernet_ports = 0
@@ -87,7 +84,7 @@ def inv_if(info, params):
"description" : if_descr,
"alias" : if_alias,
"speed" : speed,
- "phys_address" : render_mac_address(if_phys_address),
+ "phys_address" : if_render_mac_address(if_phys_address),
"oper_status" : int(if_oper_status),
"admin_status" : int(if_admin_status), # 1(up) or 2(down)
"port_type" : int(if_type),
@@ -121,10 +118,11 @@ inv_info['inv_if'] = {
"31.1.1.1.15", # ifHighSpeed .. 1000 means 1Gbit
"2.2.1.8", # ifOperStatus
"2.2.1.7", # ifAdminStatus
- "2.2.1.6", # ifPhysAddress
+ BINARY("2.2.1.6"), # ifPhysAddress
"2.2.1.9", # ifLastChange
]),
( ".1.3.6.1.2.1.1", [ "3.0" ] ), # uptime
],
'snmp_scan_function': lambda oid: int(oid(".1.3.6.1.2.1.2.1.0"))
>= 2,
+ 'includes': ['if.include'],
}