Cleanup config.nodes_of
[check_mk.git] / checks / printer_io.include
blob18cd68cc5961806ef790cdc7982cd825d271917d
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 printer_io_units = {
28 '-1': 'unknown',
29 '0': 'unknown',
30 '2': 'unknown', # defined by PrtCapacityUnitTC used in newer revs.
31 '3': '1/10000 in',
32 '4': 'micrometers',
33 '8': 'sheets',
34 '16': 'feet',
35 '17': 'meters',
36 '18': 'items',
37 '19': 'percent',
40 printer_io_states = {
41 # PrtSubUnitStatusTC monitoring-state label
43 # Availability
44 0: (0, 'Available and Idle'),
45 2: (0, 'Available and Standby'),
46 4: (0, 'Available and Active'),
47 6: (0, 'Available and Busy'),
48 1: (1, 'Unavailable and OnRequest'),
49 3: (2, 'Unavailable because Broken'),
50 5: (3, 'Unknown'),
52 # Non-critical alerts
53 8: (1, 'Non-Critical Alerts'),
55 # Critical alerts
56 16: (2, 'Critical Alerts'),
58 # On-Line state
59 32: (2, 'Off-Line'),
60 64: (0, 'Transitioning to intended state'),
63 factory_settings['printer_input_default_levels'] = {
64 'capacity_levels': (0.0, 0.0),
67 factory_settings['printer_output_default_levels'] = {
68 'capacity_levels': (100.0, 100.0),
72 def inventory_printer_io(info):
73 for line in info:
74 index, name, descr, status = line[:4]
75 if descr == '':
76 continue
77 snmp_status, _capacity_unit, capacity_max, _level = line[3:]
78 if capacity_max == '0': # useless
79 continue
81 ignore = False
82 snmp_status = saveint(status)
83 for state_val in sorted(printer_io_states, reverse=True):
84 if state_val > 0 and snmp_status - state_val >= 0:
85 snmp_status -= state_val
86 # Skip sub units where it does not seem to make sense to monitor them
87 if state_val in (1, 3, 5):
88 ignore = True
89 if ignore is True:
90 continue
92 # When no name is set
93 # a) try to use the description
94 # b) try to use the type otherwise use the index
95 if name == "unknown" or not name:
96 name = descr if descr else index.split('.')[-1]
98 yield (name, {})
101 def check_printer_io(item, params, info, what):
102 for line in info:
103 index, name, descr = line[:3]
105 if name == item or descr == item or index.split('.')[-1] == item:
106 snmp_status, capacity_unit, capacity_max, level = line[3:]
107 snmp_status, level, capacity_max = saveint(snmp_status), saveint(level), saveint(
108 capacity_max)
109 if capacity_unit != '':
110 capacity_unit = ' ' + printer_io_units[capacity_unit]
112 state_txt = []
113 state_state = 0
115 yield 0, descr
116 if snmp_status == 0:
117 state_txt.append(printer_io_states[0][1])
118 else:
119 for state_val in sorted(printer_io_states, reverse=True):
120 if state_val > 0 and snmp_status - state_val >= 0:
121 mon_state, text = printer_io_states[state_val]
122 state_state = max(mon_state, state_state)
123 state_txt.append(text)
124 snmp_status -= state_val
126 yield state_state, 'Status: %s' % ', '.join(state_txt)
128 if level in [-1, -2] or level < -3:
129 pass # totally skip this info when level is unknown or not limited
131 elif capacity_max in [-1, -2]:
132 # -1: no restriction, -2: unknown
133 yield 0, 'Capacity: %s%s' % (level, capacity_unit)
135 else:
136 state = 0
137 levels_txt = ''
138 how = 'remaining' if what == 'input' else 'filled'
139 if level == -3:
140 level_txt = "at least one"
142 else:
143 level_perc = 100.0 * level / capacity_max # to percent
144 level_txt = '%0.2f%%' % level_perc
146 if what == 'input':
147 warn, crit = params['capacity_levels'] # percentage levels
148 if crit is not None and level_perc <= crit:
149 state = 2
150 levels_txt = ' (<= %0.2f)' % crit
151 elif warn is not None and level_perc <= warn:
152 state = 1
153 levels_txt = ' (<= %0.2f%%)' % warn
155 else: # output
156 warn, crit = params['capacity_levels'] # percentage levels
157 if crit is not None and level_perc >= crit:
158 state = 2
159 levels_txt = ' (>= %0.2f)' % crit
160 elif warn is not None and level_perc >= warn:
161 state = 1
162 levels_txt = ' (>= %0.2f%%)' % warn
164 yield state, 'Capacity: %s of %s%s %s%s' % \
165 (level_txt, capacity_max, capacity_unit, how, levels_txt)