Module: check_mk
Branch: master
Commit: 9c84661c2adf6a05e1d075624b957dbf8cd0f89e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9c84661c2adf6a…
Author: Florian Heigl <fh(a)mathias-kettner.de>
Date: Tue Jul 12 14:02:02 2011 +0200
if/if64 fixed operstate monitoring
---
ChangeLog | 2 +
checks/if.include | 87 +++++++++++++++++++----------------------------------
2 files changed, 33 insertions(+), 56 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index abded47..93f605f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -18,6 +18,8 @@
* lnx_if: treat interfaces without information from ethtool as
softwareLoopback interface. The will not be found by inventory now.
* vbox_guest: new check for checking guest additions of Linux virtual box hosts
+ * if/if64: Fixed bug in operstate detection when using old tuple based params
+ * if/if64: Fixed bug in operstate detection when using tuple of valid operstates
Multisite:
* FIX: make non-Ascii characters in services names work again
diff --git a/checks/if.include b/checks/if.include
index 8213c17..9dcf206 100644
--- a/checks/if.include
+++ b/checks/if.include
@@ -68,29 +68,20 @@ def inventory_if_common(info):
if len(info) == 0 or len(info[0]) != 19:
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:
ifDescr = cleanup_if_strings(ifDescr)
ifAlias = cleanup_if_strings(ifAlias)
- # compute item now - also for unmonitored ports - in order to see if it
- # is uninque.
- if if_inventory_uses_description and ifDescr:
- item = ifDescr
- elif if_inventory_uses_alias and ifAlias:
- item = ifAlias
- else:
- item = ifIndex
-
- if item in seen_items: # duplicate
- duplicate.add(item)
- seen_items.add(item)
-
if ifType in if_inventory_porttypes and ifOperStatus in if_inventory_portstates:
+ if if_inventory_uses_description and ifDescr:
+ item = ifDescr
+ elif if_inventory_uses_alias and ifAlias:
+ item = ifAlias
+ else:
+ item = ifIndex
+
paramstring = '{ "errors" : if_default_error_levels, ' \
'"traffic" : if_default_traffic_levels, ' \
'"average" : if_default_average '
@@ -104,6 +95,13 @@ def inventory_if_common(info):
pre_inventory.append( (item, paramstring, int(ifIndex)) )
# Check for duplicate items (e.g. when using Alias as item and the alias is not
unique)
+ seen_items = set([])
+ duplicate = set([])
+ for item, params, index in pre_inventory:
+ if item in seen_items: # duplicate
+ duplicate.add(item)
+ seen_items.add(item)
+
inventory = []
for item, params, index in pre_inventory:
if item in duplicate:
@@ -111,7 +109,6 @@ def inventory_if_common(info):
else:
new_item = item
inventory.append((new_item, params))
-
return inventory
@@ -136,25 +133,21 @@ def check_if_common(item, params, info):
elif len(params) == 5:
err_warn, err_crit, targetspeed, bw_warn, bw_crit = params
elif len(params) == 6:
- err_warn, err_crit, targetspeed, bw_warn, bw_crit, allowed_operstates = params
+ err_warn, err_crit, targetspeed, bw_warn, bw_crit, targetstate = params
- 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 in info:
ifDescr = cleanup_if_strings(ifDescr)
ifAlias = cleanup_if_strings(ifAlias)
if item == ifIndex \
or item == ifAlias \
or item == ifDescr \
- or item == "%s %s" % (ifAlias, ifIndex) \
- or item == "%s %s" % (ifDescr, ifIndex):
+ or item == "%s %s" % (ifAlias, ifIndex):
# Display port number or alias in infotext if that is not part
# of the service description anyway
- if item == ifIndex and (item == ifAlias or ifAlias == '') \
- and (item == ifDescr or ifDescr == ''): # description trivial
+ if item == ifIndex and (item == ifAlias or ifAlias == '') and (item
== ifDescr or ifDescr == ''): # description trivial
infotext = ""
elif item == "%s %s" % (ifAlias, ifIndex) and ifDescr !=
'': # non-unique Alias
infotext = "[%s/%s]" % (ifAlias, ifDescr)
@@ -165,20 +158,23 @@ def check_if_common(item, params, info):
else:
infotext = "[%s] " % ifIndex
- state = 0
-
operstatus = if_statename(str(ifOperStatus))
if targetstate and \
(ifOperStatus != targetstate
- and not (type(targetstate) == list and ifOperStatus in targetstate)):
- state = 2
- infotext += "(%s!!) " % operstatus
- else:
- infotext += "(%s) " % operstatus
+ and not (type(targetstate) in [ list, tuple ] and ifOperStatus in
targetstate)):
+ return (2, "CRIT - %soperstatus: %s (CRIT)" % (infotext,
operstatus))
+ infotext += "(%s) " % operstatus
+ state = 0
- # prepare reference speed for computing relative bandwidth usage
+ # Check speed
speed = saveint(ifSpeed)
+ infotext += get_nic_speed_human_readable(speed)
+ if not targetspeed is None and speed != targetspeed:
+ infotext += " (wrong speed! expected: %s)" %
get_nic_speed_human_readable(targetspeed)
+ state = 1
+
+ # convert percentages to absolute values and vice verca - if possible
if speed:
ref_speed = speed / 8.0
elif targetspeed:
@@ -186,34 +182,13 @@ def check_if_common(item, params, info):
else:
ref_speed = None
- # Check speed settings of interface, but only if speed information
- # is available. This is not always the case.
- if speed:
- infotext += get_nic_speed_human_readable(speed)
- if not targetspeed is None and speed != targetspeed:
- infotext += " (wrong speed! expected: %s)" %
get_nic_speed_human_readable(targetspeed)
- state = max(state, 1)
- elif targetspeed:
- infotext += "assuming %s" %
get_nic_speed_human_readable(targetspeed)
- else:
- infotext += "speed unknown"
-
- # convert percentages to absolute values if levels are float
- # this is only possible if a reference speed is available.
+ # convert percentages to absolute values if reference speed available
if ref_speed:
if bw_warn != None and type(bw_warn) == float:
bw_warn = bw_warn / 100.0 * ref_speed
if bw_crit != None and type(bw_crit) == float:
bw_crit = bw_crit / 100.0 * ref_speed
- # Ignore percentual levels if no reference speed is available
- else:
- if bw_warn != None and type(bw_warn) == float:
- bw_warn = None
-
- if bw_crit != None and type(bw_crit) == float:
- bw_crit = None
-
# Performance counters
this_time = time.time()
rates = []