Module: check_mk
Branch: master
Commit: 9c20f61b5940b151b919b30c841ddf7ae8a211ca
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9c20f61b5940b1…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu May 2 14:23:38 2019 +0200
Service attributes: Cleanup check interval handling
* Moved CMC specific things to generic service attribute calculation
* The check_interval is now a mandatory attribute and casted to float
in all cases.
CMK-2030
Change-Id: I6bc03b9fc747afbe0ac49a8f24c81221148a6c61
---
cmk_base/config.py | 25 ++++++++++++++++++-------
tests/unit/cmk_base/test_config.py | 8 ++++++--
2 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index aa10f6f..5f80543 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -3034,16 +3034,27 @@ class ConfigCache(object):
return labels
def get_extra_attributes_of_service(self, hostname, description):
- # type: (str, Text) -> Dict[str, str]
- attrs = {}
+ # type: (str, Text) -> Dict[str, Any]
+ attrs = {
+ "check_interval": 1.0, # 1 minute
+ }
for key, conflist in extra_service_conf.items():
values = self.service_extra_conf(hostname, description, conflist)
- if values:
- if key[0] == "_":
- key = key.upper()
+ if not values:
+ continue
+
+ value = values[0]
+ if value is None:
+ continue
+
+ if key == "check_interval":
+ value = float(value)
+
+ if key[0] == "_":
+ key = key.upper()
+
+ attrs[key] = value
- if values[0] is not None:
- attrs[key] = values[0]
return attrs
def icons_and_actions_of_service(self, hostname, description, checkname, params):
diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py
index d009cef..1ab27b0 100644
--- a/tests/unit/cmk_base/test_config.py
+++ b/tests/unit/cmk_base/test_config.py
@@ -1020,16 +1020,20 @@ def test_labels_of_service(monkeypatch):
@pytest.mark.parametrize("hostname,result", [
- ("testhost1", {}),
+ ("testhost1", {
+ "check_interval": 1.0
+ }),
("testhost2", {
'_CUSTOM': ['value1'],
- 'dingdong': ['value1']
+ 'dingdong': ['value1'],
+ 'check_interval': 10.0,
}),
])
def test_config_cache_extra_attributes_of_service(monkeypatch, hostname, result):
ts = Scenario().add_host(hostname)
ts.set_option(
"extra_service_conf", {
+ "check_interval": [("10", [], ["testhost2"],
"CPU load$", {}),],
"dingdong": [
([
"value1",