Module: check_mk
Branch: master
Commit: a358a84e64de8b733f5f0907e36a46484a66ffc7
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a358a84e64de8b…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Mar 21 16:06:25 2019 +0100
7326 FIX "Update DNS cache" action is now really cleaning up the cache
As written in the documentation
(https://mathias-kettner.com/cms_wato_hosts.html) Check_MK is keeping an
internal DNS cache for the hosts that have configured no static IP address in
Check_MK:
---
With the host name method Check_MK uses cached data in order to minimise
repeated DNS requests during an Activate Changes – which is very important for
accelerating the activation procedure. Furthermore, the cache ensures that a
changed configuration can still be activated if the DNS stops working.
The catch is that Check_MK doesn't automatically notice the change to an
address in DNS. For this reason, in the host details there is the button which
deletes the entire DNS cache and forces a new resolution at the next Activate
changes. This file is found under ~/var/check_mk/ipaddresses.cache in your
instance, by the way. Deleting this file has the same effect as the button as
described above.
---
The problem was that previous versions did not really delete the entire cache,
but only updated it. We have now changed this to make the cache invalidation
work as intended.
Change-Id: I603f7ef5f38234f67ce5436082c91b506d516732
---
.werks/7326 | 34 ++++++++++++++++++++++++++
cmk_base/ip_lookup.py | 19 ++++++++++----
tests/integration/cmk_base/test_automations.py | 3 +++
3 files changed, 51 insertions(+), 5 deletions(-)
diff --git a/.werks/7326 b/.werks/7326
new file mode 100644
index 0000000..877f9fc
--- /dev/null
+++ b/.werks/7326
@@ -0,0 +1,34 @@
+Title: "Update DNS cache" action is now really cleaning up the cache
+Level: 2
+Component: wato
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1553180606
+Class: fix
+
+
+As written in the documentation
+(https://mathias-kettner.com/cms_wato_hosts.html) Check_MK is keeping an
+internal DNS cache for the hosts that have configured no static IP address in
+Check_MK:
+
+---
+
+With the host name method Check_MK uses cached data in order to minimise
+repeated DNS requests during an Activate Changes – which is very important for
+accelerating the activation procedure. Furthermore, the cache ensures that a
+changed configuration can still be activated if the DNS stops working.
+
+The catch is that Check_MK doesn't automatically notice the change to an
+address in DNS. For this reason, in the host details there is the button which
+deletes the entire DNS cache and forces a new resolution at the next Activate
+changes. This file is found under ~/var/check_mk/ipaddresses.cache in your
+instance, by the way. Deleting this file has the same effect as the button as
+described above.
+
+---
+
+The problem was that previous versions did not really delete the entire cache,
+but only updated it. We have now changed this to make the cache invalidation
+work as intended.
diff --git a/cmk_base/ip_lookup.py b/cmk_base/ip_lookup.py
index 513e524..6c3f998 100644
--- a/cmk_base/ip_lookup.py
+++ b/cmk_base/ip_lookup.py
@@ -25,6 +25,8 @@
# Boston, MA 02110-1301 USA.
import socket
+import errno
+import os
import cmk.utils.paths
import cmk.utils.debug
@@ -189,7 +191,7 @@ def _update_ip_lookup_cache(cache_id, ipa):
ip_lookup_cache = cmk_base.config_cache.get_dict("ip_lookup")
# Read already known data
- cache_path = cmk.utils.paths.var_dir + '/ipaddresses.cache'
+ cache_path = _cache_path()
try:
data_from_file = cmk.utils.store.load_data_from_file(cache_path, default={}, lock=True)
@@ -206,14 +208,21 @@ def _update_ip_lookup_cache(cache_id, ipa):
cmk.utils.store.release_lock(cache_path)
+def _cache_path():
+ return cmk.utils.paths.var_dir + "/ipaddresses.cache"
+
+
def update_dns_cache():
- # Temporarily disable *use* of cache, we want to force an update
- # TODO: Cleanup this hacky config override! Better add some global flag
- # that is exactly meant for this situation.
- config.use_dns_cache = False
updated = 0
failed = []
+ console.verbose("Cleaning up existing DNS cache...\n")
+ try:
+ os.unlink(_cache_path())
+ except OSError as e:
+ if e.errno != errno.ENOENT:
+ raise
+
console.verbose("Updating DNS cache...\n")
for hostname in config.all_active_hosts():
# Use intelligent logic. This prevents DNS lookups for hosts
diff --git a/tests/integration/cmk_base/test_automations.py b/tests/integration/cmk_base/test_automations.py
index 5d37871..b9786a9 100644
--- a/tests/integration/cmk_base/test_automations.py
+++ b/tests/integration/cmk_base/test_automations.py
@@ -323,6 +323,8 @@ def test_automation_update_dns_cache(test_cfg, site, web):
web.add_host("update-dns-cache-host")
web.add_host("localhost")
+ site.write_file(cache_path, "{('bla', 4): '127.0.0.1'}")
+
data = _execute_automation(site, "update-dns-cache")
assert isinstance(data, tuple)
assert len(data) == 2
@@ -335,6 +337,7 @@ def test_automation_update_dns_cache(test_cfg, site, web):
cache = eval(site.read_file(cache_path))
assert isinstance(cache, dict)
assert cache[("localhost", 4)] == "127.0.0.1"
+ assert ("bla", 4) not in cache
finally:
web.delete_host("localhost")
Module: check_mk
Branch: master
Commit: c37a0c350f8b667f05aef31c2ebc1fb0b3af2ebf
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c37a0c350f8b66…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Fri Mar 22 08:46:28 2019 +0100
added WK7247: Fixed incomplete counter cleanup routine
Change-Id: Ia2565c70e5c80e8d679cfc21c8b223a9f0323105
---
.werks/7247 | 17 +++++++++++++++++
checks/ps | 2 +-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/.werks/7247 b/.werks/7247
new file mode 100644
index 0000000..bb8d295
--- /dev/null
+++ b/.werks/7247
@@ -0,0 +1,17 @@
+Title: ps.perf: Fixed incomplete counter cleanup routine, leading to ever-growing counter state files
+Level: 1
+Component: checks
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1553175847
+
+The ps check regularly creates counter values with dyamic names and save them into the counter state file.
+There is a cleanup routine which removes outdated counters.
+
+This cleanup routine failed at cleaning up counter values from the deprecated ps.perf check.
+As a result the check counters file did steadily grow. This has been fixed. The cleanup now also
+checks for outdated ps.perf counters.
+
diff --git a/checks/ps b/checks/ps
index a0a09cb..5e354c3 100644
--- a/checks/ps
+++ b/checks/ps
@@ -98,7 +98,7 @@ def ps_cleanup_counters(parsed):
def ps_get_counters_to_delete(pids):
counters_to_delete = []
for ident in get_all_item_states():
- if isinstance(ident, tuple) and ident[0] == "ps":
+ if isinstance(ident, tuple) and ident[0] in ["ps", "ps.perf"]:
check_ident = ident[2]
elif not isinstance(ident, tuple) and (ident.startswith("ps_stat") or
ident.startswith("ps_wmic")):
Module: check_mk
Branch: master
Commit: 8d2447a293e3830b5880b0a97b062cc487cf1144
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8d2447a293e383…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Fri Mar 22 08:39:25 2019 +0100
picked WK7246: Prevent automatic discovery of duplicate services with the same service description
Change-Id: I9cedb1a76839ae8d8310433dbbcfe57d3eb95a23
---
.werks/7246 | 14 ++++++++++++++
cmk_base/check_table.py | 6 +++---
cmk_base/discovery.py | 12 ++++++++++++
3 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/.werks/7246 b/.werks/7246
new file mode 100644
index 0000000..67239c3
--- /dev/null
+++ b/.werks/7246
@@ -0,0 +1,14 @@
+Title: Prevent automatic discovery of duplicate services with the same service description
+Level: 1
+Component: checks
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1552918330
+
+Hosts using snmp as well as tcp checks may run into a scenario where discovered snmp checks share the same service description as the tcp based checks.
+One example is the service description <tt>Uptime</tt>, which is created by the <tt>snmp_uptime</tt> and <tt>uptime</tt> check.
+
+In case of identical service descriptions, the tcp based check wins and the snmp based check is ignored.
diff --git a/cmk_base/check_table.py b/cmk_base/check_table.py
index a96d818..04c6af5 100644
--- a/cmk_base/check_table.py
+++ b/cmk_base/check_table.py
@@ -67,7 +67,7 @@ def get_check_table(hostname,
# needs to be done in all cases since a host can now have a lot of different data
# sources.
if remove_duplicates and host_config.is_dual_host:
- return _remove_duplicate_checks(check_table_cache[table_cache_id])
+ return remove_duplicate_checks(check_table_cache[table_cache_id])
return check_table_cache[table_cache_id]
check_table = {}
@@ -204,7 +204,7 @@ def get_check_table(hostname,
check_table_cache[table_cache_id] = check_table
if remove_duplicates:
- return _remove_duplicate_checks(check_table)
+ return remove_duplicate_checks(check_table)
return check_table
@@ -267,7 +267,7 @@ def service_deps(hostname, servicedesc):
return deps
-def _remove_duplicate_checks(check_table):
+def remove_duplicate_checks(check_table):
have_with_tcp = {}
have_with_snmp = {}
without_duplicates = {}
diff --git a/cmk_base/discovery.py b/cmk_base/discovery.py
index 8a4e6ed..a4729c5 100644
--- a/cmk_base/discovery.py
+++ b/cmk_base/discovery.py
@@ -713,6 +713,18 @@ def _discover_services(hostname, ipaddress, sources, multi_host_sections, on_err
elif on_error == "warn":
console.error("Discovery of '%s' failed: %s\n" % (check_plugin_name, e))
+ check_table_formatted = {}
+ for (check_type, item, _paramstring) in discovered_services:
+ check_table_formatted[(check_type, item)] = (None,
+ config.service_description(
+ hostname, check_type, item))
+
+ check_table_formatted = check_table.remove_duplicate_checks(check_table_formatted)
+ for entry in discovered_services[:]:
+ check_type, item = entry[:2]
+ if (check_type, item) not in check_table_formatted:
+ discovered_services.remove(entry)
+
return discovered_services
except KeyboardInterrupt: