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 # Example output from agent:
29 # printer lpr1 disabled since Wed Jun 16 14:21:14 2010 -
31 # printer lpr2 now printing lpr2-3. enabled since Tue Jun 29 09:22:04 2010
32 # Wiederherstellbar: Der Netzwerk-Host „lpr2“ ist beschäftigt, erneuter Versuch in 30 Sekunden …
33 # printer spr1 is idle. enabled since Thu Mar 11 14:28:23 2010
34 # printer spr2 is idle. enabled since Thu Mar 11 14:28:23 2010
35 # printer spr3 is idle. enabled since Thu Mar 11 14:28:23 2010
36 # printer spr4 is idle. enabled since Thu Mar 11 14:28:23 2010
37 # printer spr5 is idle. enabled since Thu Mar 11 14:28:23 2010
38 # printer spr6 disabled since Mon Jun 21 10:29:39 2010 -
39 # /usr/lib/cups/backend/lpd failed
40 # printer spr7 is idle. enabled since Thu Mar 11 14:28:23 2010
41 # printer spr8 is idle. enabled since Thu Mar 11 14:28:23 2010
43 # lpr2-2 root 1024 Tue Jun 29 09:02:35 2010
44 # lpr2-3 root 1024 Tue Jun 29 09:05:54 2010
45 # zam19-113565 Sebastian Hirschdobler 3561472 Fri Jul 31 12:58:01 2015
48 factory_settings
['cups_queues_default_levels'] = {
49 'job_count': (5, 10), # warn/crit for queue entries
50 'job_age': (360, 720), # warn/crit for entry age in seconds
51 'is_idle': 0, # state for "is idle"
52 'now_printing': 0, # state for "now printing"
53 'disabled_since': 2, # state for "disbaled since"
57 def parse_cups_queues(info
):
60 for num
, line
in enumerate(info
):
61 if line
[0] == "printer":
63 'status_readable': ' '.join(line
[2:4]).replace(' ', '_').strip('.'),
64 'output': ' '.join(line
[2:]),
67 if len(info
) > num
+1 and \
68 not info
[num
+1][0] in [ 'printer', '---' ]:
69 parsed
[line
[1]]['output'] += " (%s)" % \
71 elif line
[0] == "---":
80 item
= line
[0].split("-", 1)[0]
81 if item
in parsed
and queue_section
:
82 # Handle different time formats...
83 try: # Tue Jun 29 09:05:54 2010
84 job_time
= time
.mktime(time
.strptime(' '.join(line
[-5:]), \
85 '%a %b %d %H:%M:%S %Y'))
86 except: # Thu 29 Aug 2013 12:41:42 AM CEST
87 job_time
= time
.mktime(time
.strptime(' '.join(line
[-7:]), \
88 '%a %d %b %Y %I:%M:%S %p %Z'))
89 parsed
[item
]['jobs'].append(job_time
)
94 def inventory_cups_queues(parsed
):
99 def check_cups_queues(item
, params
, parsed
):
102 if isinstance(params
, tuple) and len(params
) == 4:
104 "job_count": (params
[0], params
[1]),
105 "job_age": (params
[2], params
[3]),
111 if data
["status_readable"] in params
:
112 state
= params
[data
["status_readable"]]
113 yield state
, data
["output"]
115 yield 3, "Undefinded status output in \"lpr -p\""
118 jobs_count
= len(data
["jobs"])
120 warn_num
, crit_num
= params
["job_count"]
121 yield 0, "Jobs: %d" % jobs_count
, \
122 [ ("jobs", jobs_count
, warn_num
, crit_num
, 0) ]
124 warn_age
, crit_age
= params
["job_age"]
126 oldest
= min(data
["jobs"])
127 oldest_readable
= time
.strftime("%c", time
.localtime(oldest
))
129 if oldest
< now
- crit_age
or jobs_count
> crit_num
:
131 elif oldest
< now
- warn_age
or jobs_count
> warn_num
:
137 yield state
, "Oldest job is from %s" % oldest_readable
139 yield 3, "Queue not found"
142 check_info
["cups_queues"] = {
143 'parse_function': parse_cups_queues
,
144 'inventory_function': inventory_cups_queues
,
145 'check_function': check_cups_queues
,
146 'service_description': 'CUPS Queue %s',
147 'has_perfdata': True,
148 'default_levels_variable': 'cups_queues_default_levels',
149 'group': 'cups_queues'