Cleanup config.nodes_of
[check_mk.git] / checks / win_license
blob2996c6437137f9c4aa662fe9e70741a93a1ec6af
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2018 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 # <<<win_license>>>
29 # Name: Windows(R) 7, Enterprise edition
30 # Description: Windows Operating System - Windows(R) 7, TIMEBASED_EVAL channel
31 # Partial Product Key: JCDDG
32 # License Status: Initial grace period
33 # Time remaining: 11820 minute(s) (8 day(s))
35 factory_settings['windows_license_default_levels'] = {
36 'status': ['Licensed', 'Initial grace period'],
37 'expiration_time': (14 * 24 * 60 * 60, 7 * 24 * 60 * 60),
41 def parse_win_license(info):
42 parsed = {}
43 for line in info:
44 if len(line) == 0:
45 continue
47 if line[0] == 'License':
48 parsed['License'] = ' '.join(line[2:])
50 # Depending on Windows version this variable reads
51 # Time remaining or Volume activation expiration or is not present
52 if line[0] in ['Time', 'Volume']:
53 expiration = ' '.join(line).split(':')[1].strip()
54 parsed["expiration"] = expiration
55 time_left_re = regex(r'(\d+) minute')
56 time_left = int(time_left_re.search(expiration).group(1)) * 60
57 parsed['expiration_time'] = time_left
58 return parsed
61 def inventory_win_license(parsed):
62 if 'License' in parsed:
63 return [(None, {})]
66 def check_win_license(_item, params, parsed):
67 sw_license = parsed.get('License', None)
69 if not sw_license:
70 return
72 message = "Software is %s" % sw_license
74 license_state = 0 if sw_license in params['status'] else 2
76 if license_state:
77 message += " Required: " + ' '.join(params['status'])
79 yield license_state, message
81 time_left = parsed.get('expiration_time', None)
83 if not time_left:
84 return
86 time_message = "License will expire in %s" % get_age_human_readable(time_left)
88 warn, crit = params['expiration_time']
90 time_state = 0
92 if time_left < crit:
93 time_state = 2
94 elif time_left < warn:
95 time_state = 1
97 if time_state:
98 time_message += " (warn/crit at %s/%s)" % tuple(map(get_age_human_readable, (warn, crit)))
100 yield time_state, time_message
103 check_info['win_license'] = {
104 'service_description': "Windows License",
105 'parse_function': parse_win_license,
106 'inventory_function': inventory_win_license,
107 'check_function': check_win_license,
108 'group': 'win_license',
109 'default_levels_variable': 'windows_license_default_levels',