[checkmk-commits] Check_MK Git: check_mk: EC slave can copy rules from master via button

Mathias Kettner mk at mathias-kettner.de
Fri Nov 30 10:05:13 CET 2012


Module: check_mk
Branch: master
Commit: 06a979af3b27683fcad801375dd1f370a536cc3f
URL:    http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=06a979af3b27683fcad801375dd1f370a536cc3f

Author: Mathias Kettner <mk at mathias-kettner.de>
Date:   Fri Nov 30 10:05:10 2012 +0100

EC slave can copy rules from master via button

---

 ChangeLog                             |    2 ++
 mkeventd/web/plugins/wato/mkeventd.py |   28 +++++++++++++++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 968b550..16e6faa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -40,6 +40,8 @@
 
     Event Console:
     * FIX: fix exception in rules that use facility local7
+    * Replication slave can now copy rules from master into local configuration
+      via a new button in WATO.
 
 1.2.1i3:
     Core:
diff --git a/mkeventd/web/plugins/wato/mkeventd.py b/mkeventd/web/plugins/wato/mkeventd.py
index b083d1a..58c0401 100644
--- a/mkeventd/web/plugins/wato/mkeventd.py
+++ b/mkeventd/web/plugins/wato/mkeventd.py
@@ -771,6 +771,20 @@ def mode_mkeventd_rules(phase):
             else:
                 return
 
+        elif html.has_var("_copy_rules"):
+            c = wato_confirm(_("Confirm copying rules"),
+                             _("Do you really want to copy all event rules from the master and "
+                               "replace your local configuration with them?"))
+            if c:
+                copy_rules_from_master()
+                log_mkeventd("copy-rules-from-master", _("Copied the event rules from the master "
+                             "into the local configuration"))
+                return None, _("Copied rules from master")
+            elif c == False:
+                return ""
+            else:
+                return
+
             
         if html.check_transaction():
             if html.has_var("_move"):
@@ -785,10 +799,14 @@ def mode_mkeventd_rules(phase):
 
     rep_mode = mkeventd.replication_mode()
     if rep_mode in [ "sync", "takeover" ]:
+        copy_url = make_action_link([("mode", "mkeventd_rules"), ("_copy_rules", "1")])
         html.show_warning(_("WARNING: This Event Console is currently running as a replication "
           "slave. The rules edited here will not be used. Instead a copy of the rules of the "
           "master are being used in the case of a takeover. The same holds for the event "
-          "actions in the global settings."))
+          "actions in the global settings.<br><br>If you want you can copy the ruleset of "
+          "the master into your local slave configuration: ") + \
+          '<a class=button href="%s">' % copy_url + 
+          _("Copy Rules From Master") + '</a>')
 
     if len(rules) == 0:
         html.write(_("You have not created any rules yet."))
@@ -917,6 +935,14 @@ def mode_mkeventd_rules(phase):
     html.write('</table>')
 
 
+def copy_rules_from_master():
+    answer = mkeventd.query("REPLICATE 0")
+    if "rules" not in answer:
+        raise MKGeneralException(_("Cannot get rules from local event daemon."))
+    rules = answer["rules"]
+    save_mkeventd_rules(rules)
+
+
 def mode_mkeventd_edit_rule(phase):
     rules = load_mkeventd_rules()
     # Links from status view refer to rule via the rule id



More information about the checkmk-commits mailing list