Module: check_mk
Branch: master
Commit: cbcb443957d6f5b4ef0a5c80d8b60f7acd69199d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=cbcb443957d6f5…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Apr 4 08:02:35 2019 +0200
Cleanup piggyback computation
* Cleanup circular dependency between DataSources computation of
a host and the HostConfig class.
* Directly use piggyback datasource in HostConfig.has_piggyback_data
to reduce the dependencies
* Cleanup duplicated logic
Change-Id: I4662681c75d8c77ff4f923f7e9d6df9eb564680d
---
cmk_base/config.py | 22 +++++++---------------
cmk_base/data_sources/__init__.py | 13 +++++--------
2 files changed, 12 insertions(+), 23 deletions(-)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 8503ac9..71e8adb 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -846,18 +846,8 @@ def is_agent_host(hostname):
if is_tcp_host(hostname):
return True
- tags = tag_list_of_host(hostname)
-
- if "piggyback" in tags:
- is_piggyback_host = True
- elif "no-piggyback" in tags:
- is_piggyback_host = False
- else: # Legacy automatic detection
- import cmk_base.data_sources as data_sources
- is_piggyback_host = piggyback.has_piggyback_raw_data(piggyback_max_cachefile_age,
hostname) or \
-
data_sources.has_persisted_piggyback_agent_sections(hostname)
-
- return is_piggyback_host
+ host_config = get_config_cache().get_host_config(hostname)
+ return host_config.is_piggyback_host
def is_dual_host(hostname):
@@ -2826,9 +2816,11 @@ class HostConfig(object):
@property
def has_piggyback_data(self):
- import cmk_base.data_sources as data_sources
- return piggyback.has_piggyback_raw_data(piggyback_max_cachefile_age,
self.hostname) or \
- data_sources.has_persisted_piggyback_agent_sections(self.hostname)
+ if piggyback.has_piggyback_raw_data(piggyback_max_cachefile_age, self.hostname):
+ return True
+
+ from cmk_base.data_sources.piggyback import PiggyBackDataSource
+ return PiggyBackDataSource(self.hostname, None).has_persisted_agent_sections()
#.
diff --git a/cmk_base/data_sources/__init__.py b/cmk_base/data_sources/__init__.py
index b991f2e..a30a453 100644
--- a/cmk_base/data_sources/__init__.py
+++ b/cmk_base/data_sources/__init__.py
@@ -91,18 +91,15 @@ def _in_keepalive_mode():
# '----------------------------------------------------------------------'
-def has_persisted_piggyback_agent_sections(hostname):
- for source in DataSources(hostname, None).get_data_sources():
- if isinstance(source, PiggyBackDataSource) and
source.has_persisted_agent_sections():
- return True
- return False
-
-
class DataSources(object):
def __init__(self, hostname, ipaddress):
super(DataSources, self).__init__()
self._hostname = hostname
self._ipaddress = ipaddress
+
+ config_cache = config.get_config_cache()
+ self._host_config = config.HostConfig(config_cache, hostname)
+
self._initialize_data_sources()
# Has currently no effect. The value possibly set during execution on the single
data
@@ -145,7 +142,7 @@ class DataSources(object):
self._add_source(SNMPDataSource(self._hostname, self._ipaddress))
def _initialize_management_board_data_sources(self):
- protocol = config.management_protocol_of(self._hostname)
+ protocol = self._host_config.management_protocol
if protocol == "snmp":
# TODO: Why not hand over management board IP address?
self._add_source(SNMPManagementBoardDataSource(self._hostname,
self._ipaddress))