Module: check_mk
Branch: master
Commit: 60907946d4777f83bbd8848279d978eb337d2caa
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=60907946d4777f…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Jan 12 18:07:06 2017 +0100
Event console: simulating events now supports distributed EC
Change-Id: I6fa77cf4e204c2f4694080111c11da0427d9b2a7
---
bin/mkeventd | 21 +++++++++++++++++++--
web/htdocs/mkeventd.py | 44 +++++++++++++++-----------------------------
web/htdocs/watolib.py | 33 +++++++++++++++++++--------------
web/plugins/wato/mkeventd.py | 4 ++++
4 files changed, 57 insertions(+), 45 deletions(-)
diff --git a/bin/mkeventd b/bin/mkeventd
index be4acda..9c05f79 100755
--- a/bin/mkeventd
+++ b/bin/mkeventd
@@ -3048,7 +3048,7 @@ class StatusServer:
"(allowed are python, json and plain)" % output_format)
- # locked with lock_eventstatus
+ # All commands are already locked with lock_eventstatus
def handle_command_request(self, commandline):
log("Executing command: %s" % commandline)
parts = commandline.split(";")
@@ -3072,6 +3072,8 @@ class StatusServer:
self.handle_command_resetcounters(arguments)
elif command == "UPDATE":
self.handle_command_update(arguments)
+ elif command == "CREATE":
+ self.handle_command_create(arguments)
elif command == "CHANGESTATE":
self.handle_command_changestate(arguments)
elif command == "ACTION":
@@ -3081,13 +3083,14 @@ class StatusServer:
else:
raise MKClientError("Unknown command %s" % command)
- # locked with lock_eventstatus
+
def handle_command_delete(self, arguments):
if len(arguments) != 2:
raise MKClientError("Wrong number of arguments for DELETE")
event_id, user = arguments
g_event_status.delete_event(int(event_id), user)
+
def handle_command_update(self, arguments):
event_id, user, acknowledged, comment, contact = arguments
event = g_event_status.event(int(event_id))
@@ -3102,6 +3105,17 @@ class StatusServer:
event["phase"] = int(acknowledged) and "ack" or
"open"
log_event_history(event, "UPDATE", user)
+
+ def handle_command_create(self, arguments):
+ # Would rather use g_event_server.process_raw_line(), but we are already
+ # holding lock_eventstatus and it's sub functions are setting
+ # lock_eventstatus too. The lock can not be allocated twice.
+ # TODO: Change the lock type in future?
+ # process_raw_lines("%s" % ";".join(arguments))
+ with file(g_pipe_path, "w") as pipe:
+ pipe.write("%s\n" % ";".join(arguments))
+
+
def handle_command_changestate(self, arguments):
event_id, user, newstate = arguments
event = g_event_status.event(int(event_id))
@@ -3110,6 +3124,7 @@ class StatusServer:
event["state"] = int(newstate)
log_event_history(event, "CHANGESTATE", user)
+
def handle_command_reload(self):
with lock_configuration:
load_configuration()
@@ -3118,11 +3133,13 @@ class StatusServer:
g_status_server.reload_configuration()
log("Reloaded configuration.")
+
def handle_command_reopenlog(self):
log("Closing this logfile")
open_logfile()
log("Opened new logfile")
+
# Erase our current state and history!
def handle_command_flush(self):
flush_event_history()
diff --git a/web/htdocs/mkeventd.py b/web/htdocs/mkeventd.py
index e1cdebe..9d3b9d7 100644
--- a/web/htdocs/mkeventd.py
+++ b/web/htdocs/mkeventd.py
@@ -36,25 +36,13 @@ import cmk.paths
# Please sync these paths with htdocs/mkeventd.py
mib_dirs = [ ('/usr/share/snmp/mibs', _('System MIBs')) ]
-try:
- socket_path = cmk.paths.omd_root + "/tmp/run/mkeventd/status"
- pipe_path = cmk.paths.omd_root + "/tmp/run/mkeventd/events"
+socket_path = cmk.paths.omd_root + "/tmp/run/mkeventd/status"
+compiled_mibs_dir = cmk.paths.omd_root + "/local/share/check_mk/compiled_mibs"
- compiled_mibs_dir = cmk.paths.omd_root +
"/local/share/check_mk/compiled_mibs"
-
- # Please sync these paths with htdocs/mkeventd.py
- mib_upload_dir = cmk.paths.omd_root + "/local/share/snmp/mibs"
- mib_dirs.insert(0, (cmk.paths.omd_root + "/share/snmp/mibs", _('MIBs
shipped with Check_MK')))
- mib_dirs.insert(0, (mib_upload_dir, _('Custom MIBs')))
-except:
- run_dir = cmk.paths.livestatus_unix_socket.rsplit("/",1)[0]
- socket_path = run_dir + "/mkeventd/status"
- pipe_path = run_dir + "/mkeventd/events"
-
- # Please sync these paths with htdocs/mkeventd.py
- mib_upload_dir = cmk.paths.var_dir + "/mkeventd/mibs"
- compiled_mibs_dir = "/var/lib/mkeventd/compiled_mibs"
- mib_dirs.insert(0, (mib_upload_dir, _('Custom MIBs')))
+# Please sync these paths with htdocs/mkeventd.py
+mib_upload_dir = cmk.paths.omd_root + "/local/share/snmp/mibs"
+mib_dirs.insert(0, (cmk.paths.omd_root + "/share/snmp/mibs", _('MIBs
shipped with Check_MK')))
+mib_dirs.insert(0, (mib_upload_dir, _('Custom MIBs')))
syslog_priorities = [
@@ -171,16 +159,16 @@ def daemon_running():
def send_event(event):
# "<%PRI%>@%TIMESTAMP%;%SL% %HOSTNAME% %syslogtag% %msg%\n"
prio = (event["facility"] << 3) + event["priority"]
- rfc = "<%d>@%s;%d %s|%s %s: %s\n" % (
- prio, int(time.time()), event["sl"], event["host"],
- event["ipaddress"], event["application"],
event["text"])
- if type(rfc) == unicode:
- rfc = rfc.encode("utf-8")
- pipe = file(pipe_path, "w")
- pipe.write(rfc + "\n")
- pipe.close()
- return rfc
+ rfc = [
+ "<%d>@%d" % (prio, int(time.time())),
+ "%d %s|%s %s: %s\n" % (event["sl"], event["host"],
+ event["ipaddress"], event["application"],
event["text"]),
+ ]
+
+ execute_command("CREATE", map(make_utf8, rfc),
site=event["site"])
+
+ return ";".join(rfc)
def get_local_ec_status():
@@ -237,8 +225,6 @@ def execute_command(name, args=None, site=None):
sites.live().command(query, site)
-
-
def get_total_stats():
stats_keys = [
"status_average_message_rate",
diff --git a/web/htdocs/watolib.py b/web/htdocs/watolib.py
index 4425107..d7a1d7c 100644
--- a/web/htdocs/watolib.py
+++ b/web/htdocs/watolib.py
@@ -3545,12 +3545,26 @@ def get_login_sites():
# Returns a list of site ids which gets the Event Console configuration replicated
def get_event_console_sync_sites():
- sites = []
+ return [ s[0] for s in get_event_console_site_choices() ]
+
+
+def get_event_console_site_choices():
+ return site_choices(filter_func=lambda site_id, site: config.site_is_local(site_id)
or site.get("replicate_ec"))
+
+
+def site_choices(filter_func=None):
+ choices = []
for site_id, site in config.sites.items():
- if config.site_is_local(site_id) or site.get("replicate_ec"):
- sites.append(site_id)
- return sites
+ if filter_func and not filter_func(site_id, site):
+ continue
+
+ title = site_id
+ if site.get("alias"):
+ title += " - " + site["alias"]
+
+ choices.append((site_id, title))
+ return sorted(choices, key=lambda s: s[1])
@@ -3563,20 +3577,11 @@ class SiteAttribute(ValueSpecAttribute):
def __init__(self):
# Default is is the local one, if one exists or
# no one if there is no local site
- choices = []
- for id, site in config.sites.items():
- title = id
- if site.get("alias"):
- title += " - " + site["alias"]
- choices.append((id, title))
-
- choices.sort(cmp=lambda a,b: cmp(a[1], b[1]))
-
ValueSpecAttribute.__init__(self, "site", DropdownChoice(
title=_("Monitored on site"),
help=_("Specify the site that should monitor this host."),
default_value = default_site(),
- choices = choices,
+ choices = site_choices,
invalid_choice = "complain",
invalid_choice_title = _("Unknown site (%s)"),
invalid_choice_error = _("The configured site is not known to this site.
In case you "
diff --git a/web/plugins/wato/mkeventd.py b/web/plugins/wato/mkeventd.py
index e3e7f30..02b8b96 100644
--- a/web/plugins/wato/mkeventd.py
+++ b/web/plugins/wato/mkeventd.py
@@ -886,6 +886,10 @@ vs_mkeventd_event = Dictionary(
choices = mkeventd.service_levels,
prefix_values = True,
)),
+ ("site", DropdownChoice(
+ title = _("Simulate for site"),
+ choices = get_event_console_site_choices,
+ )),
])