Cleanup config.nodes_of
[check_mk.git] / checks / printer_alerts
blob15936a455c09ebf0407146a1e6c1fb6bfaa8b74c
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 # Author: Lars Michelsen <lm@mathias-kettner.de>, 2011-03-16
29 # Example output for this case:
31 # 1.3.6.1.2.1.43.18.1.1.2.1.1 4
32 # 1.3.6.1.2.1.43.18.1.1.4.1.1 11
33 # 1.3.6.1.2.1.43.18.1.1.5.1.1 -1
34 # 1.3.6.1.2.1.43.18.1.1.7.1.1 1107
35 # 1.3.6.1.2.1.43.18.1.1.8.1.1 "The waste toner container is full soon."
37 # [['4', '11', '-1', '1107', 'The waste toner container is full soon.']]
39 printer_alerts_group_map = {
40 '1': 'other',
41 '3': 'hostResourcesMIBStorageTable',
42 '4': 'hostResourcesMIBDeviceTable',
43 '5': 'generalPrinter',
44 '6': 'cover',
45 '7': 'localization',
46 '8': 'input',
47 '9': 'output',
48 '10': 'marker',
49 '11': 'markerSupplies',
50 '12': 'markerColorant',
51 '13': 'mediaPath',
52 '14': 'channel',
53 '15': 'interpreter',
54 '16': 'consoleDisplayBuffer',
55 '17': 'consoleLights',
56 '18': 'alert',
57 '30': 'finDevice',
58 '31': 'finSypply',
59 '32': 'finSupplyMediaInput',
60 '33': 'finAttributeTable',
63 # old
64 #printer_alerts_state_map = {
65 # 2: [ 8, 1101, 1102, 1112, 1114, 1115 ],
66 # 1: [ 2, 9, 12, 13, 801, 1104 ],
67 # 0: [ 1, 4, 6, 7, 19, 20, 22, 23, 24, 25, 27, 35, 36, 37, 38,
68 # 502, 503, 504, 505, 506, 507, 802, 803, 804, 805,
69 # 806, 807, 808, 809, 810, 1001, 1002, 1005, 1106,
70 # 1107, 1108, 1111, 1113, 1302, 1304, 1501, 1502,
71 # 1503, 1504, 1505, 1506, 1509 ],
74 printer_code_map = {
75 "1": ("other", 0),
76 "2": ("unknown", 1),
77 "3": ("coverOpen", 1),
78 "4": ("coverClosed", 0),
79 "5": ("interlockOpen", 3),
80 "6": ("interlockClosed", 0),
81 "7": ("configurationChange", 0),
82 "8": ("jam", 2),
83 "9": ("subunitMissing", 1),
84 "10": ("subunitLifeAlmostOver", 1),
85 "11": ("subunitLifeOver", 2),
86 "12": ("subunitAlmostEmpty", 1),
87 "13": ("subunitEmpty", 1),
88 "14": ("subunitAlmostFull", 1),
89 "15": ("subunitFull", 1),
90 "16": ("subunitNearLimit", 1),
91 "17": ("subunitAtLimit", 2),
92 "18": ("subunitOpened", 1),
93 "19": ("subunitClosed", 0),
94 "20": ("subunitTurnedOn", 0),
95 "21": ("subunitTurnedOff", 1),
96 "22": ("subunitOffline", 0),
97 "23": ("subunitPowerSaver", 0),
98 "24": ("subunitWarmingUp", 0),
99 "25": ("subunitAdded", 0),
100 "26": ("subunitRemoved", 3),
101 "27": ("subunitResourceAdded", 0),
102 "28": ("subunitResourceRemoved", 1),
103 "29": ("subunitRecoverableFailure", 1),
104 "30": ("subunitUnrecoverableFailure", 2),
105 "31": ("subunitRecoverableStorageError", 1),
106 "32": ("subunitUnrecoverableStorageError", 2),
107 "33": ("subunitMotorFailure", 1),
108 "34": ("subunitMemoryExhausted", 1),
109 "35": ("subunitUnderTemperature", 0),
110 "36": ("subunitOverTemperature", 0),
111 "37": ("subunitTimingFailure", 0),
112 "38": ("subunitThermistorFailure", 0),
113 "501": ("doorOpen", 1),
114 "502": ("doorClosed", 0),
115 "503": ("powerUp", 0),
116 "504": ("powerDown", 0),
117 "505": ("printerNMSReset", 0),
118 "506": ("printerManualReset", 0),
119 "507": ("printerReadyToPrint", 0),
120 "801": ("inputMediaTrayMissing", 1),
121 "802": ("inputMediaSizeChange", 0),
122 "803": ("inputMediaWeightChange", 0),
123 "804": ("inputMediaTypeChange", 0),
124 "805": ("inputMediaColorChange", 0),
125 "806": ("inputMediaFormPartsChange", 0),
126 "807": ("inputMediaSupplyLow", 0),
127 "808": ("inputMediaSupplyEmpty", 0),
128 "809": ("inputMediaChangeRequest", 0),
129 "810": ("inputManualInputRequest", 0),
130 "811": ("inputTrayPositionFailure", 1),
131 "812": ("inputTrayElevationFailure", 1),
132 "813": ("inputCannotFeedSizeSelected", 0),
133 "901": ("outputMediaTrayMissing", 1),
134 "902": ("outputMediaTrayAlmostFull", 0),
135 "903": ("outputMediaTrayFull", 1),
136 "904": ("outputMailboxSelectFailure", 1),
137 "1001": ("markerFuserUnderTemperature", 0),
138 "1002": ("markerFuserOverTemperature", 0),
139 "1003": ("markerFuserTimingFailure", 1),
140 "1004": ("markerFuserThermistorFailure", 1),
141 "1005": ("markerAdjustingPrintQuality", 0),
142 "1101": ("markerTonerEmpty", 2),
143 "1102": ("markerInkEmpty", 2),
144 "1103": ("markerPrintRibbonEmpty", 2),
145 "1104": ("markerTonerAlmostEmpty", 1),
146 "1105": ("markerInkAlmostEmpty", 1),
147 "1106": ("markerPrintRibbonAlmostEmpty", 0),
148 "1107": ("markerWasteTonerReceptacleAlmostFull", 0),
149 "1108": ("markerWasteInkReceptacleAlmostFull", 0),
150 "1109": ("markerWasteTonerReceptacleFull", 2),
151 "1110": ("markerWasteInkReceptacleFull", 2),
152 "1111": ("markerOpcLifeAlmostOver", 0),
153 "1112": ("markerOpcLifeOver", 2),
154 "1113": ("markerDeveloperAlmostEmpty", 0),
155 "1114": ("markerDeveloperEmpty", 2),
156 "1115": ("markerTonerCartridgeMissing", 2),
157 "1301": ("mediaPathMediaTrayMissing", 1),
158 "1302": ("mediaPathMediaTrayAlmostFull", 0),
159 "1303": ("mediaPathMediaTrayFull", 2),
160 "1304": ("mediaPathCannotDuplexMediaSelected", 0),
161 "1501": ("interpreterMemoryIncrease", 0),
162 "1502": ("interpreterMemoryDecrease", 0),
163 "1503": ("interpreterCartridgeAdded", 0),
164 "1504": ("interpreterCartridgeDeleted", 0),
165 "1505": ("interpreterResourceAdded", 0),
166 "1506": ("interpreterResourceDeleted", 0),
167 "1507": ("interpreterResourceUnavailable", 3),
168 "1509": ("interpreterComplexPageEncountered", 0),
171 # Some printers send a code of -1 but an additional text
172 # that allows us to generate a useful state - at the price
173 # of providing texts in the native language of the country
174 # of the printers user.
176 printer_alerts_text_map = {
177 'Energiesparen': 0,
178 'Sleep': 0,
182 def inventory_printer_alerts(info):
183 return [(None, None)]
186 def check_printer_alerts(_not_used, _not_used1, info):
187 # Filter out empty status lines (e.g. sent by Brother)
188 info = [i for i in info if i[1:5] != ["0", "0", "0", ""]]
189 if not info:
190 return (0, 'No alerts present')
192 sum_state = 0
193 sum_txt = []
194 for sev, group, group_index, code, desc in info:
196 code_txt, state = printer_code_map.get(code, ('unknown alert code: %s' % code, 3))
198 if desc in printer_alerts_text_map:
199 state = printer_alerts_text_map[desc]
200 if state != 0:
201 sum_state = max(state, sum_state)
202 sum_txt.append(desc)
203 continue
205 # Code not found -> take into account severity
206 if state == 3 and sev == '1':
207 state = 0
209 # determine the total(sum) state of the check
210 if state == 2:
211 sum_state = 2
212 elif state == 3 and sum_state != 2:
213 sum_state = 3
214 elif state > sum_state:
215 sum_state = max(state, sum_state)
217 # collect the check output
219 info_txt = printer_alerts_group_map.get(group, 'unknown alert group %s' % group)
220 if group_index != '-1' and info_txt.startswith("unknown alert group"):
221 info_txt += '#%s' % group_index
222 info_txt += ": "
223 if desc != "":
224 info_txt += "%s" % desc
225 elif code != "-1":
226 info_txt += "%s" % code_txt
227 sum_txt.append(info_txt)
229 if len(sum_txt) == 0:
230 sum_txt.append("No alerts found")
232 return (sum_state, ', '.join(sum_txt))
235 # no longer used
236 # check_config_variables.append("printer_alerts_state_map")
238 check_config_variables.append("printer_alerts_text_map")
240 check_info["printer_alerts"] = {
241 'check_function': check_printer_alerts,
242 'inventory_function': inventory_printer_alerts,
243 'service_description': 'Alerts',
244 'snmp_info': (
245 '.1.3.6.1.2.1.43.18.1.1',
247 '2', # prtAlertSeverityLevel
248 '4', # prtAlertGroup
249 '5', # prtAlertGroupIndex
250 '7', # prtAlertCode
251 '8', # prtAlertDescription
253 'handle_empty_info': True,
254 'snmp_scan_function': lambda oid: oid(".1.3.6.1.2.1.43.11.1.1.6.1.1") is not None,