Module: check_mk
Branch: master
Commit: d91c852cdcbf0b91e19ec6b1daeeb162142a3dc2
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d91c852cdcbf0b…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Jan 9 12:35:04 2014 +0100
FIX cups_queues: fix exception in case of alternative time format
In some cases the time format output by CUPS was not correctly
parsed by the check. An example is <tt>Thu 29 Aug 2013 06:25:55 AM CEST</tt>.
This has now been fixed.
---
.werks/404 | 12 ++++++++++++
ChangeLog | 1 +
checks/cups_queues | 20 +++++++++++++-------
3 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/.werks/404 b/.werks/404
new file mode 100644
index 0000000..6691b60
--- /dev/null
+++ b/.werks/404
@@ -0,0 +1,12 @@
+Title: cups_queues: fix exception in case of alternative time format
+Level: 1
+Component: checks
+Class: fix
+State: unknown
+Version: 1.2.5i1
+Date: 1389267220
+Targetversion: future
+
+In some cases the time format output by CUPS was not correctly
+parsed by the check. An example is <tt>Thu 29 Aug 2013 06:25:55 AM
CEST</tt>.
+This has now been fixed.
diff --git a/ChangeLog b/ChangeLog
index 210825a..8b8df37 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -86,6 +86,7 @@
* 0322 FIX: timemachine: Check now also works if there are spaces in the name of the
backup volume or the hostname
* 0253 FIX: windows agent: fixed crash on processing eventlog records...
* 0403 FIX: mem.used: Prefer statgrab on FreeBSD for supporting more than 4GB...
+ * 0404 FIX: cups_queues: fix exception in case of alternative time format...
Multisite:
* 0371 Added log class filter to hostsvcevents view
diff --git a/checks/cups_queues b/checks/cups_queues
index fa1a092..80c493e 100644
--- a/checks/cups_queues
+++ b/checks/cups_queues
@@ -45,8 +45,6 @@
#lpr2-2 root 1024 Tue Jun 29 09:02:35 2010
#lpr2-3 root 1024 Tue Jun 29 09:05:54 2010
-import time, datetime
-
# Default thresholds
# ("<Warning max entries>", "<Critical num entries>",
"<Warning entry age in seconds>", "<Critical entry age>")
cups_queues_default_levels = (5, 10, 360, 720)
@@ -59,7 +57,7 @@ def check_cups_queues(item, params, info):
state = 3
output = "Queue not found"
numJobs = 0
- now = datetime.datetime.now()
+ now = time.time()
oldest = now
for num, line in enumerate(info):
if line[0] == 'printer' and line[1] == item:
@@ -82,17 +80,25 @@ def check_cups_queues(item, params, info):
elif line[0].startswith(item+'-'):
# This is a queue item count the number of items and check the max age
numJobs += 1
- dt = datetime.datetime(*time.strptime(' '.join(line[3:]), '%a %b
%d %H:%M:%S %Y')[:6])
+ # Try to parse different time formats
+ timestring = ' '.join(line[3:])
+ 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
jobOutput = 'Jobs: %d' % numJobs
if numJobs > 0:
- if oldest < now - datetime.timedelta(seconds=critAge) or numJobs >
critNum:
+ if oldest < now - critAge or numJobs > critNum:
state = 2
- elif oldest < now - datetime.timedelta(seconds=warnAge) or numJobs >
warnNum:
+ elif oldest < now - warnAge or numJobs > warnNum:
state = 1
- jobOutput += ', Oldest job is from %s' % oldest
+ jobOutput += ', Oldest job is from %s' % time.strftime("%c",
time.localtime(oldest))
return (state, output + " - " + jobOutput, [ ("jobs", numJobs,
warnNum, critNum, 0) ])