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): ...@@ -64,7 +64,9 @@ def rfc822(date):
return email.utils.format_datetime(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() now = datetime.datetime.utcnow()
if interval < 60: if interval < 60:
interval = 60 interval = 60
...@@ -83,7 +85,7 @@ def filterWarningStatus(status_dict, interval, not_critical_url_list): ...@@ -83,7 +85,7 @@ def filterWarningStatus(status_dict, interval, not_critical_url_list):
if (expiration_date is None) or ( if (expiration_date is None) or (
(expiration_date is not None) (expiration_date is not None)
and ( and (
(60 * 60 * 24 * 14) (warning_period_duration)
< ( < (
parsedate_to_datetime(expiration_date) - now parsedate_to_datetime(expiration_date) - now
).total_seconds() ).total_seconds()
...@@ -154,7 +156,7 @@ def filterWarningStatus(status_dict, interval, not_critical_url_list): ...@@ -154,7 +156,7 @@ def filterWarningStatus(status_dict, interval, not_critical_url_list):
if ( if (
(not_after is not None) (not_after is not None)
and ( and (
(60 * 60 * 24 * 14) (warning_period_duration)
< (parsedate_to_datetime(not_after) - now).total_seconds() < (parsedate_to_datetime(not_after) - now).total_seconds()
) )
) or ( ) or (
...@@ -640,6 +642,7 @@ class WebBot: ...@@ -640,6 +642,7 @@ class WebBot:
status_dict, status_dict,
int(self.config.get("INTERVAL")), int(self.config.get("INTERVAL")),
self.calculateNotCriticalUrlList(), self.calculateNotCriticalUrlList(),
float(self.config["WARNING_PERIOD"]),
) )
if self.config["FORMAT"] == "json": if self.config["FORMAT"] == "json":
print(json.dumps(status_dict)) print(json.dumps(status_dict))
......
...@@ -37,7 +37,8 @@ from .bot import create_bot ...@@ -37,7 +37,8 @@ from .bot import create_bot
@click.option("--nameserver", "-n", help="The IP of the DNS server.") @click.option("--nameserver", "-n", help="The IP of the DNS server.")
@click.option("--url", "-u", help="The url to check.") @click.option("--url", "-u", help="The url to check.")
@click.option("--domain", "-d", help="The domain 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( @click.option(
"--configuration", "-f", help="The path of the configuration file." "--configuration", "-f", help="The path of the configuration file."
) )
...@@ -65,6 +66,7 @@ def runSurykatka( ...@@ -65,6 +66,7 @@ def runSurykatka(
url, url,
domain, domain,
timeout, timeout,
warning,
configuration, configuration,
reload, reload,
output, output,
...@@ -81,6 +83,8 @@ def runSurykatka( ...@@ -81,6 +83,8 @@ def runSurykatka(
mapping["URL"] = "" mapping["URL"] = ""
if timeout: if timeout:
mapping["TIMEOUT"] = timeout mapping["TIMEOUT"] = timeout
if warning:
mapping["WARNING_PERIOD"] = str(60 * 60 * 24 * float(warning))
if sqlite: if sqlite:
mapping["SQLITE"] = sqlite mapping["SQLITE"] = sqlite
if nameserver: if nameserver:
......
...@@ -56,6 +56,8 @@ def createConfiguration( ...@@ -56,6 +56,8 @@ def createConfiguration(
config[CONFIG_SECTION]["URL"] = "" config[CONFIG_SECTION]["URL"] = ""
if "FORMAT" not in config[CONFIG_SECTION]: if "FORMAT" not in config[CONFIG_SECTION]:
config[CONFIG_SECTION]["FORMAT"] = "json" 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]: if "TIMEOUT" not in config[CONFIG_SECTION]:
config[CONFIG_SECTION]["TIMEOUT"] = "1" config[CONFIG_SECTION]["TIMEOUT"] = "1"
if "ELAPSED_FAST" not in config[CONFIG_SECTION]: 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