Module: check_mk
Branch: master
Commit: 6b75c593f9a924ee0bb1ad287ec3dd29825c2b11
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6b75c593f9a924…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Wed Mar 21 13:08:58 2018 +0100
Fixed race condition regarding rules/rule packs.
Change-Id: I6cd24176ce368b14c69f51c2c112aa3e5aecd4b4
---
cmk/ec/export.py | 3 +++
web/plugins/wato/mkeventd.py | 8 ++++----
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/cmk/ec/export.py b/cmk/ec/export.py
index 47fa629..287678f 100644
--- a/cmk/ec/export.py
+++ b/cmk/ec/export.py
@@ -284,6 +284,9 @@ def save_rule_packs(legacy_rules, rule_packs, pretty_print=False,
dir_=None):
cmk.store.save_file(file_, output)
+# NOTE: It is essential that export_rule_pack() is called *before*
+# save_rule_packs(), otherwise there is a race condition when the EC
+# recursively reads all *.mk files!
def export_rule_pack(rule_pack, pretty_print=False, dir_=None):
# type: (Dict[str, Any], bool, Optional[Path]) -> None
"""
diff --git a/web/plugins/wato/mkeventd.py b/web/plugins/wato/mkeventd.py
index 6ed1def..184a6fe 100644
--- a/web/plugins/wato/mkeventd.py
+++ b/web/plugins/wato/mkeventd.py
@@ -1418,11 +1418,11 @@ def mode_mkeventd_rules(phase):
rule_packs[other_pack_nr]["rules"][0:0] = [ rule ]
del rule_packs[rule_pack_nr]["rules"][move_nr]
- save_mkeventd_rules(legacy_rules, rule_packs)
if other_type_ == ec.RulePackType.exported:
export_mkp_rule_pack(other_pack)
if type_ == ec.RulePackType.exported:
export_mkp_rule_pack(rule_pack)
+ save_mkeventd_rules(legacy_rules, rule_packs)
add_ec_change("move-rule-to-pack", _("Moved rule
%s to pack %s") % (rule["id"], other_pack["id"]))
return None, html.render_text(_("Moved rule %s to pack
%s") % (rule["id"], other_pack["title"]))
@@ -1445,9 +1445,9 @@ def mode_mkeventd_rules(phase):
del rules[nr]
- save_mkeventd_rules(legacy_rules, rule_packs)
if type_ == ec.RulePackType.exported:
export_mkp_rule_pack(rule_pack)
+ save_mkeventd_rules(legacy_rules, rule_packs)
elif c == False:
return ""
else:
@@ -1466,9 +1466,9 @@ def mode_mkeventd_rules(phase):
del rules[from_pos] # make to_pos now match!
rules[to_pos:to_pos] = [rule]
- save_mkeventd_rules(legacy_rules, rule_packs)
if type_ == ec.RulePackType.exported:
export_mkp_rule_pack(rule_pack)
+ save_mkeventd_rules(legacy_rules, rule_packs)
add_ec_change("move-rule", _("Changed position of rule
%s") % rule["id"])
return
@@ -1850,9 +1850,9 @@ def mode_mkeventd_edit_rule(phase):
else:
rules[edit_nr] = rule
- save_mkeventd_rules(legacy_rules, rule_packs)
if type_ == ec.RulePackType.exported:
export_mkp_rule_pack(rule_pack)
+ save_mkeventd_rules(legacy_rules, rule_packs)
if new:
add_ec_change("new-rule", _("Created new event correlation
rule with id %s") % rule["id"])