[checkmk-commits] Check_MK Git: check_mk: #2198 FIX windows_updates: Fix missing warning if reboot required in case forced reboot is in the past

Mathias Kettner mk at mathias-kettner.de
Fri Apr 10 16:58:31 CEST 2015


Module: check_mk
Branch: master
Commit: 5aca793ef9a0a3bbdc970f248c2ac44b344089ee
URL:    http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5aca793ef9a0a3bbdc970f248c2ac44b344089ee

Author: Mathias Kettner <mk at mathias-kettner.de>
Date:   Fri Apr 10 16:58:26 2015 +0200

#2198 FIX windows_updates: Fix missing warning if reboot required in case forced reboot is in the past

If the plugin reports the next forced reboot to lie in the past then
the check did not warn anymore about a neccessary reboot for applying
the installed patches. Also the code was cleaned up on the dependency
to the Python module <tt>datetime</tt> has been removed.

---

 .werks/2198            |   13 +++++++++++++
 ChangeLog              |    1 +
 checks/windows_updates |   48 +++++++++++++++++-------------------------------
 3 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/.werks/2198 b/.werks/2198
new file mode 100644
index 0000000..c425f3d
--- /dev/null
+++ b/.werks/2198
@@ -0,0 +1,13 @@
+Title: windows_updates: Fix missing warning if reboot required in case forced reboot is in the past
+Level: 1
+Component: checks
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.7i1
+Date: 1428677837
+
+If the plugin reports the next forced reboot to lie in the past then
+the check did not warn anymore about a neccessary reboot for applying
+the installed patches. Also the code was cleaned up on the dependency
+to the Python module <tt>datetime</tt> has been removed.
diff --git a/ChangeLog b/ChangeLog
index 7738037..bcef5c2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -316,6 +316,7 @@
     * 2192 FIX: check_notify_count": Fix exception in PNP template in case of explit email addresses...
     * 2172 FIX: Allowing OIDs in checks not starting with a dot again...
     * 2173 FIX: mk-job: Fixed quoting of command line arguments
+    * 2198 FIX: windows_updates: Fix missing warning if reboot required in case forced reboot is in the past...
 
     Multisite:
     * 1758 Improved exception hander: Shows details without additional debug request, added mailto link for error report...
diff --git a/checks/windows_updates b/checks/windows_updates
index 717ff52..9c49864 100644
--- a/checks/windows_updates
+++ b/checks/windows_updates
@@ -24,8 +24,6 @@
 # to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
 # Boston, MA 02110-1301 USA.
 
-# Author: Lars Michelsen <lm at mathias-kettner.de>
-
 # <<<windows_updates>>>
 # 0 2 5
 # Windows XP Service Pack 3 (KB936929); Windows-Tool zum Entfernen sch�dlicher Software - M�rz 2011 (KB890830)
@@ -36,15 +34,13 @@
 # Third row:  List of all optional updates (optional)
 # Last row:  Date and time of forced update (optional)
 
-import datetime
-
 windows_updates_default_params = (0, 0, 0, 0, 604800, 172800, True)
 
 def inventory_windows_updates(info):
     if info and len(info[0]) == 3:
         return [(None, "windows_updates_default_params")]
 
-def check_windows_updates(_unused, params, info):
+def check_windows_updates(_no_item, params, info):
     if info and len(info[0]) == 3:
         status = 0
         # Workarround to return errors from the plugin
@@ -95,38 +91,28 @@ def check_windows_updates(_unused, params, info):
             txt.append(this_txt)
             perfdata.append((label, cur, warn, crit))
 
+        if reboot_required == 1:
+            if status < 1:
+                status = 1
+            txt.append('Reboot required to finish updates(!)')
+
         if forced_reboot != "":
-            date, time = forced_reboot
-            year, month, day = map(int, date.split("-"))
-            hour, minute, second = map(int, time.split(":"))
-            force_date = datetime.datetime(year, month, day, hour, minute, second)
-            now = datetime.datetime.now()
-            nix = datetime.timedelta(seconds=0)
+            parsed = time.strptime(" ".join(forced_reboot), "%Y-%m-%d %H:%M:%S")
+            now = int(time.time())
+            delta = time.mktime(parsed) - now
+
             # check if force_date is in the future
-            if force_date - now > nix:
-                if force_crit:
-                    diff_crit = datetime.timedelta(seconds=force_crit)
-                else:
-                    diff_crit = None
-                if force_warn:
-                    diff_warn = datetime.timedelta(seconds=force_warn)
-                else:
-                    diff_warn = None
+            if delta >= 0:
                 sym = ""
-                if diff_crit and diff_crit > force_date - now:
-                    status = 2
+                if force_crit and delta <= force_crit:
                     sym = "(!!)"
-                elif diff_warn and diff_warn > force_date - now:
-                    if status < 1:
-                        status = 1
+                    status = 2
+                elif force_warn and delta <= force_warn:
                     sym = "(!)"
-                boot_txt = ('Reboot enforced on %s to finish updates %s') \
-                              % ( " ".join(forced_reboot), sym )
+                    status = max(status, 1)
+
+                boot_txt = 'Reboot enforced in %s to finish updates%s' % (get_age_human_readable(delta), sym)
                 txt.append(boot_txt)
-        elif reboot_required == 1:
-            if status < 1:
-                status = 1
-            txt.append('Reboot required to finish updates (!)')
 
         return (status, ', '.join(txt), perfdata)
 



More information about the checkmk-commits mailing list