Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / omd_status
blobbb2d1564bdddde0cbcd5ed846221cdb99d9af4d6
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 # <<<omd_status>>>
28 # [kaputt]
29 # apache 1
30 # rrdcached 1
31 # npcd 1
32 # nagios 1
33 # crontab 1
34 # OVERALL 1
35 # [test]
36 # apache 1
37 # rrdcached 1
38 # npcd 0
39 # nagios 1
40 # crontab 1
41 # OVERALL 2
44 def inventory_omd_status(info):
45 for site in info.keys():
46 yield site, None
49 def parse_omd_status(info):
50 active = False
51 parsed = {}
53 for line in info:
54 if line[1][0] == '[':
55 item = line[1][1:-1]
56 # items may appear several times in clusters
57 # so dont overwrite the previous node result
58 if item not in parsed:
59 parsed[item] = {}
60 node = line[0]
61 parsed[item][node] = {}
62 parsed[item][node]["stopped"] = []
63 active = True
64 elif active and line[1] == 'OVERALL':
65 if line[2] == '0':
66 parsed[item][node]["overall"] = "running"
67 elif line[2] == '1':
68 parsed[item][node]["overall"] = "stopped"
69 active = False
70 elif active and line[2] != '0':
71 parsed[item][node]["stopped"].append(line[1])
72 parsed[item][node]["overall"] = "partially"
74 return parsed
77 def check_omd_status(item, _no_params, parsed):
79 if item not in parsed:
80 return
82 parsed_site = parsed[item]
83 number_nodes = len(parsed_site)
84 stopped_nodes = 0
86 for node, services in parsed_site.iteritems():
87 if "overall" in services and services["overall"] == "stopped":
88 stopped_nodes += 1
90 # stopped sites are only CRIT when all are stopped
91 if stopped_nodes == number_nodes:
92 state = 2
93 else:
94 state = 0
96 for node, services in parsed_site.iteritems():
97 if node:
98 node_text = " on %s" % node
99 else:
100 node_text = ""
101 if "overall" not in services:
102 infotext = "defective installation%s" % node_text
103 yield 2, infotext
104 elif services["overall"] == "running":
105 infotext = "running%s" % node_text
106 # running sites are always OK
107 yield 0, infotext
108 elif services["overall"] == "stopped":
109 infotext = "stopped%s" % node_text
110 # stopped sites are only CRIT when all are stopped
111 yield state, infotext
112 else:
113 infotext = "partially running%s, stopped services: " % node_text
114 infotext += ", ".join(services["stopped"])
115 # partially running sites are always CRIT
116 yield 2, infotext
119 check_info["omd_status"] = {
120 'check_function': check_omd_status,
121 'inventory_function': inventory_omd_status,
122 'parse_function': parse_omd_status,
123 'service_description': 'OMD %s status',
124 'node_info': True,