Module: check_mk
Branch: master
Commit: f213e6f25d9b72aa9a712aa4a87a435b5d3f57d0
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f213e6f25d9b72…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Fri Sep 21 13:20:31 2018 +0200
6572 azure_agent_info: General state of Azure agent
Add a check reporting on the general state of the azure special agent.
It reports the remaining API calls (which are limited to 15.000 per hour),
the monitored groups and encountered issues.
Change-Id: I588e475d8440225d22d91b85630feb7920cbbb39
---
.werks/6572 | 12 ++++
checkman/azure_agent_info | 17 +++++
checks/azure_agent_info | 115 +++++++++++++++++++++++++++++++
cmk/gui/plugins/metrics/check_mk.py | 8 ++-
cmk/gui/plugins/wato/check_parameters.py | 39 +++++++++++
5 files changed, 190 insertions(+), 1 deletion(-)
diff --git a/.werks/6572 b/.werks/6572
new file mode 100644
index 0000000..a827b43
--- /dev/null
+++ b/.werks/6572
@@ -0,0 +1,12 @@
+Title: azure_agent_info: General state of Azure agent
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1537528740
+Class: feature
+
+Add a check reporting on the general state of the azure special agent.
+It reports the remaining API calls (which are limited to 15.000 per hour),
+the monitored groups and encountered issues.
diff --git a/checkman/azure_agent_info b/checkman/azure_agent_info
new file mode 100644
index 0000000..42d0830
--- /dev/null
+++ b/checkman/azure_agent_info
@@ -0,0 +1,17 @@
+title: Azure Agent Info
+agents: linux
+catalog: app/Azure
+license: GPL
+distribution: check_mk
+description:
+ This check reports the general state of the azure special agent.
+ It reports the remaining API calls (which are limited to 15.000 per hour),
+ the monitored groups and encountered issues.
+
+item:
+ "Azure Agent Info".
+
+inventory:
+ One service is created per monitored resource group and one for the
+ host that runs the agent.
+
diff --git a/checks/azure_agent_info b/checks/azure_agent_info
new file mode 100644
index 0000000..7972c1f
--- /dev/null
+++ b/checks/azure_agent_info
@@ -0,0 +1,115 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2018 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at
http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# tails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
+import json
+
+
+factory_settings['azure_agent_info_levels'] = {
+ 'warning_levels': (1, 10),
+ 'exception_levels': (1, 1),
+ 'remaining_reads_levels_lower': (1000, 100),
+ 'remaining_reads_unknown_state': 1,
+}
+
+
+def parse_azure_agent_info(info):
+
+ parsed = {}
+ for row in info:
+ k, v = row[0], json.loads(' '.join(row[1:]))
+
+ if k == 'remaining-reads':
+ try:
+ v = int(v)
+ v = min(int(parsed.get(k, 'fail')), v)
+ except ValueError:
+ pass
+ parsed[k] = v
+ continue
+
+ elif k == 'issue':
+ issues = parsed.setdefault('issues', {})
+ issues.setdefault(v['type'], []).append(v)
+ continue
+
+ parsed.setdefault(k, []).append(v)
+
+ return parsed
+
+
+def discovery_azure_agent_info(parsed):
+ yield "Azure Agent Info", {}
+
+
+def check_azure_agent_info(item, params, parsed):
+
+ reads = parsed.get('remaining-reads')
+ # this is only reported for the Datasource Host, so None
+ # is ignored.
+ if reads is not None:
+ state, txt = 0, "Remaining API reads: %s" % reads
+ if not isinstance(reads, int):
+ yield params['remaining_reads_unknown_state'], txt
+ else:
+ warn, crit = params.get('remaining_reads_levels_lower', (None,
None))
+ if crit is not None and reads <= crit:
+ state = 2
+ elif warn is not None and reads <= warn:
+ state = 1
+ yield state, txt, [('remaining_reads', reads, warn, crit, 0, 15000)]
+
+ groups = parsed.get('monitored-groups')
+ if groups is not None:
+ yield 0, "Monitored groups: %s" % ', '.join(groups[0])
+
+ issues = parsed.get('issues', {})
+ for t in ('warning', 'exception'):
+ count = len(issues.get(t, ()))
+ state, txt = 0, "%d %ss" % (count, t)
+ warn, crit = params.get('%s_levels' % t, (None, None))
+ if crit is not None and count >= crit:
+ state = 2
+ elif warn is not None and count >= warn:
+ state = 1
+ yield state, txt
+
+ for i in sorted(issues.get('exception', []), key=lambda x:
x["msg"]):
+ yield 0, "\nIssue in %s: Exception: %s (!!)" %
(i["issued_by"], i["msg"])
+ for i in sorted(issues.get('warning', []), key=lambda x:
x["msg"]):
+ yield 0, "\nIssue in %s: Warning: %s (!)" % (i["issued_by"],
i["msg"])
+ for i in sorted(issues.get('info', []), key=lambda x: x["msg"]):
+ yield 0, "\nIssue in %s: Info: %s" % (i["issued_by"],
i["msg"])
+
+
+check_info['azure_agent_info'] = {
+ 'parse_function' : parse_azure_agent_info,
+ 'inventory_function' : discovery_azure_agent_info,
+ 'check_function' : check_azure_agent_info,
+ 'service_description' : "%s",
+ 'default_levels_variable': "azure_agent_info_levels",
+ 'has_perfdata' : True,
+ 'group' : "azure_agent_info",
+}
+
diff --git a/cmk/gui/plugins/metrics/check_mk.py b/cmk/gui/plugins/metrics/check_mk.py
index d0a126a..0e1fee0 100644
--- a/cmk/gui/plugins/metrics/check_mk.py
+++ b/cmk/gui/plugins/metrics/check_mk.py
@@ -4409,7 +4409,13 @@ metric_info["queue"] = {
metric_info["avg_response_time"] = {
"title" : _("Average response time"),
"unit" : "s",
- "color" : "#4040ff"
+ "color" : "#4040ff",
+}
+
+metric_info["remaining_reads"] = {
+ "title" : _("Remaining Reads"),
+ "unit" : "count",
+ "color" : "42/a",
}
#.
diff --git a/cmk/gui/plugins/wato/check_parameters.py
b/cmk/gui/plugins/wato/check_parameters.py
index 6092885..b7120d7 100755
--- a/cmk/gui/plugins/wato/check_parameters.py
+++ b/cmk/gui/plugins/wato/check_parameters.py
@@ -4851,6 +4851,44 @@ register_check_parameters(
)
+register_check_parameters(
+ subgroup_applications,
+ "azure_agent_info",
+ ("Azure Agent Info"),
+ Dictionary(
+ elements = [
+ ("warning_levels", Tuple(
+ title = _("Upper levels for encountered warnings"),
+ elements = [
+ Integer(title = _("Warning at"), default_value=1),
+ Integer(title = _("Critical at"), default_value=10),
+ ],
+ )),
+ ("exception_levels", Tuple(
+ title = _("Upper levels for encountered exceptions"),
+ elements = [
+ Integer(title = _("Warning at"), default_value=1),
+ Integer(title = _("Critical at"), default_value=1),
+ ],
+ )),
+ ("remaining_reads_levels_lower", Tuple(
+ title = _("Lower levels for remaining API reads"),
+ elements = [
+ Integer(title = _("Warning below"), default_value=1000),
+ Integer(title = _("Critical below"), default_value=100),
+ ],
+ )),
+ ("remaining_reads_unknown_state", MonitoringState(
+ title = _("State if remaining API reads are unknown"),
+ default_value = 1
+ )),
+ ]
+ ),
+ TextAscii(title = _("Azure Agent Info")),
+ match_type = "dict",
+)
+
+
#.
# .--Environment---------------------------------------------------------.
# | _____ _ _ |
@@ -16376,6 +16414,7 @@ register_check_parameters(
TextAscii( title = _("Node ID")),
"first"
)
+
register_check_parameters(
subgroup_environment,
"carbon_monoxide",