Module: check_mk
Branch: master
Commit: 6213efd0b5afd3beebe12fdb074d49b3cbfacce8
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6213efd0b5afd3…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Wed Apr 3 12:01:50 2019 +0200
7390 FIX ipmi_sensors: Stop flooding syslog if no IPMI devices are present
In case no IPMI device was present on a system, the system log was flooded
with error messages.
We no longer call ipmi-sensors if no IPMI devices are found. Considered IPMI
devices are all that match "/dev/ipmi*" (in particular /dev/ipmi0, /dev/ipmi/0
and /dev/ipmidev/0).
CMK-1884
Change-Id: I3a49a4e0ca3c609bff513a60442bb38e1c76cf2a
---
.werks/7390 | 14 ++++++++++++++
agents/check_mk_agent.linux | 2 +-
agents/check_mk_agent.openwrt | 2 +-
3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/.werks/7390 b/.werks/7390
new file mode 100644
index 0000000..4d15b3b
--- /dev/null
+++ b/.werks/7390
@@ -0,0 +1,14 @@
+Title: ipmi_sensors: Stop flooding syslog if no IPMI devices are present
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1554283471
+Class: fix
+
+In case no IPMI device was present on a system, the system log was flooded
+with error messages.
+We no longer call ipmi-sensors if no IPMI devices are found. Considered IPMI
+devices are all that match "/dev/ipmi*" (in particular /dev/ipmi0, /dev/ipmi/0
+and /dev/ipmidev/0).
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index b93d76d..b787fd1 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -571,7 +571,7 @@ fi
# IPMI data via ipmi-sensors (of freeipmi). Please make sure, that if you
# have installed freeipmi that IPMI is really support by your hardware.
-if type ipmi-sensors >/dev/null
+if (type ipmi-sensors && ls /dev/ipmi*) &>/dev/null
then
echo '<<<ipmi_sensors>>>'
# Newer ipmi-sensors version have new output format; Legacy format can be used
diff --git a/agents/check_mk_agent.openwrt b/agents/check_mk_agent.openwrt
index 6661bf5..8deb826 100755
--- a/agents/check_mk_agent.openwrt
+++ b/agents/check_mk_agent.openwrt
@@ -410,7 +410,7 @@ fi
# IPMI data via ipmi-sensors (of freeipmi). Please make sure, that if you
# have installed freeipmi that IPMI is really support by your hardware.
-if type ipmi-sensors >/dev/null
+if (type ipmi-sensors && ls /dev/ipmi*) &>/dev/null
then
echo '<<<ipmi_sensors>>>'
# Newer ipmi-sensors version have new output format; Legacy format can be used
Module: check_mk
Branch: master
Commit: eca0e13a18ed01200647cd4074f8fa4628d74866
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=eca0e13a18ed01…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Apr 3 09:50:41 2019 +0200
ConfigCache: Manage HostConfig instances during lifetime
The base code may use config_cache.get_host_config(hostname) to
get a host configuration instance of the given host name. The
ConfigCache object ensures that only a single object is created
per host.
Change-Id: I9b6f285ff5db064318c20eee005206f1ec8ea14f
---
cmk_base/config.py | 15 +++++++++++++++
tests/unit/cmk_base/test_config.py | 9 +++++++++
2 files changed, 24 insertions(+)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index a306b9f..f43a361 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -2927,6 +2927,21 @@ class ConfigCache(object):
# It is used to determine the best rule evualation method
self._all_processed_hosts_similarity = 1
+ # Keep HostConfig instances created with the current configuration cache
+ self._host_configs = {}
+
+ def get_host_config(self, hostname):
+ """Returns a HostConfig instance for the given host
+
+ It lazy initializes the host config object and caches the objects during the livetime
+ of the ConfigCache."""
+ host_config = self._host_configs.get(hostname)
+ if host_config:
+ return host_config
+
+ host_config = self._host_configs[hostname] = HostConfig(hostname)
+ return host_config
+
def _collect_hosttags(self):
for tagged_host in all_hosts + clusters.keys():
parts = tagged_host.split("|")
diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py
index f18895b..4994423 100644
--- a/tests/unit/cmk_base/test_config.py
+++ b/tests/unit/cmk_base/test_config.py
@@ -386,3 +386,12 @@ def test_tags_of_service(monkeypatch):
assert config.get_config_cache().tags_of_service("test-host", "CPU load") == {
"tag_group1": "val1"
}
+
+
+def test_config_cache_get_host_config():
+ cache = config.ConfigCache()
+ assert cache._host_configs == {}
+
+ host_config = cache.get_host_config("xyz")
+ assert isinstance(host_config, config.HostConfig)
+ assert host_config is cache.get_host_config("xyz")