Module: check_mk
Branch: master
Commit: 9958411596970016e79b98f69866c0632a1f7c14
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=99584115969700…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Mar 31 17:11:01 2016 +0200
3354 FIX Added missing option to exclude IP addresses by regex
---
.werks/3354 | 10 ++++++++++
ChangeLog | 1 +
web/htdocs/wato.py | 24 ++++++++++++++++++++++++
web/plugins/wato/builtin_attributes.py | 6 ++++++
4 files changed, 41 insertions(+)
diff --git a/.werks/3354 b/.werks/3354
new file mode 100644
index 0000000..cca92fe
--- /dev/null
+++ b/.werks/3354
@@ -0,0 +1,10 @@
+Title: Added missing option to exclude IP addresses by regex
+Level: 1
+Component: wato
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.9i1
+Date: 1459437039
+
+
diff --git a/ChangeLog b/ChangeLog
index 45b87ba..ecdcba4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -192,6 +192,7 @@
* 3351 FIX: Network scan: Fixed number in hosts not being updated during network
scan
* 3352 FIX: Network scan: Added hostname translation to translate detected DNS names
of scanned hosts
* 3353 FIX: Displaying disabled/offline host state in WATO host list now
+ * 3354 FIX: Added missing option to exclude IP addresses by regex
Notifications:
* 3263 Notifications: allow users to restrict by their contact groups...
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index ebc075a..1c443e5 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -15234,6 +15234,9 @@ def ip_addresses_to_scan(folder):
# FIXME/TODO: Shouldn't this filtering be done on the central site?
to_scan.difference_update(known_ip_addresses())
+ # And now apply the IP regex patterns to exclude even more addresses
+ to_scan.difference_update(excludes_by_regexes(to_scan, exclude_specs))
+
return to_scan
@@ -15263,6 +15266,27 @@ def ip_addresses_of_ranges(ip_ranges):
return addresses
+def excludes_by_regexes(addresses, exclude_specs):
+ patterns = []
+ for ty, spec in exclude_specs:
+ if ty == "ip_regex_list":
+ for p in spec:
+ patterns.append(re.compile(p))
+
+ if not patterns:
+ return addresses
+
+ excludes = []
+ for address in addresses:
+ for p in patterns:
+ if p.match(address):
+ excludes.append(address)
+ break # one match is enough, exclude this.
+
+ return excludes
+
+
+
FULL_IPV4 = (2 ** 32) - 1
diff --git a/web/plugins/wato/builtin_attributes.py
b/web/plugins/wato/builtin_attributes.py
index b6d9f87..c838488 100644
--- a/web/plugins/wato/builtin_attributes.py
+++ b/web/plugins/wato/builtin_attributes.py
@@ -226,6 +226,12 @@ class NetworkScanAttribute(ValueSpecAttribute):
valuespec = IPv4Address(),
orientation = "horizontal",
)),
+ ("ip_regex_list", _("List of patterns to exclude"),
ListOfStrings(
+ valuespec = RegExp(),
+ orientation = "horizontal",
+ help = _("A list of regular expressions which are matched
against the found "
+ "IP addresses to exclude them. The matched addresses
are excluded."),
+ )),
]
)