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.
30 '2': 'unknown', # defined by PrtCapacityUnitTC used in newer revs.
41 # PrtSubUnitStatusTC monitoring-state label
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'),
53 8: (1, 'Non-Critical Alerts'),
56 16: (2, 'Critical Alerts'),
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
):
74 index
, name
, descr
, status
= line
[:4]
77 snmp_status
, _capacity_unit
, capacity_max
, _level
= line
[3:]
78 if capacity_max
== '0': # useless
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):
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]
101 def check_printer_io(item
, params
, info
, what
):
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(
109 if capacity_unit
!= '':
110 capacity_unit
= ' ' + printer_io_units
[capacity_unit
]
117 state_txt
.append(printer_io_states
[0][1])
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
)
138 how
= 'remaining' if what
== 'input' else 'filled'
140 level_txt
= "at least one"
143 level_perc
= 100.0 * level
/ capacity_max
# to percent
144 level_txt
= '%0.2f%%' % level_perc
147 warn
, crit
= params
['capacity_levels'] # percentage levels
148 if crit
is not None and level_perc
<= crit
:
150 levels_txt
= ' (<= %0.2f)' % crit
151 elif warn
is not None and level_perc
<= warn
:
153 levels_txt
= ' (<= %0.2f%%)' % warn
156 warn
, crit
= params
['capacity_levels'] # percentage levels
157 if crit
is not None and level_perc
>= crit
:
159 levels_txt
= ' (>= %0.2f)' % crit
160 elif warn
is not None and level_perc
>= warn
:
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
)