Cleanup config.nodes_of
[check_mk.git] / checks / printer_supply_ricoh
blobcde1dd96e17a4afd70c9bfa5a6b1cbdd6bbf5b1e
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
11 # +------------------------------------------------------------------+
13 # This file is part of Check_MK.
14 # The official homepage is at http://mathias-kettner.de/check_mk.
16 # check_mk is free software; you can redistribute it and/or modify it
17 # under the terms of the GNU General Public License as published by
18 # the Free Software Foundation in version 2. check_mk is distributed
19 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
20 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
22 # tails. You should have received a copy of the GNU General Public
23 # License along with GNU Make; see the file COPYING. If not, write
24 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
25 # Boston, MA 02110-1301 USA.
27 # .1.3.6.1.4.1.367.3.2.1.2.24.1.1.2.1 Black Toner
28 # .1.3.6.1.4.1.367.3.2.1.2.24.1.1.2.2 Cyan Toner
29 # .1.3.6.1.4.1.367.3.2.1.2.24.1.1.2.3 Magenta Toner
30 # .1.3.6.1.4.1.367.3.2.1.2.24.1.1.2.4 Yellow Toner
31 # .1.3.6.1.4.1.367.3.2.1.2.24.1.1.5.1 30
32 # .1.3.6.1.4.1.367.3.2.1.2.24.1.1.5.2 20
33 # .1.3.6.1.4.1.367.3.2.1.2.24.1.1.5.3 30
34 # .1.3.6.1.4.1.367.3.2.1.2.24.1.1.5.4 -100
36 # some data may look like
37 # .1.3.6.1.4.1.367.3.2.1.2.24.1.1.2.1 Toner
38 # .1.3.6.1.4.1.367.3.2.1.2.24.1.1.5.1 30
40 factory_settings["printer_supply_ricoh_default_levels"] = {"levels": (20.0, 10.0)}
43 def parse_printer_supply_ricoh(info):
44 parsed = {}
45 for what, pages_text in info:
46 name_reversed = what.split(" ")
48 if len(name_reversed) == 2:
49 name_reversed.reverse()
51 name = " ".join(name_reversed)
52 parsed[name] = int(pages_text)
53 return parsed
56 def inventory_printer_supply_ricoh(parsed):
57 return [(key, {}) for key in parsed]
60 def check_printer_supply_ricoh(item, params, parsed):
61 def handle_regular(supply_level):
62 infotext = "%.0f%%" % supply_level
64 if supply_level <= crit:
65 state = 2
66 elif supply_level <= warn:
67 state = 1
68 else:
69 state = 0
71 if state > 0:
72 infotext += " (warn/crit at %.0f%%/%.0f%%)" % (warn, crit)
73 return state, infotext, supply_level
75 def handle_negative(code):
76 # the following codes are based on the MP C2800
77 if code == -100:
78 # does not apply level. Since we don't get a proper reading
79 # the best we could do would be test against 0
80 return 2, "almost empty (<10%)", 0
81 elif code == -2:
82 # cartridge removed?
83 return 3, "unknown level", 0
84 elif code == -3:
85 # -3 = full is based on user claim, but other walks also show
86 # the device itself does not alert in this state
87 return 0, "100%", 100
88 # unknown code
89 return handle_regular(0)
91 if isinstance(params, tuple):
92 if len(params) == 2:
93 params = {"levels": params}
94 else:
95 params = {"levels": params[:2], "upturn_toner": params[2]}
97 warn, crit = params["levels"]
98 for name, supply_level in parsed.items():
99 if item == name:
100 if supply_level < 0:
101 # negative levels usually have special meaning
102 state, infotext, supply_level = handle_negative(supply_level)
103 else:
104 state, infotext, supply_level = handle_regular(supply_level)
106 if "black" in name.lower():
107 perf_type = "black"
108 elif "cyan" in name.lower():
109 perf_type = "cyan"
110 elif "magenta" in name.lower():
111 perf_type = "magenta"
112 elif "yellow" in name.lower():
113 perf_type = "yellow"
114 else:
115 perf_type = "other"
117 perfdata = [("supply_toner_" + perf_type, supply_level, warn, crit, 0, 100)]
119 return state, infotext, perfdata
122 check_info['printer_supply_ricoh'] = {
123 "parse_function": parse_printer_supply_ricoh,
124 "inventory_function": inventory_printer_supply_ricoh,
125 "check_function": check_printer_supply_ricoh,
126 "service_description": "Supply %s",
127 "has_perfdata": True,
128 "group": "printer_supply",
129 "snmp_info": (".1.3.6.1.4.1.367.3.2.1.2.24.1.1", [2, 5]),
130 "snmp_scan_function": lambda oid: oid(".1.3.6.1.2.1.1.2.0") in [".1.3.6.1.4.1.367.1.1"],
131 "default_levels_variable": "printer_supply_ricoh_default_levels",