Module: check_mk
Branch: master
Commit: 8cebfd79aecc8fa237f9a31b1987b8ff594b325c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8cebfd79aecc8f…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Dec 2 10:55:06 2015 +0100
#2782 FIX cups_queues: fix crash in case user name contains spaces
---
.werks/2782 | 10 ++++++++++
ChangeLog | 1 +
checks/cups_queues | 50 ++++++++++++++++++++++++++++++--------------------
3 files changed, 41 insertions(+), 20 deletions(-)
diff --git a/.werks/2782 b/.werks/2782
new file mode 100644
index 0000000..f934edb
--- /dev/null
+++ b/.werks/2782
@@ -0,0 +1,10 @@
+Title: cups_queues: fix crash in case user name contains spaces
+Level: 1
+Component: checks
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.7i4
+Date: 1449050089
+
+
diff --git a/ChangeLog b/ChangeLog
index 161e4c0..42ee294 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -113,6 +113,7 @@
* 2800 FIX: mk_mysql: fixed some issues with incorrect assembled command line...
* 2744 FIX: waitmax now kills the whole process group and is a bit more robust.
* 2842 FIX: jolokia_metrics.perm_gen: fixed wrong calculation of perf variables warn
and crit
+ * 2782 FIX: cups_queues: fix crash in case user name contains spaces
Multisite:
* 2684 Added icons for downloading agent data / walks of hosts...
diff --git a/checks/cups_queues b/checks/cups_queues
index 9a92d3c..d5131c7 100644
--- a/checks/cups_queues
+++ b/checks/cups_queues
@@ -24,26 +24,25 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
-# Author: Lars Michelsen <lm(a)mathias-kettner.de>
-
# Example output from agent:
-#<<<cups_queues>>>
-#printer lpr1 disabled since Wed Jun 16 14:21:14 2010 -
-# reason unknown
-#printer lpr2 now printing lpr2-3. enabled since Tue Jun 29 09:22:04 2010
-# Wiederherstellbar: Der Netzwerk-Host „lpr2“ ist beschäftigt, erneuter Versuch in 30
Sekunden …
-#printer spr1 is idle. enabled since Thu Mar 11 14:28:23 2010
-#printer spr2 is idle. enabled since Thu Mar 11 14:28:23 2010
-#printer spr3 is idle. enabled since Thu Mar 11 14:28:23 2010
-#printer spr4 is idle. enabled since Thu Mar 11 14:28:23 2010
-#printer spr5 is idle. enabled since Thu Mar 11 14:28:23 2010
-#printer spr6 disabled since Mon Jun 21 10:29:39 2010 -
-# /usr/lib/cups/backend/lpd failed
-#printer spr7 is idle. enabled since Thu Mar 11 14:28:23 2010
-#printer spr8 is idle. enabled since Thu Mar 11 14:28:23 2010
-#---
-#lpr2-2 root 1024 Tue Jun 29 09:02:35 2010
-#lpr2-3 root 1024 Tue Jun 29 09:05:54 2010
+# <<<cups_queues>>>
+# printer lpr1 disabled since Wed Jun 16 14:21:14 2010 -
+# reason unknown
+# printer lpr2 now printing lpr2-3. enabled since Tue Jun 29 09:22:04 2010
+# Wiederherstellbar: Der Netzwerk-Host „lpr2“ ist beschäftigt, erneuter Versuch in 30
Sekunden …
+# printer spr1 is idle. enabled since Thu Mar 11 14:28:23 2010
+# printer spr2 is idle. enabled since Thu Mar 11 14:28:23 2010
+# printer spr3 is idle. enabled since Thu Mar 11 14:28:23 2010
+# printer spr4 is idle. enabled since Thu Mar 11 14:28:23 2010
+# printer spr5 is idle. enabled since Thu Mar 11 14:28:23 2010
+# printer spr6 disabled since Mon Jun 21 10:29:39 2010 -
+# /usr/lib/cups/backend/lpd failed
+# printer spr7 is idle. enabled since Thu Mar 11 14:28:23 2010
+# printer spr8 is idle. enabled since Thu Mar 11 14:28:23 2010
+# ---
+# lpr2-2 root 1024 Tue Jun 29 09:02:35 2010
+# lpr2-3 root 1024 Tue Jun 29 09:05:54 2010
+# zam19-113565 Sebastian Hirschdobler 3561472 Fri Jul 31 12:58:01 2015
# Default thresholds
# ("<Warning max entries>", "<Critical num entries>",
"<Warning entry age in seconds>", "<Critical entry age>")
@@ -60,6 +59,7 @@ def check_cups_queues(item, params, info):
now = time.time()
oldest = now
for num, line in enumerate(info):
+ # Parse printer status
if line[0] == 'printer' and line[1] == item:
statusoutput = ' '.join(line[2:])
status = ' '.join(line[2:4])
@@ -77,17 +77,27 @@ def check_cups_queues(item, params, info):
else:
state = 3
output = "Undefined status output in \"lpr -p\""
+
+ # Parse job
elif line[0].startswith(item+'-'):
# This is a queue item count the number of items and check the max age
numJobs += 1
# Try to parse different time formats
- timestring = ' '.join(line[3:])
+
+ # Handle case where user names contain spaces
+ # zam19-113565 Sebastian Hirschdobler 3561472 Fri Jul 31 12:58:01 2015
+ time_parts = line[3:]
+ while saveint(time_parts[0]) > 35:
+ time_parts = time_parts[1:]
+
+ timestring = ' '.join(time_parts)
try:
# Tue Jun 29 09:05:54 2010
parsed = time.strptime(timestring, '%a %b %d %H:%M:%S %Y')
except:
# Thu 29 Aug 2013 12:41:42 AM CEST
parsed = time.strptime(timestring, '%a %d %b %Y %H:%M:%S %p %Z')
+
dt = time.mktime(parsed)
if dt < oldest:
oldest = dt