[checkmk-commits] Check_MK Git: check_mk: Allow event expiration also on acknowledged events (configurable)

git version control git at mathias-kettner.de
Fri Nov 16 12:37:25 CET 2012


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

Author: Mathias Kettner <mk at mathias-kettner.de>
Date:   Fri Nov 16 12:32:23 2012 +0100

Allow event expiration also on acknowledged events (configurable)

---

 ChangeLog                             |    1 +
 mkeventd/bin/mkeventd                 |   26 +++++++++++++++++++-------
 mkeventd/web/plugins/wato/mkeventd.py |   27 +++++++++++++++++++++++----
 3 files changed, 43 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 595d878..e7d4a27 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -22,6 +22,7 @@
     * New button for generating test events directly via WATO
     * Allow Event Console to replicate from another (master) console for
       fast failover.
+    * Allow event expiration also on acknowledged events (configurable)
 
     Multisite:
     * Enable automation login with _username= and _secret=, while
diff --git a/mkeventd/bin/mkeventd b/mkeventd/bin/mkeventd
index 58d3599..b8b4d94 100755
--- a/mkeventd/bin/mkeventd
+++ b/mkeventd/bin/mkeventd
@@ -727,12 +727,14 @@ class EventServer:
 
 
             # Handle events with a limited lifetime
-            elif event["phase"] == "open" and "live_until" in event:
+            elif "live_until" in event:
                 if now >= event["live_until"]:
-                    events_to_delete.append(nr)
-                    log("Livetime of event %d (rule %s) exceeded. Deleting event." % (
-                            event["id"], event["rule_id"]))
-                    log_event_history(event, "EXPIRED")
+                    allowed_phases = event.get("live_until_phases", ["open"])
+                    if event["phase"] in allowed_phases:
+                        events_to_delete.append(nr)
+                        log("Livetime of event %d (rule %s) exceeded. Deleting event." % (
+                                event["id"], event["rule_id"]))
+                        log_event_history(event, "EXPIRED")
 
 
         # Do delayed deletion now (was delayed in order to keep list indices OK)
@@ -871,6 +873,13 @@ class EventServer:
             else:
                 count_rules += 1
                 rule = rule.copy() # keep original intact because of slave replication
+
+                # Convert some data fields into newer format
+                if "livetime" in rule:
+                    livetime = rule["livetime"]
+                    if type(livetime) != tuple:
+                        rule["livetime"] = ( livetime, ["open"] )
+
                 self._rules.append(rule)
                 self._rule_by_id[rule["id"]] = rule
                 try:
@@ -1980,9 +1989,12 @@ class EventStatus():
 
 def do_rule_actions(rule, event):
     # Prepare for events with a limited livetime. This time starts
-    # when the event enters the open state.
+    # when the event enters the open state or acked state
     if "livetime" in rule:
-        event["live_until"] = time.time() + rule["livetime"]
+        livetime, phases = rule["livetime"]
+        event["live_until"] = time.time() + livetime
+        event["live_until_phases"] = phases
+
     for aname in rule.get("actions", []):
         action = g_config["action"].get(aname)
         if not action:
diff --git a/mkeventd/web/plugins/wato/mkeventd.py b/mkeventd/web/plugins/wato/mkeventd.py
index ceaf169..b083d1a 100644
--- a/mkeventd/web/plugins/wato/mkeventd.py
+++ b/mkeventd/web/plugins/wato/mkeventd.py
@@ -422,10 +422,22 @@ vs_mkeventd_rule = Dictionary(
                      "rule."))
         ),
         ( "livetime",
-          Age(
-            title = _("Limit event livetime"),
-            help = _("If you set a livetime of an event, then it will automatically be "
-                     "deleted after that time if, even if no action has taken by the user."),
+          Tuple(
+              title = _("Limit event livetime"),
+              help = _("If you set a livetime of an event, then it will automatically be "
+                       "deleted after that time if, even if no action has taken by the user. You can "
+                       "decide whether to expire open, acknowledged or both types of events. The lifetime "
+                       "always starts when the event is entering the open state."),
+              elements = [
+                  Age(),
+                  ListChoice(
+                    choices = [
+                      ( "open", _("Expire events that are in state <i>open</i>") ),
+                      ( "ack", _("Expire events thar are in state <i>acknowledged</i>") ),
+                    ],
+                    default_value = [ "open" ],
+                  )
+              ],
           ),
         ),
         ( "match",
@@ -659,6 +671,13 @@ def load_mkeventd_rules():
             for rule in vars["rules"]:
                 rule["hits"] = rule_stats.get(rule["id"], 0)
 
+        # Convert some data fields into a new format
+        for rule in vars["rules"]:
+            if "livetime" in rule:
+                livetime = rule["livetime"]
+                if type(livetime) != tuple:
+                    rule["livetime"] = ( livetime, ["open"] )
+
         return vars["rules"]
 
     except Exception, e:



More information about the checkmk-commits mailing list