Cleanup config.nodes_of
[check_mk.git] / checks / livestatus_status
blob90762159bdff0d38da6137a95c5717c2dbc80f3f
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 # Example output from agent:
28 # <<<livestatus_status:sep(59)>>>
29 # [downsite]
30 # [mysite]
31 # accept_passive_host_checks;accept_passive_service_checks;cached_log_messages;check_external_commands;check_host_freshness;check_service_freshness;connections;connections_rate;enable_event_handlers;enable_flap_detection;enable_notifications;execute_host_checks;execute_service_checks;external_command_buffer_max;external_command_buffer_slots;external_command_buffer_usage;external_commands;external_commands_rate;forks;forks_rate;host_checks;host_checks_rate;interval_length;last_command_check;last_log_rotation;livecheck_overflows;livecheck_overflows_rate;livechecks;livechecks_rate;livestatus_active_connections;livestatus_queued_connections;livestatus_threads;livestatus_version;log_messages;log_messages_rate;nagios_pid;neb_callbacks;neb_callbacks_rate;num_hosts;num_services;obsess_over_hosts;obsess_over_services;process_performance_data;program_start;program_version;requests;requests_rate;service_checks;service_checks_rate
32 # 1;1;0;1;0;1;231;1.0327125668e-01;1;1;1;1;1;0;32768;0;0;0.0000000000e+00;0;0.0000000000e+00;0;0.0000000000e+00;60;1359471450;0;0;0.0000000000e+00;0;0.0000000000e+00;1;0;20;2013.01.23;0;0.0000000000e+00;15126;15263;6.5307324420e+00;0;0;0;0;1;1359469039;3.2.3;230;1.0327125668e-01;0;0.0000000000e+00
34 factory_settings["livestatus_status_default_levels"] = {
35 "site_stopped": 2,
36 "execute_host_checks": 2,
37 "execute_service_checks": 2,
38 "accept_passive_host_checks": 2,
39 "accept_passive_service_checks": 2,
40 "check_host_freshness": 0, # Was in OMD the default up to now, better not warn
41 "check_service_freshness": 1,
42 "enable_event_handlers": 1,
43 "enable_flap_detection": 1,
44 "enable_notifications": 2,
45 "process_performance_data": 1,
46 "check_external_commands": 2,
47 "site_cert_days": (30, 7),
51 def parse_livestatus_status(info):
52 parsed = {}
53 site, headers = None, None
54 for line in info:
55 if line and line[0][0] == "[" and line[0][-1] == "]":
56 site = line[0][1:-1]
57 parsed[site] = None # Site is marked as down until overwritten later
59 elif site:
60 if headers is None:
61 headers = line
62 else:
63 parsed[site] = dict(zip(headers, line))
64 headers = None
66 return parsed
69 def parse_livestatus_ssl_certs(info):
70 if not info:
71 return {}
73 parsed = {}
74 site = None
75 for line in info:
76 if line and line[0][0] == "[" and line[0][-1] == "]":
77 site = line[0][1:-1]
78 parsed[site] = {}
80 elif site and len(line) == 2:
81 pem_path, valid_until = line
82 parsed[site][pem_path] = valid_until
84 return parsed
87 def inventory_livestatus_status(sections):
88 return [(site, {}) for (site, status) in sections[0].items() if status is not None]
91 def check_livestatus_status(item, params, sections):
92 parsed, ssl_certs = sections[0], parse_livestatus_ssl_certs(sections[1])
94 if item not in parsed:
95 return
96 status = parsed[item]
98 # Ignore down sites. This happens on a regular basis due to restarts
99 # of the core. The availability of a site is monitored with 'omd_status'.
100 if status is None:
101 yield params["site_stopped"], "Site is currently not running"
102 return
104 # Check Performance counters
105 this_time = time.time()
106 status_counters = [
107 # factor,calc_rate,column,format,title
108 (1, True, "%.1f/s", "host_checks", "HostChecks"),
109 (1, True, "%.1f/s", "service_checks", "ServiceChecks"),
110 (1, True, "%.1f/s", "forks", "ProcessCreations"),
111 (1, True, "%.1f/s", "connections", "LivestatusConnects"),
112 (1, True, "%.1f/s", "requests", "LivestatusRequests"),
113 (1, True, "%.1f/s", "log_messages", "LogMessages"),
116 if status["program_version"].startswith("Check_MK"):
117 # We have a CMC here.
119 status_counters += [
120 # factor, calc_rate, format, column, title
121 (1, False, "%.3fs", "average_latency_generic", "Average check latency"),
122 (1, False, "%.3fs", "average_latency_cmk", "Average Check_MK latency"),
123 (100, False, "%.1f%%", "helper_usage_generic", "Check helper usage"),
124 (100, False, "%.1f%%", "helper_usage_cmk", "Check_MK helper usage"),
125 (100, False, "%.1f%%", "livestatus_usage", "Livestatus usage"),
126 (1, False, "%.1f/s", "livestatus_overflows_rate", "Livestatus overflow rate"),
129 for factor, calc_rate, fmt, counter, title in status_counters:
130 value = factor * float(status[counter])
132 if calc_rate:
133 value = get_rate("livestatus_status.%s.%s" % (item, counter), this_time, value)
135 yield 0, ("%s: %s" % (title, fmt % value)), [(counter, value)]
137 yield 0, "%d Hosts" % int(status["num_hosts"]), [("monitored_hosts", int(status["num_hosts"]))]
138 yield 0, "%d Services" % int(status["num_services"]), [("monitored_services",
139 int(status["num_services"]))]
141 # Output some general information
142 yield 0, "Core version: %s" % status["program_version"]
143 yield 0, "Livestatus version: %s" % status["livestatus_version"]
145 pem_path = "/omd/sites/%s/etc/ssl/sites/%s.pem" % (item, item)
146 cert_valid_until = ssl_certs.get(item, {}).get(pem_path)
147 if cert_valid_until is not None:
148 days_left = (int(cert_valid_until) - time.time()) / 86400.0
149 valid_until_formatted = time.strftime("%Y-%m-%d %H:%M:%S",
150 time.localtime(int(cert_valid_until)))
151 ssl_state, ssl_infotext, _ssl_perfdata = check_levels(
152 value=days_left,
153 dsname="site_cert_days",
154 infoname="Site certificate validity (until %s)" % valid_until_formatted,
155 unit="days",
156 params=(None, None, params["site_cert_days"][0], params["site_cert_days"][1]),
158 yield ssl_state, ssl_infotext
160 settings = [
161 ("execute_host_checks", "Active host checks are disabled"),
162 ("execute_service_checks", "Active service checks are disabled"),
163 ("accept_passive_host_checks", "Passive host check are disabled"),
164 ("accept_passive_service_checks", "Passive service checks are disabled"),
165 ("check_host_freshness", "Host freshness checking is disabled"),
166 ("check_service_freshness", "Service freshness checking is disabled"),
167 # ("enable_event_handlers", "Alert handlers are disabled"), # special case below
168 ("enable_flap_detection", "Flap detection is disabled"),
169 ("enable_notifications", "Notifications are disabled"),
170 ("process_performance_data", "Performance data is disabled"),
171 ("check_external_commands", "External commands are disabled"),
173 # Check settings of enablings. Here we are quiet unless a non-OK state is found
174 for settingname, title in settings:
175 if status[settingname] != '1' and params[settingname] != 0:
176 yield params[settingname], title
178 # special considerations for enable_event_handlers
179 if status["program_version"].startswith("Check_MK 1.2.6"):
180 # In CMC <= 1.2.6 event handlers cannot be enabled. So never warn.
181 return
182 if status.get("has_event_handlers", '1') == '0':
183 # After update from < 1.2.7 the check would warn about disabled alert
184 # handlers since they are disabled in this case. But the user has no alert
185 # handlers defined, so this is nothing to warn about. Start warn when the
186 # user defines his first alert handlers.
187 return
188 else:
189 if status["enable_event_handlers"] != '1' and params["enable_event_handlers"] != 0:
190 yield params["enable_event_handlers"], "Alert handlers are disabled"
193 check_info['livestatus_status'] = {
194 "parse_function": parse_livestatus_status,
195 "inventory_function": inventory_livestatus_status,
196 "check_function": check_livestatus_status,
197 "service_description": "OMD %s performance",
198 "has_perfdata": True,
199 "group": "livestatus_status",
200 "default_levels_variable": "livestatus_status_default_levels",
201 "extra_sections": ["livestatus_ssl_certs"],