Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / rds_licenses
blob1f658b8538bad3e182e0c11aeb94154a4d71b7bc
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2016 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 # <<<rds_licenses:sep(44)>>>
28 # KeyPackId,Description,KeyPackType,ProductType,ProductVersion,ProductVersionID,TotalLicenses,IssuedLi...
29 # 13,A02-6.00-S,4,0,Windows Server 2008 oder Windows Server 2008 R2,2,-1,100,-1,20380119031407.000000-000
30 # 2,A02-5.00-EX,6,3,Windows 2000 Server,0,-1,0,-1,20351231230000.000000-000
31 # 3,A02-6.00-S,2,0,Windows Server 2008 oder Windows Server 2008 R2,2,250,250,0,20230209121549.000000-000
32 # 14,A02-6.00-S,2,0,Windows Server 2008 oder Windows Server 2008 R2,2,1050,731,319,20380101081108.000000-000
33 # 16,A02-6.00-S,2,0,Windows Server 2008 oder Windows Server 2008 R2,2,50,23,27,20380101150128.000000-000
34 # 17,A02-6.00-S,2,0,Windows Server 2008 oder Windows Server 2008 R2,2,50,18,32,20380101110453.000000-000
35 # 18,A02-6.00-S,2,0,Windows Server 2008 oder Windows Server 2008 R2,2,65,22,43,20380101083530.000000-000
36 # 19,A02-6.00-S,2,0,Windows Server 2008 oder Windows Server 2008 R2,2,600,0,600,20380101083248.000000-000
38 # Insert any new keys here
39 # https://msdn.microsoft.com/en-us/library/aa383803%28v=vs.85%29.aspx#properties
40 rds_licenses_product_versionid_map = {
41 "4": "Windows Server 2012",
42 "3": "Windows Server 2008 R2",
43 "2": "Windows Server 2008"
44 #1 Not supported.
45 #0 Not supported.
49 def parse_rds_licenses(info):
50 parsed = {}
51 headers = info[0]
52 for line in info[1:]:
53 data = dict(zip(headers, line))
54 version_id = data.get("ProductVersionID")
55 if version_id not in rds_licenses_product_versionid_map:
56 continue
57 version = rds_licenses_product_versionid_map[version_id]
58 parsed.setdefault(version, [])
59 parsed[version].append(data)
60 return parsed
63 def inventory_rds_licenses(parsed):
64 for key in parsed:
65 yield key, None
68 def check_rds_licenses(item, params, parsed):
69 license_pack = parsed.get(item)
70 if not license_pack:
71 return
73 total = 0
74 used = 0
75 for pack in license_pack:
76 pack_total = int(pack.get("TotalLicenses"))
77 pack_avail = int(pack.get("AvailableLicenses"))
78 total += pack_total
79 used += pack_total - pack_avail
81 return license_check_levels(total, used, params)
84 check_info['rds_licenses'] = {
85 'parse_function': parse_rds_licenses,
86 'inventory_function': inventory_rds_licenses,
87 'check_function': check_rds_licenses,
88 'service_description': "RDS Licenses %s",
89 'group': "rds_licenses",
90 'has_perfdata': True,
91 'includes': ['license.include'],