Module: check_mk
Branch: master
Commit: 5fcd950400559d742703d9801002efa641c7036f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5fcd950400559d…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Thu Dec 20 08:35:40 2018 +0100
6949 ACME SBC Health (via SNMP)
This SNMP check reports the health status in percent and the redundancy state of
an ACME SBC device.
Change-Id: Ifbc2573820dfce036b93a3e2cc40644c6a2f7d8d
---
.werks/6949 | 11 +++
checkman/acme_sbc_snmp | 14 ++++
checks/acme_sbc_snmp | 92 ++++++++++++++++++++++
.../plugins/wato/check_parameters/acme_sbc_snmp.py | 55 +++++++++++++
.../checks/generictests/datasets/acme_sbc_snmp.py | 25 ++++++
tests/unit/cmk/gui/test_watolib.py | 2 +
6 files changed, 199 insertions(+)
diff --git a/.werks/6949 b/.werks/6949
new file mode 100644
index 0000000..79e1d27
--- /dev/null
+++ b/.werks/6949
@@ -0,0 +1,11 @@
+Title: ACME SBC Health (via SNMP)
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1545291224
+Class: feature
+
+This SNMP check reports the health status in percent and the redundancy state of
+an ACME SBC device.
diff --git a/checkman/acme_sbc_snmp b/checkman/acme_sbc_snmp
new file mode 100644
index 0000000..2efa09b
--- /dev/null
+++ b/checkman/acme_sbc_snmp
@@ -0,0 +1,14 @@
+title: ACME SBC: Health (via SNMP)
+agents: snmp
+catalog: hw/network/acme
+license: GPL
+distribution: check_mk
+description:
+ This is a simple check which checks the health status in percent and the redundancy
state.
+ The percent value is reported by the devices and reflects the status of cluster
+ and hardware. If the status not is at 100 %, a {WARN} is raised. If a device is in
outOfService
+ or unassigned state, a {CRIT} will be raised. If the device is in an initial or pending
state, a
+ {WARN} will be raised.
+
+inventory:
+ One check will be created.
diff --git a/checks/acme_sbc_snmp b/checks/acme_sbc_snmp
new file mode 100644
index 0000000..d800b84
--- /dev/null
+++ b/checks/acme_sbc_snmp
@@ -0,0 +1,92 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2017 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.
+
+# comNET GmbH, Fabian Binder
+
+# .1.3.6.1.4.1.9148.3.2.1.1.3 Health Score (apSysHealthScore)
+# .1.3.6.1.4.1.9148.3.2.1.1.4 Health Status Description (apSysRedundancy)
+
+factory_settings["acme_sbc_snmp_default_levels"] = {
+ "levels_lower": (99, 75),
+}
+
+
+def inventory_acme_sbc_snmp(info):
+ yield None, {}
+
+
+def check_acme_sbc_snmp(_no_item, params, info):
+ map_states = {
+ "0": (3, "unknown"),
+ "1": (1, "initial"),
+ "2": (0, "active"),
+ "3": (0, "standby"),
+ "4": (2, "out of service"),
+ "5": (2, "unassigned"),
+ "6": (1, "active (pending)"),
+ "7": (1, "standby (pending)"),
+ "8": (1, "out of service (pending)"),
+ "9": (1, "recovery"),
+ }
+
+ try:
+ score, state = info[0]
+ except (IndexError, ValueError):
+ return
+ health_state, health_state_readable = map_states.get(state, (3,
"unknown"))
+ yield health_state, "Health state: %s" % (health_state_readable)
+
+ try:
+ score = int(score)
+ except ValueError:
+ yield 3, "Unknown score: %s" % score
+ return
+ warn, crit = params.get("levels_lower", (None, None))
+ levels_msg = " (warn/crit at or below %s%%/%s%%)" % (warn, crit)
+ score_msg = "Score: %s%%" % score
+ if crit is not None and score <= crit:
+ yield 2, score_msg + levels_msg
+ elif warn is not None and score <= warn:
+ yield 1, score_msg + levels_msg
+ else:
+ yield 0, score_msg
+
+
+check_info['acme_sbc_snmp'] = {
+ 'inventory_function': inventory_acme_sbc_snmp,
+ 'check_function': check_acme_sbc_snmp,
+ 'service_description': 'ACME SBC health',
+ 'snmp_info': (
+ '.1.3.6.1.4.1.9148.3.2.1.1',
+ [
+ "3", # APSYSMGMT-MIB::apSysHealthScore
+ "4", # APSYSMGMT-MIB::apSysRedundancy
+ ]),
+ 'snmp_scan_function': scan_acme,
+ 'includes': ['acme.include'],
+ 'group': 'acme_sbc_snmp',
+ 'default_levels_variable': 'acme_sbc_snmp_default_levels',
+}
diff --git a/cmk/gui/plugins/wato/check_parameters/acme_sbc_snmp.py
b/cmk/gui/plugins/wato/check_parameters/acme_sbc_snmp.py
new file mode 100644
index 0000000..ec83909
--- /dev/null
+++ b/cmk/gui/plugins/wato/check_parameters/acme_sbc_snmp.py
@@ -0,0 +1,55 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2014 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.
+
+from cmk.gui.i18n import _
+from cmk.gui.valuespec import (
+ Integer,
+ Dictionary,
+ Tuple,
+)
+from cmk.gui.plugins.wato import (
+ RulespecGroupCheckParametersApplications,
+ register_check_parameters,
+)
+
+register_check_parameters(
+ RulespecGroupCheckParametersApplications,
+ "acme_sbc_snmp",
+ _("ACME SBC health"),
+ Dictionary(
+ elements=[
+ ("levels_lower",
+ Tuple(
+ title=_("Levels on health status score in percent"),
+ elements=[
+ Integer(title=_("Warning below"),
unit=_("percent"), default_value=99),
+ Integer(title=_("Critical below"),
unit=_("percent"), default_value=75),
+ ])),
+ ],
+ required_keys=["levels_lower"]),
+ None,
+ match_type="dict",
+)
diff --git a/tests/unit/checks/generictests/datasets/acme_sbc_snmp.py
b/tests/unit/checks/generictests/datasets/acme_sbc_snmp.py
new file mode 100644
index 0000000..ef1a7b8
--- /dev/null
+++ b/tests/unit/checks/generictests/datasets/acme_sbc_snmp.py
@@ -0,0 +1,25 @@
+
+
+checkname = 'acme_sbc_snmp'
+
+
+info = [
+ ['20', '2'],
+]
+
+
+discovery = {
+ '': [
+ (None, {}),
+ ],
+}
+
+
+checks = {
+ '': [
+ (None, {'levels_lower': (99, 75)}, [
+ (0, 'Health state: active', []),
+ (2, 'Score: 20% (warn/crit at or below 99%/75%)', []),
+ ]),
+ ],
+}
diff --git a/tests/unit/cmk/gui/test_watolib.py b/tests/unit/cmk/gui/test_watolib.py
index bec1ece..15d5aa5 100644
--- a/tests/unit/cmk/gui/test_watolib.py
+++ b/tests/unit/cmk/gui/test_watolib.py
@@ -582,6 +582,7 @@ def test_grouped_rulespecs():
'static_checks:skype_xmpp',
'static_checks:skype_edgeauth',
'static_checks:acme_certificates',
+ 'static_checks:acme_sbc_snmp',
'static_checks:skype',
'static_checks:skype_proxy',
'static_checks:skype_edge',
@@ -1088,6 +1089,7 @@ def test_grouped_rulespecs():
'checkgroup_parameters:skype_xmpp',
'checkgroup_parameters:skype_edgeauth',
'checkgroup_parameters:acme_certificates',
+ 'checkgroup_parameters:acme_sbc_snmp',
'checkgroup_parameters:skype',
'checkgroup_parameters:skype_proxy',
'checkgroup_parameters:skype_edge',