2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
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
):
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
)
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
:
66 elif supply_level
<= warn
:
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
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
83 return 3, "unknown level", 0
85 # -3 = full is based on user claim, but other walks also show
86 # the device itself does not alert in this state
89 return handle_regular(0)
91 if isinstance(params
, tuple):
93 params
= {"levels": params
}
95 params
= {"levels": params
[:2], "upturn_toner": params
[2]}
97 warn
, crit
= params
["levels"]
98 for name
, supply_level
in parsed
.items():
101 # negative levels usually have special meaning
102 state
, infotext
, supply_level
= handle_negative(supply_level
)
104 state
, infotext
, supply_level
= handle_regular(supply_level
)
106 if "black" in name
.lower():
108 elif "cyan" in name
.lower():
110 elif "magenta" in name
.lower():
111 perf_type
= "magenta"
112 elif "yellow" in name
.lower():
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",