Module: check_mk
Branch: master
Commit: 0bbf930a23f16bf9e751ea52a3aa669b5a131267
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0bbf930a23f16b…
Author: Bastian Kuhn <bk(a)mathias-kettner.de>
Date: Thu Feb 27 13:47:54 2014 +0100
Step1: Using Regex for Hostnames
---
modules/check_mk.py | 17 +++++++++++++----
web/htdocs/wato.py | 7 +++++--
2 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 12a5a98..22b2d31 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -1821,7 +1821,8 @@ def in_boolean_serviceconf_list(hostname, service_description, ruleset):
# Entries in list are (tagged) hostnames that must equal the
# (untagged) hostname. Expressions beginning with ! are negated: if
-# they match, the item is excluded from the list. Also the three
+# they match, the item is excluded from the list. Expressions beginning
+# withy ~ are treated as Regular Expression. Also the three
# special tags '@all', '@clusters', '@physical' are allowed.
def in_extraconf_hostlist(hostlist, hostname):
@@ -1832,6 +1833,8 @@ def in_extraconf_hostlist(hostlist, hostname):
for hostentry in hostlist:
if len(hostentry) == 0:
raise MKGeneralException('Empty hostname in host list %r' % hostlist)
+ negate = False
+ regex = False
if hostentry[0] == '@':
if hostentry == '@all':
return True
@@ -1845,11 +1848,17 @@ def in_extraconf_hostlist(hostlist, hostname):
elif hostentry[0] == '!':
hostentry = hostentry[1:]
negate = True
- else:
- negate = False
+ # Allow regex with prefix '~'
+ elif hostentry[0] == '~':
+ hostentry = hostentry[1:]
+ regex = True
- if hostname == strip_tags(hostentry):
+ hostentry = strip_tags(hostentry)
+ if not regex and hostname == hostentry:
return not negate
+ # Handle Regex
+ elif re.match(hostentry, hostname):
+ return True
return False
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 372ef61..b65ce1e 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -12725,12 +12725,15 @@ def rule_matches_host_and_item(rulespec, tag_specs, host_list, item_list,
rule_folder, host_folder, hostname, item):
reasons = []
host = host_folder[".hosts"][hostname]
- if not (
+ hostname_match = False
+
+ if not (
(hostname in host_list)
or
(("!"+hostname) not in host_list
and len(host_list) > 0
- and host_list[-1] == ALL_HOSTS[0])):
+ and host_list[-1] == ALL_HOSTS[0])
+ or len([ x for x in host_list if x.startswith('~') and re.match(x[1:], hostname) ]) > 0):
reasons.append(_("The host name does not match."))
tags_match = True
Module: check_mk
Branch: master
Commit: 81ce173177cdde92999855ae955f1e0cda242404
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=81ce173177cdde…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Wed Feb 26 17:34:35 2014 +0100
beautified werk 561
---
.werks/561 | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/.werks/561 b/.werks/561
index d220b8d..2ad4445 100644
--- a/.werks/561
+++ b/.werks/561
@@ -21,7 +21,7 @@ C+:
s: mem h: localhost
C-:
-This will search for all services containing <tt>mem</tt> on the localhost.
+This will search for all services containing <tt>mem</tt> on the <tt>localhost</tt>.
Furthermore you can combine these filters.
C+:
@@ -36,8 +36,11 @@ The search algorhytm is as follow:
<li>Different filters are combined with <tt>AND</tt></li>
</ul>
-The query <tt>h: localhost s: mem s: cpu h:switch-intern</tt> actually results in the
-following livestatus query:
+The query
+C+:
+h: localhost s: mem s: cpu h:switch-intern
+C-:
+actually results in the following livestatus query:
C+:
GET services
@@ -54,4 +57,4 @@ Limit: 80
C-:
You can also add the <tt>hg:</tt> and <tt>sg:</tt> filters to the query.<br>
-<b>Note:</b> Right now, this multisearch filter only works if at least one of the filters is a service (<tt>s:</tt>).
+<b>Note:</b> Right now, this multisearch filter only works if at least one of the filters is a service ( <tt>s:</tt> ).