Module: check_mk
Branch: master
Commit: e1bd0cfbbb37a68abc6fea87267a7b5cac15aba6
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e1bd0cfbbb37a6…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Jul 10 16:12:45 2017 +0200
Slightly improved exception handling during icon rendering
Change-Id: Ic48ea8747f8db345a69c615e5d38b0d850e63ae2
---
.werks/4956 | 39 +++++++++++++++++++++++++++++++++++++++
cmk_base/piggyback.py | 13 ++++---------
web/plugins/views/painters.py | 6 ++++--
3 files changed, 47 insertions(+), 11 deletions(-)
diff --git a/.werks/4956 b/.werks/4956
new file mode 100644
index 0000000..9203b97
--- /dev/null
+++ b/.werks/4956
@@ -0,0 +1,39 @@
+Title: Fixed possible exception in cmc.log when working with piggyback data
+Level: 1
+Component: core
+Class: fix
+Compatible: compat
+Edition: cee
+State: unknown
+Version: 1.5.0i1
+Date: 1499694823
+
+When monitoring hosts using piggyback data an exception could occur when
+a host is checked by different processes at the same time. This could happen
+e.g. when the running core updates the piggyback data while a manual
+"check_mk -nv [hostname]" call also tries to update this data.
+
+The fixed exception looks like this in cmc.log:
+
+C+:
+2017-07-03 19:39:04 [4] [Check_MK helper 2835] >> Traceback (most recent call
last):
+2017-07-03 19:39:04 [4] [Check_MK helper 2835] >> File
"/omd/sites/master/share/check_mk/modules/keepalive.py", line 118, in
do_keepalive
+2017-07-03 19:39:04 [4] [Check_MK helper 2835] >> status =
command_function(command_tuple)
+2017-07-03 19:39:04 [4] [Check_MK helper 2835] >> File
"/omd/sites/master/share/check_mk/modules/keepalive.py", line 464, in
execute_keepalive_command
+2017-07-03 19:39:04 [4] [Check_MK helper 2835] >> return
mode_function(hostname, ipaddress)
+2017-07-03 19:39:04 [4] [Check_MK helper 2835] >> File
"/omd/sites/master/share/check_mk/modules/check_mk_base.py", line 1242, in
do_check
+2017-07-03 19:39:04 [4] [Check_MK helper 2835] >>
do_all_checks_on_host(hostname, ipaddress, only_check_types)
+2017-07-03 19:39:04 [4] [Check_MK helper 2835] >> File
"/omd/sites/master/share/check_mk/modules/check_mk_base.py", line 1526, in
do_all_checks_on_host
+2017-07-03 19:39:04 [4] [Check_MK helper 2835] >> res =
execute_check(checkname, item, params, description, aggrname, address)
+2017-07-03 19:39:04 [4] [Check_MK helper 2835] >> File
"/omd/sites/master/share/check_mk/modules/check_mk_base.py", line 1415, in
execute_check
+2017-07-03 19:39:04 [4] [Check_MK helper 2835] >> info =
get_info_for_check(hostname, ipaddress, infotype)
+2017-07-03 19:39:04 [4] [Check_MK helper 2835] >> File
"/omd/sites/master/share/check_mk/modules/check_mk_base.py", line 224, in
get_info_for_check
+2017-07-03 19:39:04 [4] [Check_MK helper 2835] >> info =
apply_parse_function(get_host_info(hostname, ipaddress, section_name, max_cachefile_age,
ignore_check_interval), section_name)
+2017-07-03 19:39:04 [4] [Check_MK helper 2835] >> File
"/omd/sites/master/share/check_mk/modules/check_mk_base.py", line 317, in
get_host_info
+2017-07-03 19:39:04 [4] [Check_MK helper 2835] >> ignore_check_interval)
+2017-07-03 19:39:04 [4] [Check_MK helper 2835] >> File
"/omd/sites/master/share/check_mk/modules/check_mk_base.py", line 461, in
get_realhost_info
+2017-07-03 19:39:04 [4] [Check_MK helper 2835] >>
store_piggyback_info(hostname, piggybacked)
+2017-07-03 19:39:04 [4] [Check_MK helper 2835] >> File
"/omd/sites/master/share/check_mk/modules/check_mk_base.py", line 598, in
store_piggyback_info
+2017-07-03 19:39:04 [4] [Check_MK helper 2835] >> os.rename(dir +
"/.new." + sourcehost, dir + "/" + sourcehost)
+2017-07-03 19:39:04 [4] [Check_MK helper 2835] >> OSError: [Errno 2] No such file
or directory
+C-:
diff --git a/cmk_base/piggyback.py b/cmk_base/piggyback.py
index c945587..edeb9d0 100644
--- a/cmk_base/piggyback.py
+++ b/cmk_base/piggyback.py
@@ -28,6 +28,7 @@ import os
import cmk.paths
import cmk.hostname_translation
+import cmk.store as store
from cmk.exceptions import MKGeneralException
import cmk_base.utils
@@ -66,7 +67,7 @@ def get_piggyback_files(hostname):
raise
for sourcehost in source_hosts:
- if sourcehost in ['.', '..'] or
sourcehost.startswith(".new."):
+ if sourcehost.startswith("."):
continue
file_path = dir + "/" + sourcehost
@@ -97,16 +98,10 @@ def get_piggyback_files(hostname):
def store_piggyback_info(sourcehost, piggybacked):
- piggyback_path = cmk.paths.tmp_dir + "/piggyback/"
for backedhost, lines in piggybacked.items():
console.verbose("Storing piggyback data for %s.\n" % backedhost)
- dir = piggyback_path + backedhost
- if not os.path.exists(dir):
- os.makedirs(dir)
- out = file(dir + "/.new." + sourcehost, "w")
- for line in lines:
- out.write("%s\n" % line)
- os.rename(dir + "/.new." + sourcehost, dir + "/" +
sourcehost)
+ content = "\n".join(lines) + "\n"
+ store.save_file(os.path.join(cmk.paths.tmp_dir, "piggyback",
backedhost, sourcehost), content)
# Remove piggybacked information that is not
# being sent this turn
diff --git a/web/plugins/views/painters.py b/web/plugins/views/painters.py
index 057c434..a4f8f06 100644
--- a/web/plugins/views/painters.py
+++ b/web/plugins/views/painters.py
@@ -62,6 +62,8 @@
# styles are not modular and all defined in check_mk.css. This will
# change in future.
+import traceback
+
import bi # Needed for BI Icon. For arkane reasons (ask htdocs/module.py) this
# cannot be imported in views.py directly.
@@ -302,7 +304,8 @@ def process_multisite_icons(what, row, tags, custom_vars, toplevel):
except Exception, e:
if config.debug:
raise
- result = ("alert", "%s" % e)
+ result = ("alert", "Exception in icon '%s':
%s" %
+ (icon_id, traceback.format_exc()))
if result is None:
continue
@@ -338,7 +341,6 @@ def process_multisite_icons(what, row, tags, custom_vars, toplevel):
icons.append((sort_index, icon_name, title, url))
except Exception, e:
- import traceback
icons.append((sort_index, 'Exception in icon plugin!<br />'
+ traceback.format_exc()))
return icons