Module: check_mk
Branch: master
Commit: 0812ebdd4d65b67e7334693e656ebeb8d58c7bdf
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0812ebdd4d65b6…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Mar 21 18:01:34 2011 +0100
printer_supply: further change of handling of -2
---
checks/printer_supply | 44 +++++++++++++++++++++++++++-----------------
1 files changed, 27 insertions(+), 17 deletions(-)
diff --git a/checks/printer_supply b/checks/printer_supply
index 1532201..13d0bfa 100644
--- a/checks/printer_supply
+++ b/checks/printer_supply
@@ -74,26 +74,34 @@ def printer_supply_fix_infos(info):
def inventory_printer_supply(checkname, info):
# Ignore devices which show -2 for current value and -2 for max value -> useless
- return [ (line[0], "printer_supply_default_levels") for line in
printer_supply_fix_infos(info)
- if savefloat(line[2]) != -2 and
float(line[1]) != -2 ]
+ return [ (line[0], "printer_supply_default_levels")
+ for line in printer_supply_fix_infos(info)
+ if not (line[1] == '-2' and line[2] == '-2') ] # ignore
useless devices
def check_printer_supply(item, params, info):
for line in printer_supply_fix_infos(info):
if line[0] == item:
- maxlevel = float(line[1])
- current = savefloat(line[2])
- leftperc = 100.0 * current / maxlevel
+ maxlevel = int(line[1])
+ current = saveint(line[2])
warn, crit = params # in percent
- infotext = "%.0f%% (levels at %.0f%% / %.0f%%)" % (leftperc, warn,
crit)
perfdata = [ ("pages", current, warn / 100.0 * maxlevel, crit /
100.0 * maxlevel, 0, maxlevel ) ]
- if current == -1 or maxlevel == -1:
- return (0, "OK - there are no restrictions on this supply")
- elif current == -3:
- return (printer_supply_some_remaining_status, "%s - Some
remaining" %
- (nagios_state_names[printer_supply_some_remaining_status]),
perfdata)
- elif current == -2 or maxlevel == -2:
- return (3, "UNKNOWN - Couldn't get info about supply")
- elif leftperc <= crit:
+
+ # handle cases with partial data
+ if maxlevel == -2 or current in [ -3, -2, -1 ]: # no percentage possible
+ if current == -1 or maxlevel == -1:
+ return (0, "OK - there are no restrictions on this
supply")
+ elif current == -3:
+ return (printer_supply_some_remaining_status, "%s - Some
remaining" %
+ (nagios_state_names[printer_supply_some_remaining_status]),
perfdata)
+ elif current == -2:
+ return (3, "UNKNOWN - current level is unknown")
+ elif maxlevel == -2:
+ # no percentage possible. We compare directly against levels
+ return (0, "OK - current level is %d" % current, [("pages",
current)])
+
+ leftperc = 100.0 * current / maxlevel
+ infotext = "%.0f%% (levels at %.0f%% / %.0f%%)" % (leftperc, warn,
crit)
+ if leftperc <= crit:
return (2, "CRIT - %s" % infotext, perfdata)
elif leftperc <= warn:
return (1, "WARNING - %s" % infotext, perfdata)
@@ -104,11 +112,13 @@ def check_printer_supply(item, params, info):
check_info['printer_supply'] = (check_printer_supply, "Supply %s", 1,
inventory_printer_supply)
-snmp_info['printer_supply'] = ( ".1.3.6.1.2.1.43", [
'11.1.1.6',
- '11.1.1.8',
- '11.1.1.9',
+snmp_info['printer_supply'] = ( ".1.3.6.1.2.1.43", [
'11.1.1.6', # Printer-MIB::prtMarkerSuppliesDescription
+ '11.1.1.8', #
Printer-MIB::prtMarkerSuppliesMaxCapacity
+ '11.1.1.9', #
Printer-MIB::prtMarkerSuppliesLevel
'12.1.1.4' ] )
+
+
check_config_variables.append("printer_supply_some_remaining_status")
snmp_scan_functions['printer_supply'] = \