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 # <<<windows_updates>>>
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:
48 # Workarround to return errors from the plugin
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]
54 force_warn
, force_crit
, verbose
= params
[4:7]
64 important
= ' '.join(info
[1])
66 if num_opt
!= 0 and num_imp
!= 0:
68 optional
= ' '.join(info
[2])
71 optional
= ' '.join(info
[1])
73 # the last element may be the forced_reboot time
75 if len(info
) - 1 == last
and len(info
[last
]) == 2:
76 forced_reboot
= info
[last
]
80 for label
, updates
, cur
, warn
, crit
in [('important', important
, num_imp
, imp_warn
,
82 ('optional', optional
, num_opt
, opt_warn
,
84 this_txt
= '%d %s updates' % (cur
, label
)
85 if crit
and cur
>= crit
:
86 this_txt
+= ' >=%d (!!)' % crit
89 elif warn
and cur
>= warn
:
90 this_txt
+= ' >=%d (!)' % warn
93 if label
== 'important' and cur
> 0 and verbose
:
94 this_txt
+= ', (%s) --- ' % updates
96 perfdata
.append((label
, cur
, warn
, crit
))
98 if reboot_required
== 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
111 if force_crit
and delta
<= force_crit
:
114 elif force_warn
and delta
<= force_warn
:
116 status
= max(status
, 1)
118 boot_txt
= 'Reboot enforced in %s to finish updates%s' % (
119 get_age_human_readable(delta
), sym
)
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,