Module: check_mk
Branch: master
Commit: 80706d0666ee89897b046acc17cc8222940fc61b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=80706d0666ee89…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Jan 20 09:25:47 2016 +0100
#2903 Added "Service Level" to event simulation
The service level of a simulated event can now be set in the Event Simulator.
---
.werks/2903 | 9 +++++++++
ChangeLog | 1 +
mkeventd/bin/mkeventd | 17 ++++++++++++++---
mkeventd/web/htdocs/mkeventd.py | 19 +++++++++++++++----
mkeventd/web/plugins/wato/mkeventd.py | 7 +++++++
5 files changed, 46 insertions(+), 7 deletions(-)
diff --git a/.werks/2903 b/.werks/2903
new file mode 100644
index 0000000..df1df49
--- /dev/null
+++ b/.werks/2903
@@ -0,0 +1,9 @@
+Title: Added "Service Level" to event simulation
+Level: 1
+Component: ec
+Compatible: compat
+Version: 1.2.7i4
+Date: 1453278286
+Class: feature
+
+The service level of a simulated event can now be set in the Event Simulator.
diff --git a/ChangeLog b/ChangeLog
index 373c413..0a036c3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -272,6 +272,7 @@
Event Console:
* 2733 Visibility of Event Console events more flexible now...
* 1306 mkeventd: The Recent event history can you be filtered by extended regexes
+ * 2903 Added "Service Level" to event simulation...
* 2719 FIX: Events Check: Links to EC were broken when using regular expressions as
application...
* 2757 FIX: Events Check: Fixed check finding too many events (host search was infix
search instead of full match)...
* 2795 FIX: mkeventd: send email action did not work if message text contains
umlauts...
diff --git a/mkeventd/bin/mkeventd b/mkeventd/bin/mkeventd
index 5e4bb05..088961c 100755
--- a/mkeventd/bin/mkeventd
+++ b/mkeventd/bin/mkeventd
@@ -2238,9 +2238,12 @@ class EventServer:
# Variant 6: syslog message without date / host:
# <5>SYSTEM_INFO: [WLAN-1] Triggering Background Scan
- #Varian 7: logwatch.ec event forwarding
+ # Variant 7: logwatch.ec event forwarding
# <78>@1341847712 Klapprechner /var/log/syslog: message....
+ # Variant 7a: Event simulation
+ # <%PRI%>@%TIMESTAMP%;%SL% %HOSTNAME% %syslogtag%: %msg%
+
# Variant 8: syslog message from sophos firewall
# <84>2015:03:25-12:02:06 gw pluto[7122]: listening for IKE messages
@@ -2263,8 +2266,16 @@ class EventServer:
event["priority"] = 5 # notice
# Variant 7
- if line[0] == '@' and line[11] == ' ':
- timestamp, event['host'], line = line.split(' ', 2)
+ if line[0] == '@' and line[11] in [ ' ', ';' ]:
+ if line[11] == ' ':
+ # Variant 7
+ timestamp, event['host'], line = line.split(' ', 2)
+ else:
+ # Variant 7a
+ details, event['host'], line = line.split(' ', 2)
+ timestamp, sl = details.split(';', 1)
+ event["sl"] = int(sl)
+
event['time'] = float(timestamp[1:])
event.update(self.parse_syslog_info(line))
diff --git a/mkeventd/web/htdocs/mkeventd.py b/mkeventd/web/htdocs/mkeventd.py
index a6a0e25..626c769 100644
--- a/mkeventd/web/htdocs/mkeventd.py
+++ b/mkeventd/web/htdocs/mkeventd.py
@@ -165,11 +165,11 @@ def daemon_running():
# we put hostname|ipaddress into the host name field. The EC
# recognizes this and unpacks the data correctly.
def send_event(event):
- # "<%PRI%>%TIMESTAMP% %HOSTNAME% %syslogtag% %msg%\n"
+ # "<%PRI%>@%TIMESTAMP%;%SL% %HOSTNAME% %syslogtag% %msg%\n"
prio = (event["facility"] << 3) + event["priority"]
- timestamp = time.strftime("%b %d %T", time.localtime())
- rfc = "<%d>%s %s|%s %s: %s\n" % (
- prio, timestamp, event["host"], event["ipaddress"],
event["application"], event["text"])
+ 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")
@@ -269,6 +269,17 @@ def event_rule_matches_non_inverted(rule, event):
if p < prio_from or p > prio_to:
return _("The syslog priority is not in the required range.")
+ if "match_sl" in rule:
+ sl_from, sl_to = rule["match_sl"]
+ if sl_from > sl_to:
+ sl_to, sl_from = sl_from, sl_to
+ p = event.get("sl")
+ if p == None:
+ return _("No service level is set in event")
+
+ if p < sl_from or p > sl_to:
+ return _("Wrong service level %d (need %d..%d)" % (p, sl_from,
sl_to))
+
if "match_timeperiod" in rule:
reason = check_timeperiod(rule["match_timeperiod"])
if reason:
diff --git a/mkeventd/web/plugins/wato/mkeventd.py
b/mkeventd/web/plugins/wato/mkeventd.py
index 1882696..491e62a 100644
--- a/mkeventd/web/plugins/wato/mkeventd.py
+++ b/mkeventd/web/plugins/wato/mkeventd.py
@@ -819,6 +819,11 @@ vs_mkeventd_event = Dictionary(
default_value = 1,
)
),
+ ("sl", DropdownChoice(
+ title = _("Service Level"),
+ choices = mkeventd.service_levels,
+ prefix_values = True,
+ )),
])
@@ -1115,6 +1120,7 @@ def show_event_simulator():
else:
return None
+
def event_simulation_action():
# Validation of input for rule simulation (no further action here)
if html.var("simulate") or html.var("_generate"):
@@ -1130,6 +1136,7 @@ def event_simulation_action():
rfc = mkeventd.send_event(event)
return None, "Test event generated and sent to Event
Console.<br><pre>%s</pre>" % rfc
+
def rule_pack_with_id(rule_packs, rule_pack_id):
for nr, entry in enumerate(rule_packs):
if entry["id"] == rule_pack_id: