Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / check_mk
blob79b19523fb4e2183285ecd05ceb78e18552075f4
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 # .--only_from-----------------------------------------------------------.
28 # | _ __ |
29 # | ___ _ __ | |_ _ / _|_ __ ___ _ __ ___ |
30 # | / _ \| '_ \| | | | | | |_| '__/ _ \| '_ ` _ \ |
31 # | | (_) | | | | | |_| | | _| | | (_) | | | | | | |
32 # | \___/|_| |_|_|\__, |___|_| |_| \___/|_| |_| |_| |
33 # | |___/_____| |
34 # '----------------------------------------------------------------------'
36 # Target value for agent's IP access configuration. Only if this
37 # is not None, the inventory will create services
38 check_mk_only_from_default = None
41 def check_only_from(_no_item, _no_params, _no_info):
42 return 3, '''This has been included in the service "Check_MK" (see long output for details).
43 The functionality of this service has been incorporated in the "Check_MK" service.
44 The corresponding global config option "check_mk_only_from_default"
45 will no longer work; please remove it from your main.mk file if
46 you have been using this service.
47 From now on this feature can be configured via WATO using the
48 ruleset "Allowed IP addresses for agent access" - the same rule that
49 will be used for the agent bakery (if available).
50 The check state will be displayed as part of the "Check_MK" sercice.
51 '''
54 check_info["check_mk.only_from"] = {
55 'check_function': check_only_from,
56 'inventory_function': lambda info: [],
57 'service_description': 'Check_MK Agent Access',
61 # .--agent_update--------------------------------------------------------.
62 # | _ _ _ |
63 # | __ _ __ _ ___ _ __ | |_ _ _ _ __ __| | __ _| |_ ___ |
64 # | / _` |/ _` |/ _ \ '_ \| __| | | | | '_ \ / _` |/ _` | __/ _ \ |
65 # | | (_| | (_| | __/ | | | |_ | |_| | |_) | (_| | (_| | || __/ |
66 # | \__,_|\__, |\___|_| |_|\__|___\__,_| .__/ \__,_|\__,_|\__\___| |
67 # | |___/ |_____| |_| |
68 # '----------------------------------------------------------------------'
70 # Example output from agent:
71 # <<<check_mk>>>
72 # AgentUpdate: last_check 1447777834.22 last_update 1447776761.52 aghash e33d0cebcf7404d9 error None
75 def inventory_cmk_agent_update(info):
76 for line in info:
77 if line[0] == "AgentUpdate:":
78 return [(None, {})]
81 def check_cmk_agent_update(_no_item, _no_params, info):
82 for line in info:
83 if line[0] == "AgentUpdate:":
84 parsed = {}
85 parts = line[1:]
86 while parts:
87 key = parts[0]
88 if key == "error":
89 value = " ".join(parts[1:])
90 parts = []
91 else:
92 value = parts[1]
93 if value == "None":
94 value = None
95 parts = parts[2:]
96 parsed[key] = value
98 now = time.time()
100 if parsed["error"] != "None":
101 yield 1, "error: %s" % parsed["error"]
102 else:
103 yield 0, "no errors"
105 if parsed["last_check"]:
106 try:
107 last_check = float(parsed["last_check"])
108 age = now - last_check
109 # Currently there is no crit level
110 warn = 2 * 3600 * 24
111 if age > warn:
112 state = 1
113 else:
114 state = 0
115 if state:
116 levels_text = " (warn at %s)" % (get_age_human_readable(warn))
117 else:
118 levels_text = ""
119 yield state, "last update check: " + get_timestamp_human_readable(
120 parsed["last_check"]) + levels_text
121 except:
122 yield 1, "no successful connect to server yet"
124 if parsed["last_update"]:
125 yield 0, "last agent update: %s" % get_timestamp_human_readable(
126 parsed["last_update"])
128 if parsed["aghash"]:
129 yield 0, "agent configuration: %s" % parsed["aghash"][:8]
131 return
134 check_info["check_mk.agent_update"] = {
135 'check_function': check_cmk_agent_update,
136 'inventory_function': inventory_cmk_agent_update,
137 'service_description': 'Check_MK Agent'