Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / site_object_counts
blob40864bbe592b0954c67c44b68f3c468d417b035f
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
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 # <<<site_object_counts:sep(124)>>>
28 # [[[heute]]]
29 # Tags|snmp;prod|1;1
30 # Check commands|kernel;mem.linux|4;1
31 # [[[ostable]]]
32 # Tags|snmp;prod|1;1
33 # Check commands|kernel;mem.linux|4;1
34 # {u'heute': {u'Check commands': {u'kernel': 4, u'mem.linux': 1},
35 # u'Tags': {u'prod': 1, u'snmp': 1}},
36 # u'stable': {}}
39 def parse_site_object_counts(info):
40 parsed = {}
41 site_objects = None
42 for line in info:
43 line0 = line[1]
44 if line0.startswith("[[[") and line0.endswith("]]]"):
45 site = line0[3:-3]
46 site_objects = parsed.setdefault("%s/%s" % (site, line[0]), {})
47 continue
49 _, type_, header, data = line
50 if site_objects is not None and data:
51 site_objects.setdefault(type_, dict(zip(header.split(), map(int, data.split(";")))))
52 return parsed
55 def inventory_site_object_counts(parsed):
56 if parsed:
57 return [(None, {})]
60 def check_site_object_counts(item, params, parsed):
61 if not parsed:
62 return
64 summary = {}
65 details = []
66 for site, data in parsed.iteritems():
67 site_infos = []
68 for type_, type_data in data.iteritems():
69 summary_of_type = summary.setdefault(type_, {})
70 data_info = []
71 for k, v in type_data.iteritems():
72 summary_of_type.setdefault(k, 0)
73 summary_of_type[k] += v
74 data_info.append("%s %s" % (v, k))
75 site_infos.append("%s: %s" % (type_.title(), ", ".join(data_info)))
76 details.append("[%s] %s" % (site, ", ".join(site_infos)))
78 infotexts = []
79 perfdata = []
80 for type_, data in summary.iteritems():
81 type_infos = []
82 for k, v in data.iteritems():
83 perfdata.append((("%s %s" % (type_, k)).lower()\
84 .replace(" ", "_")\
85 .replace(".", "_"), v))
86 type_infos.append("%s %s" % (v, k))
87 infotexts.append("%s: %s" % (type_.title(), ", ".join(type_infos)))
89 return 0, "[Summary] %s\n%s" % (", ".join(infotexts), "\n".join(details)), perfdata
92 check_info['site_object_counts'] = {
93 'parse_function': parse_site_object_counts,
94 'inventory_function': inventory_site_object_counts,
95 'check_function': check_site_object_counts,
96 'service_description': 'OMD objects', # Leave 'OMD' to be consistent (OMD %s apache,...)
97 'has_perfdata': True,
98 'node_info': True,