Cleanup config.nodes_of
[check_mk.git] / checks / suseconnect
blob51590ef0cce9c4d7bfe028ff08056ab72c487f95
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 # <<<suse_connect:sep(58)>>>
28 # identifier: SLES
29 # version: 12.1
30 # arch: x86_64
31 # status: Registered
32 # regcode: 987498234zGDTS
33 # starts_at: 2015-12-01 00:00:00 UTC
34 # expires_at: 2019-12-31 00:00:00 UTC
35 # subscription_status: ACTIVE
36 # type: full
38 factory_settings['sles_license_default_levels'] = {
39 'status': 'Registered',
40 'subscription_status': 'ACTIVE',
41 'days_left': (14, 7),
45 def parse_suseconnect(info):
46 parsed = {}
47 used_keys = {'status', 'regcode', 'starts_at', 'expires_at', 'subscription_status', 'type'}
49 is_sles = False
50 for item in info:
51 # a value may contain the sep ':' as well
52 key, value = item[0], ":".join(item[1:]).strip()
53 if key == 'identifier':
54 is_sles = True if value == 'SLES' else False
56 if is_sles and key in used_keys:
57 parsed[key] = value
59 return parsed
62 def inventory_suseconnect(parsed):
63 return [(None, {})]
66 def check_suseconnect(_no_item, params, parsed):
67 # we assume here that the parsed data contains all required keys
69 if not parsed:
70 yield 3, 'No license information found'
71 return
73 state, infotext = 0, 'Status: %(status)s' % parsed
74 if params['status'] != 'Ignore' and params['status'] != parsed['status']:
75 state = 2
76 yield state, infotext
78 state, infotext = 0, ', Subscription: %(subscription_status)s' % parsed
79 if (params['subscription_status'] != 'Ignore' and
80 params['subscription_status'] != parsed['subscription_status']):
81 state = 2
82 yield state, infotext
84 yield 0, (', Subscription type: %(type)s, Registration code: %(regcode)s, '
85 'Starts at: %(starts_at)s, Expires at: %(expires_at)s') % parsed
87 expiration_date = time.strptime(parsed['expires_at'], '%Y-%m-%d %H:%M:%S %Z')
88 expiration_time = time.mktime(expiration_date) - time.time()
90 if expiration_time > 0:
91 warn, crit = params['days_left']
92 days2seconds = 24 * 60 * 60
94 if expiration_time <= crit * days2seconds:
95 state = 2
96 elif expiration_time <= warn * days2seconds:
97 state = 1
98 else:
99 state = 0
101 infotext = ', Expires in: %s' % get_age_human_readable(expiration_time)
102 if state:
103 infotext += ' (warn/crit at %d/%d days)' % (warn, crit)
105 yield state, infotext
106 else:
107 yield 2, ', Expired since: %s' % get_age_human_readable(-1.0 * expiration_time)
110 check_info['suseconnect'] = {
111 'service_description': 'SLES license',
112 'parse_function': parse_suseconnect,
113 'inventory_function': inventory_suseconnect,
114 'check_function': check_suseconnect,
115 'group': 'sles_license',
116 'default_levels_variable': 'sles_license_default_levels',