Module: check_mk
Branch: master
Commit: 84b51434c7ed485a725f34fbb34c352ed43cd236
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=84b51434c7ed48…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Apr 25 10:54:04 2017 +0200
4600 Network scan: Can now be configured to be executed only in a given time frame
Instead of being scheduled over the whole day you can now configure the network scan
of a folder to be executed in a time frame.
Change-Id: I53779a451964b80d69a1b61eeba24868a8063588
---
.werks/4600 | 11 ++++++++++
web/htdocs/watolib.py | 40 ++++++++++++++++++++++++++++------
web/plugins/wato/builtin_attributes.py | 5 +++++
3 files changed, 49 insertions(+), 7 deletions(-)
diff --git a/.werks/4600 b/.werks/4600
new file mode 100644
index 0000000..837c7fd
--- /dev/null
+++ b/.werks/4600
@@ -0,0 +1,11 @@
+Title: Network scan: Can now be configured to be executed only in a given time frame
+Level: 1
+Component: wato
+Compatible: compat
+Edition: cre
+Version: 1.5.0i1
+Date: 1493110366
+Class: feature
+
+Instead of being scheduled over the whole day you can now configure the network scan
+of a folder to be executed in a time frame.
diff --git a/web/htdocs/watolib.py b/web/htdocs/watolib.py
index 36ac0b0..1073b42 100644
--- a/web/htdocs/watolib.py
+++ b/web/htdocs/watolib.py
@@ -1607,13 +1607,39 @@ class CREFolder(BaseFolder):
# None: No network scan is enabled.
# timestamp: Next planned run according to config.
def next_network_scan_at(self):
- if "network_scan" in self._attributes:
- interval =
self._attributes["network_scan"]["scan_interval"]
- last_end = self._attributes.get("network_scan_result",
{}).get("end", None)
- if last_end == None:
- return time.time()
- else:
- return last_end + interval
+ if "network_scan" not in self._attributes:
+ return
+
+ interval = self._attributes["network_scan"]["scan_interval"]
+ last_end = self._attributes.get("network_scan_result",
{}).get("end", None)
+ if last_end == None:
+ next_time = time.time()
+ else:
+ next_time = last_end + interval
+
+ time_allowed =
self._attributes["network_scan"].get("time_allowed")
+ if time_allowed == None:
+ return next_time # No time frame limit
+
+ # First transform the time given by the user to UTC time
+ brokentime = list(time.localtime(next_time))
+ brokentime[3], brokentime[4] = time_allowed[0]
+ start_time = time.mktime(brokentime)
+
+ brokentime[3], brokentime[4] = time_allowed[1]
+ end_time = time.mktime(brokentime)
+
+ # In case the next time is earlier than the allowed time frame at a day set
+ # the time to the time frame start.
+ # In case the next time is in the time frame leave it at it's value.
+ # In case the next time is later then advance one day to the start of the
+ # time frame.
+ if next_time < start_time:
+ next_time = start_time
+ elif next_time > end_time:
+ next_time = start_time + 86400
+
+ return next_time
# .-----------------------------------------------------------------------.
diff --git a/web/plugins/wato/builtin_attributes.py
b/web/plugins/wato/builtin_attributes.py
index f18638a..34a014e 100644
--- a/web/plugins/wato/builtin_attributes.py
+++ b/web/plugins/wato/builtin_attributes.py
@@ -274,6 +274,11 @@ class NetworkScanAttribute(ValueSpecAttribute):
default_value = 60*60*24,
minvalue = 3600, # 1 hour
)),
+ ("time_allowed", TimeofdayRange(
+ title = _("Time allowed"),
+ help = _("Limit the execution of the scan to this time
range."),
+ allow_empty=False,
+ )),
("max_parallel_pings", Integer(
title = _("Parallel pings to send"),
help = _("Set the maximum number of concurrent pings sent to
target IP "