Module: check_mk
Branch: master
Commit: ca9d6828a6cd3f1f6db455b0208fbd10b5cb8d74
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ca9d6828a6cd3f…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Wed Dec 6 17:18:19 2017 +0100
Added some basic tests for check plugin 'if'
Change-Id: If0ac4210cc5f04754b2ea51cb3a2ee4d7b986e69
---
checks/if.include | 3 +++
tests/checks/test_if_check.py | 50 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 53 insertions(+)
diff --git a/checks/if.include b/checks/if.include
index 2331844..2bff526 100644
--- a/checks/if.include
+++ b/checks/if.include
@@ -305,6 +305,9 @@ def inventory_if_common(info, has_nodeinfo = False):
group_patterns = _prepare_if_group_patterns_from_conf()
+
+ print settings_sets
+
for settings in settings_sets:
uses_description = settings.get('use_desc',
if_inventory_uses_description)
uses_alias = settings.get('use_alias', if_inventory_uses_alias)
diff --git a/tests/checks/test_if_check.py b/tests/checks/test_if_check.py
new file mode 100644
index 0000000..4098e87
--- /dev/null
+++ b/tests/checks/test_if_check.py
@@ -0,0 +1,50 @@
+import pytest
+import pprint
+import ast
+from testlib import cmk_path
+
+# Mark all tests in this file as check related tests
+pytestmark = pytest.mark.checks
+
+
+# line in info:
+# [NODE_INFO]
+# ifIndex
+# ifDescr
+# ifType
+# ifSpeed
+# ifOperStatus
+# ifInOctets
+# inucast
+# inmcast
+# inbcast
+# ifInDiscards
+# ifInErrors
+# ifOutOctets
+# outucast
+# outmcast
+# outbcast
+# ifOutDiscards
+# ifOutErrors,
+# ifOutQLen
+# ifAlias
+# ifPhysAddress
+
+
+(a)pytest.mark.parametrize("info,inventory_if_rules,result"sult", [
+ ([], [], 0),
+ ([20*[""]], [], 0),
+ ([20*["0"]], [], 0),
+ ([21*[""]], [], 0),
+ ([21*["0"]], [], 0),
+ ([["1", "EINS", "6", "10", "1"] +
13*["0"] + ["EINS-ALIAS", "00:00:00:00:00:00"]], [], 1),
+ ([["1", "EINS", "6", "10", "2"] +
13*["0"] + ["EINS-ALIAS", "00:00:00:00:00:00"]], [], 0),
+ ([["1", "EINS", "00000", "10", "1"]
+ 13*["0"] + ["EINS-ALIAS", "00:00:00:00:00:00"]], [], 0),
+ ([["1", "EINS", "6", "10", "1"] +
13*["0"] + ["EINS-ALIAS", "00:00:00:00:00:00"],
+ ["1", "EINS-DUPLICATE", "6", "10",
"1"] + 13*["0",] + ["EINS-ALIAS-DUPLICATE",
"00:00:00:00:00:00"]], [], 2),
+])
+def test_if_inventory_if_common_count_interfaces(check_manager, monkeypatch, info,
inventory_if_rules, result):
+ check = check_manager.get_check("if")
+ #TODO How to handle several "host_extra_conf"s?
+ #monkeypatch.setitem(check.context, "host_extra_conf", lambda _, __:
inventory_if_rules)
+ assert len(check.run_discovery(info)) == result