Cleanup config.nodes_of
[check_mk.git] / inventory / win_wmi_updates
blob08f447ce1b78de719df1aebbc621c01dbb7bbc6c
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2013 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 # Example output
28 #<<<win_wmi_updates:sep(44):cached(1494868004,3600)>>>
29 #Node,Description,HotFixID,InstalledOn^M
30 #S050MWSIZ001,Update,KB2849697,5/10/2017^M
31 #S050MWSIZ001,Update,KB2849697,5/10/2017^M
32 #S050MWSIZ001,Update,KB2849696,5/10/2017^M
33 #S050MWSIZ001,Update,KB2849696,5/10/2017^M
34 #S050MWSIZ001,Update,KB2841134,5/10/2017^M
35 # Microsoft Office Professional Plus 2010|Microsoft Corporation|14.0.7015.1000
37 # InstalledOn may have different formats, see
38 # https://docs.microsoft.com/de-de/windows/desktop/CIMWin32Prov/win32-quickfixengineering
39 # Examples:
40 # - 20170523
41 # - 23-10-2013
42 # - 5/23/2017
43 # - 01ce83596afd20a7
46 def _parse_install_date(install_date_str):
47 for format_ in ["%Y%m%d", "%m/%d/%Y", "%d-%m-%Y"]:
48 try:
49 return time.mktime(time.strptime(install_date_str, format_))
50 except ValueError:
51 pass
52 # However, some systems may return a 64-bit hexidecimal value in the Win32
53 # FILETIME format:
54 # Contains a 64-bit value representing the number of 100-nanosecond intervals
55 # since January 1, 1601 (UTC).
56 try:
57 return 1.0 * int(install_date_str, 16) / 10**7
58 except ValueError:
59 pass
60 return
63 def inv_win_wmi_updates(info):
64 paclist = inv_tree_list("software.packages:")
65 for line in info:
66 if len(line) <> 4:
67 continue
69 _, description, knowledge_base, install_date_str = line
70 paclist.append({
71 "name": "Windows Update " + knowledge_base,
72 "version": knowledge_base,
73 "vendor": "Micorosoft " + description,
74 "install_date": _parse_install_date(install_date_str),
75 "package_type": "wmi",
79 inv_info['win_wmi_updates'] = {
80 "inv_function": inv_win_wmi_updates,