Cleanup config.nodes_of
[check_mk.git] / checks / windows_updates
blob7f7d324d2597fbeaa92e8f5204cd3838c13c2c3b
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
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 # <<<windows_updates>>>
28 # 0 2 5
29 # Windows XP Service Pack 3 (KB936929); Windows-Tool zum Entfernen sch�dlicher Software - M�rz 2011 (KB890830)
30 # Update f�r WMDRM-f�hige Medienplayer (KB891122); Windows Media Player 11; Windows Search 4.0 f�r Windows XP (KB940157); Microsoft Base Smartcard-Kryptografiedienstanbieter-Paket: x86 (KB909520); Update f�r die Microsoft .NET Framework 3.5 Service Pack 1- und .NET Framework 3.5-Produktfamilie (KB951847) x86
32 # First row: Reboot_required, num_important, num_optional
33 # Second row: List of all important updates (optional)
34 # Third row: List of all optional updates (optional)
35 # Last row: Date and time of forced update (optional)
37 windows_updates_default_params = (0, 0, 0, 0, 604800, 172800, True)
40 def inventory_windows_updates(info):
41 if info and len(info[0]) == 3:
42 return [(None, "windows_updates_default_params")]
45 def check_windows_updates(_no_item, params, info):
46 if info and len(info[0]) == 3:
47 status = 0
48 # Workarround to return errors from the plugin
49 if info[0][0] == 'x':
50 return 2, ' '.join(info[1])
51 reboot_required, num_imp, num_opt = map(saveint, info[0])
52 imp_warn, imp_crit, opt_warn, opt_crit = params[0:4]
53 if len(params) == 7:
54 force_warn, force_crit, verbose = params[4:7]
55 else:
56 force_warn = 604800
57 force_crit = 172800
58 verbose = True
59 important = ''
60 optional = ''
62 last = 1
63 if num_imp != 0:
64 important = ' '.join(info[1])
65 last += 1
66 if num_opt != 0 and num_imp != 0:
67 last += 1
68 optional = ' '.join(info[2])
69 elif num_opt != 0:
70 last += 1
71 optional = ' '.join(info[1])
73 # the last element may be the forced_reboot time
74 forced_reboot = ""
75 if len(info) - 1 == last and len(info[last]) == 2:
76 forced_reboot = info[last]
78 txt = []
79 perfdata = []
80 for label, updates, cur, warn, crit in [('important', important, num_imp, imp_warn,
81 imp_crit),
82 ('optional', optional, num_opt, opt_warn,
83 opt_crit)]:
84 this_txt = '%d %s updates' % (cur, label)
85 if crit and cur >= crit:
86 this_txt += ' >=%d (!!)' % crit
87 if status < 2:
88 status = 2
89 elif warn and cur >= warn:
90 this_txt += ' >=%d (!)' % warn
91 if status < 1:
92 status = 1
93 if label == 'important' and cur > 0 and verbose:
94 this_txt += ', (%s) --- ' % updates
95 txt.append(this_txt)
96 perfdata.append((label, cur, warn, crit))
98 if reboot_required == 1:
99 if status < 1:
100 status = 1
101 txt.append('Reboot required to finish updates(!)')
103 if forced_reboot != "":
104 parsed = time.strptime(" ".join(forced_reboot), "%Y-%m-%d %H:%M:%S")
105 now = int(time.time())
106 delta = time.mktime(parsed) - now
108 # check if force_date is in the future
109 if delta >= 0:
110 sym = ""
111 if force_crit and delta <= force_crit:
112 sym = "(!!)"
113 status = 2
114 elif force_warn and delta <= force_warn:
115 sym = "(!)"
116 status = max(status, 1)
118 boot_txt = 'Reboot enforced in %s to finish updates%s' % (
119 get_age_human_readable(delta), sym)
120 txt.append(boot_txt)
122 return (status, ', '.join(txt), perfdata)
124 return (3, 'No windows update information provided')
127 check_info["windows_updates"] = {
128 'check_function': check_windows_updates,
129 'inventory_function': inventory_windows_updates,
130 'service_description': 'System Updates',
131 'group': 'windows_updates',
132 'has_perfdata': True,