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 # <<<suse_connect:sep(58)>>>
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
38 factory_settings
['sles_license_default_levels'] = {
39 'status': 'Registered',
40 'subscription_status': 'ACTIVE',
45 def parse_suseconnect(info
):
47 used_keys
= {'status', 'regcode', 'starts_at', 'expires_at', 'subscription_status', 'type'}
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
:
62 def inventory_suseconnect(parsed
):
66 def check_suseconnect(_no_item
, params
, parsed
):
67 # we assume here that the parsed data contains all required keys
70 yield 3, 'No license information found'
73 state
, infotext
= 0, 'Status: %(status)s' % parsed
74 if params
['status'] != 'Ignore' and params
['status'] != parsed
['status']:
78 state
, infotext
= 0, ', Subscription: %(subscription_status)s' % parsed
79 if (params
['subscription_status'] != 'Ignore' and
80 params
['subscription_status'] != parsed
['subscription_status']):
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
:
96 elif expiration_time
<= warn
* days2seconds
:
101 infotext
= ', Expires in: %s' % get_age_human_readable(expiration_time
)
103 infotext
+= ' (warn/crit at %d/%d days)' % (warn
, crit
)
105 yield state
, infotext
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',