Commit b498c212 authored by Romain Courteaud's avatar Romain Courteaud

Allow to configure the warning period

parent fafd25bd
......@@ -64,7 +64,9 @@ def rfc822(date):
return email.utils.format_datetime(date)
def filterWarningStatus(status_dict, interval, not_critical_url_list):
def filterWarningStatus(
status_dict, interval, not_critical_url_list, warning_period_duration
):
now = datetime.datetime.utcnow()
if interval < 60:
interval = 60
......@@ -83,7 +85,7 @@ def filterWarningStatus(status_dict, interval, not_critical_url_list):
if (expiration_date is None) or (
(expiration_date is not None)
and (
(60 * 60 * 24 * 14)
(warning_period_duration)
< (
parsedate_to_datetime(expiration_date) - now
).total_seconds()
......@@ -154,7 +156,7 @@ def filterWarningStatus(status_dict, interval, not_critical_url_list):
if (
(not_after is not None)
and (
(60 * 60 * 24 * 14)
(warning_period_duration)
< (parsedate_to_datetime(not_after) - now).total_seconds()
)
) or (
......@@ -640,6 +642,7 @@ class WebBot:
status_dict,
int(self.config.get("INTERVAL")),
self.calculateNotCriticalUrlList(),
float(self.config["WARNING_PERIOD"]),
)
if self.config["FORMAT"] == "json":
print(json.dumps(status_dict))
......
......@@ -37,7 +37,8 @@ from .bot import create_bot
@click.option("--nameserver", "-n", help="The IP of the DNS server.")
@click.option("--url", "-u", help="The url to check.")
@click.option("--domain", "-d", help="The domain to check.")
@click.option("--timeout", "-t", help="The timeout value.")
@click.option("--timeout", "-t", help="The timeout value (in second).")
@click.option("--warning", "-w", help="The warning duration value (in days).")
@click.option(
"--configuration", "-f", help="The path of the configuration file."
)
......@@ -65,6 +66,7 @@ def runSurykatka(
url,
domain,
timeout,
warning,
configuration,
reload,
output,
......@@ -81,6 +83,8 @@ def runSurykatka(
mapping["URL"] = ""
if timeout:
mapping["TIMEOUT"] = timeout
if warning:
mapping["WARNING_PERIOD"] = str(60 * 60 * 24 * float(warning))
if sqlite:
mapping["SQLITE"] = sqlite
if nameserver:
......
......@@ -56,6 +56,8 @@ def createConfiguration(
config[CONFIG_SECTION]["URL"] = ""
if "FORMAT" not in config[CONFIG_SECTION]:
config[CONFIG_SECTION]["FORMAT"] = "json"
if "WARNING_PERIOD" not in config[CONFIG_SECTION]:
config[CONFIG_SECTION]["WARNING_PERIOD"] = str(60 * 60 * 24 * 7)
if "TIMEOUT" not in config[CONFIG_SECTION]:
config[CONFIG_SECTION]["TIMEOUT"] = "1"
if "ELAPSED_FAST" not in config[CONFIG_SECTION]:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment