[checkmk-commits] Check_MK Git: check_mk: Event Console: New button for generating test events directly via WATO

git version control git at mathias-kettner.de
Wed Nov 14 16:15:28 CET 2012


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

Author: Mathias Kettner <mk at mathias-kettner.de>
Date:   Wed Nov 14 11:26:35 2012 +0100

Event Console: New button for generating test events directly via WATO

---

 ChangeLog                             |    1 +
 mkeventd/web/htdocs/mkeventd.py       |   27 ++++++++++++++++++++++++---
 mkeventd/web/plugins/wato/mkeventd.py |   14 ++++++++++++--
 3 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 64365cc..508f152 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -19,6 +19,7 @@
     * Max. number of queued connections on status sockets is configurable now
     * check_mkevents: new option -a for ignoring acknowledged events
     * New sub-permissions for changing comment and contact while updating an event
+    * New button for generating test events directly via WATO
 
     Multisite:
     * Enable automation login with _username= and _secret=, while
diff --git a/mkeventd/web/htdocs/mkeventd.py b/mkeventd/web/htdocs/mkeventd.py
index a5c165b..934ade6 100644
--- a/mkeventd/web/htdocs/mkeventd.py
+++ b/mkeventd/web/htdocs/mkeventd.py
@@ -1,9 +1,19 @@
 #!/usr/bin/python
 # encoding: utf-8
 
-import socket, config, defaults, re
+import socket, config, defaults, re, time
 from lib import *
 
+# TODO: make this configurable and thus work for non OMD-users as
+# well.
+try:
+    socket_path = defaults.omd_root + "/tmp/run/mkeventd/status"
+    pipe_path = defaults.omd_root + "/tmp/run/mkeventd/events"
+except:
+    run_dir = defaults.livestatus_unix_socket.rsplit("/",1)[0]
+    socket_path = run_dir + "/mkeventd/status"
+    pipe_path = run_dir + "/mkeventd/events"
+
 syslog_priorities = [
     (0, "emerg" ),
     (1, "alert" ),
@@ -98,7 +108,18 @@ def eventd_configuration():
     
 
 def daemon_running():
-    return os.path.exists(defaults.omd_root + "/tmp/run/mkeventd/status")
+    return os.path.exists(socket_path)
+
+
+def send_event(event):
+    # "<%PRI%>%TIMESTAMP% %HOSTNAME% %syslogtag% %msg%\n"
+    prio = (event["facility"] << 3) + event["priority"]
+    timestamp = time.strftime("%b %d %T", time.localtime())
+    rfc = "<%d>%s %s %s: %s\n" % (
+        prio, timestamp, event["host"], event["application"], event["text"])
+    pipe = file(pipe_path, "w")
+    pipe.write(rfc + "\n")
+    return rfc
 
 def query(query):
     try:
@@ -110,7 +131,7 @@ def query(query):
 
         sock.settimeout(timeout)
         # TODO: Pfad nicht auf OMD hart kodieren
-        sock.connect(defaults.omd_root + "/tmp/run/mkeventd/status")
+        sock.connect(socket_path)
         sock.send(query)
 
         response_text = ""
diff --git a/mkeventd/web/plugins/wato/mkeventd.py b/mkeventd/web/plugins/wato/mkeventd.py
index 6395413..93fef1f 100644
--- a/mkeventd/web/plugins/wato/mkeventd.py
+++ b/mkeventd/web/plugins/wato/mkeventd.py
@@ -712,10 +712,19 @@ def mode_mkeventd_rules(phase):
 
     if phase == "action":
         # Validation of input for rule simulation (no further action here)
-        if html.var("simulate"):
+        if html.var("simulate") or html.var("_generate"):
             event = vs_mkeventd_event.from_html_vars("event")
             vs_mkeventd_event.validate_value(event, "event")
 
+        if html.has_var("_generate") and html.check_transaction():
+            if not event.get("application"):
+                raise MKUserError("event_p_application", _("Please specify an application name"))
+            if not event.get("host"):
+                raise MKUserError("event_p_host", _("Please specify a host name"))
+            rfc = mkeventd.send_event(event)
+            return None, "Test event generated and sent to Event Console.<br><pre>%s</pre>" % rfc
+
+
         if html.has_var("_delete"):
             nr = int(html.var("_delete"))
             rule = rules[nr]
@@ -764,7 +773,8 @@ def mode_mkeventd_rules(phase):
     vs_mkeventd_event.render_input("event", event)
     forms.end()
     html.hidden_fields()
-    html.button("simulate", _("Try out!"))
+    html.button("simulate", _("Try out"))
+    html.button("_generate", _("Generate Event!"))
     html.end_form()
     html.write("<br>")
 



More information about the checkmk-commits mailing list