Module: check_mk
Branch: master
Commit: 83bec89089310072eadf97e9a59d6bf56e42a472
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=83bec890893100…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Sat Mar 25 15:23:15 2017 +0100
4465 FIX Fixed raise condition when mulitple Check_MK helpers updated the
ipaddresses.cache file
Check helpers now lock the ipaddresses.cache file when they want to update an ip address.
The locked file is read, updated with the new content and written afterwards.
The raise condition happened when multiple check helpers tried to update the file
at the same time, hereby removing some recently looked up ip addresses.
Change-Id: Ic68fcf342b8dc92a2b7d7a28f45f3d9b9b06e5aa
---
.werks/4465 | 14 ++++++++++++++
modules/check_mk.py | 19 ++++++++++++++-----
2 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/.werks/4465 b/.werks/4465
new file mode 100644
index 0000000..2b027f1
--- /dev/null
+++ b/.werks/4465
@@ -0,0 +1,14 @@
+Title: Fixed raise condition when mulitple Check_MK helpers updated the ipaddresses.cache
file
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.5.0i1
+Date: 1490451474
+Class: fix
+
+Check helpers now lock the ipaddresses.cache file when they want to update an ip
address.
+The locked file is read, updated with the new content and written afterwards.
+The raise condition happened when multiple check helpers tried to update the file
+at the same time, hereby removing some recently looked up ip addresses.
+
diff --git a/modules/check_mk.py b/modules/check_mk.py
index ec24602..0e2f2df 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -2268,7 +2268,8 @@ def initialize_ip_lookup_cache():
ip_lookup_cache = cmk_base.config_cache.get_dict("ip_lookup")
try:
- ip_lookup_cache.update(eval(file(cmk.paths.var_dir +
'/ipaddresses.cache').read()))
+ data_from_file = cmk.store.load_data_from_file(cmk.paths.var_dir +
'/ipaddresses.cache', {})
+ ip_lookup_cache.update(data_from_file)
# be compatible to old caches which were created by Check_MK without IPv6
support
if ip_lookup_cache and type(ip_lookup_cache.keys()[0]) != tuple:
@@ -2286,10 +2287,18 @@ def initialize_ip_lookup_cache():
def write_ip_lookup_cache():
ip_lookup_cache = cmk_base.config_cache.get_dict("ip_lookup")
- # TODO: Write using cmk.store
- suffix = "." + str(os.getpid())
- file(cmk.paths.var_dir + '/ipaddresses.cache' + suffix,
'w').write(repr(ip_lookup_cache))
- os.rename(cmk.paths.var_dir + '/ipaddresses.cache' + suffix,
cmk.paths.var_dir + '/ipaddresses.cache')
+
+ cache_path = cmk.paths.var_dir + '/ipaddresses.cache'
+ # Read already known data
+ data_from_file = cmk.store.load_data_from_file(cache_path,
+ default={},
+ lock=True)
+ ip_lookup_cache.update(data_from_file)
+ # The lock from the previous call is released in the following function
+ # (I don't like this)
+ # TODO: this file always grows... there should be a cleanup mechanism
+ # maybe on "cmk --update-dns-cache"
+ cmk.store.save_data_to_file(cache_path, ip_lookup_cache)
def do_update_dns_cache():