Module: check_mk
Branch: master
Commit: 256cbedcb27bf3c5cde46eacf69fe8e2602e8c2e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=256cbedcb27bf3…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Nov 17 17:38:08 2015 +0100
New plugin for checking Check_MK agent updates
This is not yet useful since the update mechanism itself
is not yet finished.
---
agents/plugins/.f12 | 2 +-
checkman/check_mk.agent_update | 9 +++++
checks/check_mk | 85 ++++++++++++++++++++++++++++++++++++++++
web/htdocs/lib.py | 6 ++-
4 files changed, 99 insertions(+), 3 deletions(-)
diff --git a/agents/plugins/.f12 b/agents/plugins/.f12
index 184bd99..a6cfba2 100755
--- a/agents/plugins/.f12
+++ b/agents/plugins/.f12
@@ -3,4 +3,4 @@ SITE=${SITE:-$(cat ../../.site 2>/dev/null || true)}
SITE=${SITE:-$(omd sites --bare | head -n 1)}
# sudo mkdir -p /usr/lib/check_mk_agent/plugins
# sudo install -m 755 * /usr/lib/check_mk_agent/plugins || true
-sudo rsync --delete -va ./ /omd/sites/$SITE/share/check_mk/agents/plugins/
+sudo rsync -va ./ /omd/sites/$SITE/share/check_mk/agents/plugins/
diff --git a/checkman/check_mk.agent_update b/checkman/check_mk.agent_update
new file mode 100644
index 0000000..a0353bf
--- /dev/null
+++ b/checkman/check_mk.agent_update
@@ -0,0 +1,9 @@
+title: Check automatic agent deployments of Check_MK Agent
+agents: linux, windows
+catalog: generic
+license: GPL
+distribution: check_mk
+description:
+ This plugin makes sure that the Check_MK agent deploy mechanism (if used)
+ is working properly. It checks the time of the last successful connect
+ to the deployment server and if there are any error messages.
diff --git a/checks/check_mk b/checks/check_mk
index 21543b5..2937c0a 100644
--- a/checks/check_mk
+++ b/checks/check_mk
@@ -25,6 +25,14 @@
# Boston, MA 02110-1301 USA.
+# .--only_from-----------------------------------------------------------.
+# | _ __ |
+# | ___ _ __ | |_ _ / _|_ __ ___ _ __ ___ |
+# | / _ \| '_ \| | | | | | |_| '__/ _ \| '_ ` _ \ |
+# | | (_) | | | | | |_| | | _| | | (_) | | | | | | |
+# | \___/|_| |_|_|\__, |___|_| |_| \___/|_| |_| |_| |
+# | |___/_____| |
+# '----------------------------------------------------------------------'
# Target value for agent's IP access configuration. Only if this
# is not None, the inventory will create services
@@ -97,3 +105,80 @@ check_info["check_mk.only_from"] = {
'inventory_function': inventory_only_from,
'service_description': 'Check_MK Agent Access',
}
+
+
+#.
+# .--agent_update--------------------------------------------------------.
+# | _ _ _ |
+# | __ _ __ _ ___ _ __ | |_ _ _ _ __ __| | __ _| |_ ___ |
+# | / _` |/ _` |/ _ \ '_ \| __| | | | | '_ \ / _` |/ _` | __/ _ \ |
+# | | (_| | (_| | __/ | | | |_ | |_| | |_) | (_| | (_| | || __/ |
+# | \__,_|\__, |\___|_| |_|\__|___\__,_| .__/ \__,_|\__,_|\__\___| |
+# | |___/ |_____| |_| |
+# '----------------------------------------------------------------------'
+
+# Example output from agent:
+# <<<check_mk>>>
+# AgentUpdate: last_check 1447777834.22 last_update 1447776761.52 aghash e33d0cebcf7404d9
error None
+
+
+def inventory_cmk_agent_update(info):
+ for line in info:
+ if line[0] == "AgentUpdate:":
+ return [ (None, {}) ]
+
+def check_cmk_agent_update(_no_item, _no_params, info):
+ def output_age(text):
+ if text == "None":
+ return "never"
+ else:
+ return "%s ago" % (get_age_human_readable(time.time() -
float(text)))
+
+ for line in info:
+ if line[0] == "AgentUpdate:":
+ parsed = {}
+ parts = line[1:]
+ while parts:
+ key = parts[0]
+ if key == "error":
+ value = " ".join(parts[1:])
+ parts = []
+ else:
+ value = parts[1]
+ parts = parts[2:]
+ parsed[key] = value
+
+ now = time.time()
+
+ try:
+ last_check = float(parsed["last_check"])
+ age = now - last_check
+ warn, crit = (3600 * 24, 2 * 3600 * 24)
+ if age > crit:
+ state = 2
+ elif age > warn:
+ state = 1
+ else:
+ state = 0
+ if state:
+ levels_text = " (warn/crit at %s/%s)" %
(get_age_human_readable(warn), get_age_human_readable(crit))
+ else:
+ levels_text = ""
+ yield state, "last update check: " +
output_age(parsed["last_check"]) + levels_text
+ except:
+ yield 1, "no successful connect to server yet"
+
+ yield 0, "last agent update: %s" %
output_age(parsed["last_update"])
+ if parsed["aghash"] != "None":
+ yield 0, "agent configuration: %s" %
parsed["aghash"]
+ if parsed["error"] != "None":
+ yield 2, "error: %s" % parsed["error"]
+ else:
+ yield 0, "no errors"
+
+
+check_info["check_mk.agent_update"] = {
+ 'check_function' : check_cmk_agent_update,
+ 'inventory_function' : inventory_cmk_agent_update,
+ 'service_description' : 'Check_MK Agent'
+}
diff --git a/web/htdocs/lib.py b/web/htdocs/lib.py
index 110c144..433be23 100644
--- a/web/htdocs/lib.py
+++ b/web/htdocs/lib.py
@@ -187,12 +187,12 @@ def make_utf8(x):
# because of loss of entropy. So we hope /dev/urandom is enough.
# Furthermore we filter out non-printable characters. The byte
# 0x00 for example does not make it through HTTP and the URL.
-def get_random_string(size):
+def get_random_string(size, from_ascii=48, to_ascii=90):
secret = ""
urandom = file("/dev/urandom")
while len(secret) < size:
c = urandom.read(1)
- if ord(c) >= 48 and ord(c) <= 90:
+ if ord(c) >= from_ascii and ord(c) <= to_ascii:
secret += c
return secret
@@ -438,6 +438,8 @@ def num_split(s):
def cmp_service_name_equiv(r):
if r == "Check_MK":
+ return -6
+ elif r == "Check_MK Agent":
return -5
elif r == "Check_MK Discovery":
return -4