Module: check_mk
Branch: master
Commit: 9ef0193af36dd1e0e0b8a6a5fc5e985b995851f6
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9ef0193af36dd1…
Author: Konstantin Büttner <kb(a)mathias-kettner.de>
Date: Tue Jul 10 13:09:37 2018 +0200
6226 Allow to match against the monitoring site in rules
This allows to apply rules only on specific sites. This is required
to make the feature expect regular messages work in a distibuted
environment with config replication.
Example: If you have three centrally configured event consoles,
and you want a device to regularily report to one of them, you
previously had no way to configure that only the one site reports
missing messages. Instead, all sites the device doesn't send messages
to would repeatedly open events. This limitation can now be
worked around by specifying to which site expect rules should apply.
Change-Id: Ie9557ee96d3e62169823593c3f41a70f03a853c9
---
.werks/6226 | 22 ++++++++++++++++++++++
cmk/ec/main.py | 8 ++++++++
web/plugins/wato/mkeventd.py | 16 +++++++++++++---
3 files changed, 43 insertions(+), 3 deletions(-)
diff --git a/.werks/6226 b/.werks/6226
new file mode 100644
index 0000000..5bc2da3
--- /dev/null
+++ b/.werks/6226
@@ -0,0 +1,22 @@
+Title: Allow to match against the monitoring site in rules
+Level: 2
+Component: ec
+Class: feature
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1531314180
+
+This allows to apply rules only on specific sites. Restricting
+rules to sites can yield performance benefits in environments with
+many sites. Beyond that, this is required to make the feature expect
+regular messages work in a distributed environment with
+config replication.
+
+Example: If you have three centrally configured event consoles,
+and you want a device to regularily report to one of them, you
+previously had no way to configure that only the one site reports
+missing messages. Instead, all sites the device doesn't send messages
+to would repeatedly open events. This limitation can now be
+worked around by specifying to which site expect rules should apply.
diff --git a/cmk/ec/main.py b/cmk/ec/main.py
index 01a34ca..93a0386 100644
--- a/cmk/ec/main.py
+++ b/cmk/ec/main.py
@@ -1199,6 +1199,10 @@ class EventServer(ECServerThread):
# in that case.
for rule in self._rules:
if "expect" in rule:
+
+ if not self.event_rule_matches_site(rule, event=None):
+ continue
+
# Interval is either a number of seconds, or pair of a number of seconds
# (e.g. 86400, meaning one day) and a timezone offset relative to UTC in
hours.
interval = rule["expect"]["interval"]
@@ -1659,6 +1663,7 @@ class EventServer(ECServerThread):
def event_rule_matches_generic(self, rule, event):
generic_match_functions = [
+ self.event_rule_matches_site,
self.event_rule_matches_host,
self.event_rule_matches_ip,
self.event_rule_matches_facility,
@@ -1671,6 +1676,9 @@ class EventServer(ECServerThread):
return False
return True
+ def event_rule_matches_site(self, rule, event):
+ return "match_site" not in rule or cmk.omd_site() in
rule["match_site"]
+
def event_rule_matches_host(self, rule, event):
if match(rule.get("match_host"), event["host"],
complete=True) is False:
if self._config["debug_rules"]:
diff --git a/web/plugins/wato/mkeventd.py b/web/plugins/wato/mkeventd.py
index 8b5b2be..9633c9c 100644
--- a/web/plugins/wato/mkeventd.py
+++ b/web/plugins/wato/mkeventd.py
@@ -576,7 +576,10 @@ def vs_mkeventd_rule(customer=None):
"The options <i>week</i>, <i>two
days</i> and <i>day</i> refer to "
"periodic intervals aligned at 00:00:00 on the 1st of January
1970. "
"You can specify a relative offset in hours in order to
re-align this "
- "to any other point of time."),
+ "to any other point of time. In a distributed environment,
make "
+ "sure to specify which site should expect the messages in the
match "
+ "criteria above, else all sites with config replication will
warn if "
+ "messages fail to arrive."),
optional_keys = False,
columns = 2,
elements = [
@@ -704,6 +707,13 @@ def vs_mkeventd_rule(customer=None):
case_sensitive = False,
)
),
+ ( "match_site",
+ DualListChoice(
+ title = _("Match site"),
+ help = _("Apply this rule only on the following sites"),
+ choices = config.get_event_console_site_choices(),
+ )
+ ),
( "match_host",
RegExpUnicode(
title = _("Match host"),
@@ -903,12 +913,12 @@ def vs_mkeventd_rule(customer=None):
title = _("Rule Properties"),
elements = elements,
optional_keys = [ "delay", "livetime", "count",
"expect", "match_priority", "match_priority",
- "match_facility", "match_sl",
"match_host", "match_ipaddress", "match_application",
"match_timeperiod",
+ "match_facility", "match_sl",
"match_host", "match_site", "match_ipaddress",
"match_application", "match_timeperiod",
"set_text", "set_host",
"set_application", "set_comment",
"set_contact", "cancel_priority",
"cancel_application", "match_ok", "contact_groups", ],
headers = [
( _("Rule Properties"), [ "id", "description",
"comment", "docu_url", "disabled", "customer" ]
),
- ( _("Matching Criteria"), [ "match",
"match_host", "match_ipaddress", "match_application",
"match_priority", "match_facility",
+ ( _("Matching Criteria"), [ "match",
"match_site", "match_host", "match_ipaddress",
"match_application", "match_priority", "match_facility",
"match_sl", "match_ok",
"cancel_priority", "cancel_application", "match_timeperiod",
"invert_matching" ]),
( _("Outcome & Action"), [ "state", "sl",
"contact_groups", "actions", "actions_in_downtime",
"cancel_actions",
"cancel_action_phases", "drop", "autodelete",
"event_limit" ]),