Module: check_mk
Branch: master
Commit: 169433a9ae37d59f6fba5574ed5e455b77060b6c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=169433a9ae37d5…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Apr 23 20:00:26 2019 +0200
Cleanup config.check_interval_of
CMK-2030
Change-Id: Ic2516a5e990b5d61f10cbbc141b14101179f4453
---
cmk_base/config.py | 33 +++++++++++++++++++++------------
cmk_base/core_nagios.py | 2 +-
cmk_base/data_sources/snmp.py | 2 +-
tests/unit/cmk_base/test_config.py | 17 +++++++++++++++++
4 files changed, 40 insertions(+), 14 deletions(-)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index e19294d..ca28bdc 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -763,18 +763,6 @@ def check_period_of(hostname, service):
return None
-def check_interval_of(hostname, section_name):
- if not cmk_base.cmk_base.check_utils.is_snmp_check(section_name):
- return # no values at all for non snmp checks
-
- # Previous to 1.5 "match" could be a check name (including subchecks)
instead of
- # only main check names -> section names. This has been cleaned up, but we still
- # need to be compatible. Strip of the sub check part of "match".
- for match, minutes in get_config_cache().host_extra_conf(hostname,
snmp_check_interval):
- if match is None or match.split(".")[0] == section_name:
- return minutes # use first match
-
-
#.
# .--Services------------------------------------------------------------.
# | ____ _ |
@@ -2507,6 +2495,27 @@ class HostConfig(object):
of this site"""
return self.hostname in self._config_cache.all_configured_clusters()
+ def snmp_check_interval(self, section_name):
+ # type: (str) -> Optional[int]
+ """Return the check interval of SNMP check sections
+
+ This has been added to reduce the check interval of single SNMP checks (or
+ more precise: sections) to be executed less frequent that the
"Check_MK"
+ service is executed.
+ """
+ if not cmk_base.cmk_base.check_utils.is_snmp_check(section_name):
+ return None # no values at all for non snmp checks
+
+ # Previous to 1.5 "match" could be a check name (including subchecks)
instead of
+ # only main check names -> section names. This has been cleaned up, but we
still
+ # need to be compatible. Strip of the sub check part of "match".
+ for match, minutes in self._config_cache.host_extra_conf(self.hostname,
+ snmp_check_interval):
+ if match is None or match.split(".")[0] == section_name:
+ return minutes # use first match
+
+ return None
+
@property
def agent_port(self):
# type: () -> int
diff --git a/cmk_base/core_nagios.py b/cmk_base/core_nagios.py
index e5f1fbe..fc8e680 100644
--- a/cmk_base/core_nagios.py
+++ b/cmk_base/core_nagios.py
@@ -325,7 +325,7 @@ def _create_nagios_servicedefs(cfg, config_cache, hostname,
host_attrs):
check_interval = int(values[0])
except:
check_interval = float(values[0])
- value = config.check_interval_of(hostname,
cmk_base.check_utils.section_name_of(checkname))
+ value =
host_config.snmp_check_interval(cmk_base.check_utils.section_name_of(checkname))
if value is not None:
check_interval = value
diff --git a/cmk_base/data_sources/snmp.py b/cmk_base/data_sources/snmp.py
index f696658..3795852 100644
--- a/cmk_base/data_sources/snmp.py
+++ b/cmk_base/data_sources/snmp.py
@@ -247,7 +247,7 @@ class SNMPDataSource(DataSource):
persisted_sections = {}
for section_name, section_content in raw_data.items():
- check_interval = config.check_interval_of(self._hostname, section_name)
+ check_interval = self._host_config.snmp_check_interval(section_name)
if check_interval is None:
continue
diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py
index 116175f..c574970 100644
--- a/tests/unit/cmk_base/test_config.py
+++ b/tests/unit/cmk_base/test_config.py
@@ -9,6 +9,7 @@ import cmk
import cmk.utils.paths
import cmk_base.config as config
import cmk_base.piggyback as piggyback
+import cmk_base.check_api as check_api
def test_all_configured_realhosts(monkeypatch):
@@ -399,6 +400,22 @@ def test_host_config_exit_code_spec_individual(monkeypatch, hostname,
result):
assert
config_cache.get_host_config(hostname).exit_code_spec(data_source_id="snmp") ==
result
+(a)pytest.mark.parametrize("hostname,section_name,result"sult", [
+ ("testhost1", "uptime", None),
+ ("testhost2", "uptime", None),
+ ("testhost1", "snmp_uptime", None),
+ ("testhost2", "snmp_uptime", 4),
+])
+def test_host_config_snmp_check_interval(monkeypatch, hostname, section_name, result):
+ config.load_checks(check_api.get_check_api_context, ["checks/uptime",
"checks/snmp_uptime"])
+ ts = Scenario().add_host(hostname)
+ ts.set_ruleset("snmp_check_interval", [
+ (("snmp_uptime", 4), [], ["testhost2"], {}),
+ ])
+ config_cache = ts.apply(monkeypatch)
+ assert config_cache.get_host_config(hostname).snmp_check_interval(section_name) ==
result
+
+
def test_http_proxies():
assert config.http_proxies == {}