Module: check_mk
Branch: master
Commit: c9a91d8ae3c38a329c0cc95b7a1fdd0058d8a092
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c9a91d8ae3c38a…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Oct 8 14:55:26 2012 +0200
Event Console: allow to reset rule hit counters
---
ChangeLog | 2 ++
mkeventd/bin/mkeventd | 22 ++++++++++++++++++++++
mkeventd/web/plugins/wato/mkeventd.py | 15 +++++++++++++++
3 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 9aa7cbc..e2babc9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,8 @@
Event Console:
* Moved source of Event Console into Check_MK project
+ * New button for resetting all rule hits counters
+ * When saving a rule then its hits counter is always reset
Multisite:
* Enable automation login with _username= and _secret=, while
diff --git a/mkeventd/bin/mkeventd b/mkeventd/bin/mkeventd
index 373c198..de491f5 100755
--- a/mkeventd/bin/mkeventd
+++ b/mkeventd/bin/mkeventd
@@ -1291,6 +1291,8 @@ class StatusServer:
self.handle_command_flush()
elif command == "SYNC":
self.handle_command_sync()
+ elif command == "RESETCOUNTERS":
+ self.handle_command_resetcounters(arguments)
elif command == "UPDATE":
self.handle_command_update(arguments)
elif command == "CHANGESTATE":
@@ -1351,6 +1353,16 @@ class StatusServer:
def handle_command_sync(self):
g_event_status.save_status()
+ def handle_command_resetcounters(self, arguments):
+ if arguments:
+ rule_id = arguments[0]
+ log("Resetting counters of rule " + rule_id)
+ else:
+ rule_id = None # Reset all rule counters
+ log("Resetting all rule counters")
+ g_event_status.reset_counters(rule_id)
+
+
def handle_command_action(self, arguments):
with lock_configuration:
event_id, user, action_id = arguments
@@ -1594,6 +1606,16 @@ class EventStatus():
elapsed = time.time() - now
log("Saved event state to %s in %.3fms." % (path, elapsed * 1000))
+ def reset_counters(self, rule_id):
+ if rule_id:
+ if rule_id in self._rule_stats:
+ del self._rule_stats[rule_id]
+ else:
+ self._rule_stats = {}
+ self.save_status()
+
+
+
def load_status(self):
path = g_state_dir + "/status"
if os.path.exists(path):
diff --git a/mkeventd/web/plugins/wato/mkeventd.py
b/mkeventd/web/plugins/wato/mkeventd.py
index 2c5bff9..84a5fc2 100644
--- a/mkeventd/web/plugins/wato/mkeventd.py
+++ b/mkeventd/web/plugins/wato/mkeventd.py
@@ -695,6 +695,8 @@ def mode_mkeventd_rules(phase):
mkeventd_changes_button()
if config.may("mkeventd.edit"):
html.context_button(_("New Rule"), make_link([("mode",
"mkeventd_edit_rule")]), "new")
+ html.context_button(_("Reset Counters"),
+ make_action_link([("mode", "mkeventd_rules"),
("_reset_counters", "1")]), "resetcounters")
return
rules = load_mkeventd_rules()
@@ -720,6 +722,17 @@ def mode_mkeventd_rules(phase):
else:
return
+ elif html.has_var("_reset_counters"):
+ c = wato_confirm(_("Confirm counter reset"),
+ _("Do you really want to reset all
<i>Hits</i> counters to zero?"))
+ if c:
+ mkeventd.query("COMMAND RESETCOUNTERS")
+ log_mkeventd("counter-reset", _("Resetted all rule hit
counters to zero"))
+ elif c == False:
+ return ""
+ else:
+ return
+
if html.check_transaction():
if html.has_var("_move"):
@@ -931,6 +944,8 @@ def mode_mkeventd_edit_rule(phase):
log_mkeventd("new-rule", _("Created new event corelation rule
with id %s" % rule["id"]))
else:
log_mkeventd("edit-rule", _("Modified event corelation rule
%s" % rule["id"]))
+ # Reset hit counters of this rule
+ mkeventd.query("COMMAND RESETCOUNTERS;" + rule["id"])
return "mkeventd_rules"