Commit e5e0512b authored by Romain Courteaud's avatar Romain Courteaud

Add warning section to report various wrong configuration

parent bb6fb890
......@@ -67,7 +67,11 @@ def rfc822(date):
def filterWarningStatus(
status_dict, interval, not_critical_url_list, warning_period_duration
status_dict,
interval,
not_critical_url_list,
warning_period_duration,
keep_warning=True,
):
now = datetime.datetime.utcnow()
if interval < 60:
......@@ -82,6 +86,9 @@ def filterWarningStatus(
if not status_dict["bot_status"]:
del status_dict["bot_status"]
if (not status_dict["warning"]) or (not keep_warning):
del status_dict["warning"]
for i in range(len(status_dict["whois"]) - 1, -1, -1):
expiration_date = status_dict["whois"][i]["expiration_date"]
if (expiration_date is None) or (
......@@ -484,6 +491,7 @@ class WebBot:
)
server_ip_dict = {}
result_dict["dns_query"] = []
result_dict["warning"] = []
for dns_change in query.dicts().iterator():
if dns_change["domain"] not in checked_domain_dict:
......@@ -713,22 +721,31 @@ class WebBot:
def run(self, mode):
status_dict = None
if mode not in ["crawl", "pack", "status", "warning"]:
if mode not in ["crawl", "pack", "status", "warning", "error"]:
raise NotImplementedError("Unexpected mode: %s" % mode)
if self.config["SQLITE"] == ":memory:":
# Crawl/report are mandatory when using memory
if mode == "warning":
mode = "wallwarning"
elif mode == "error":
mode = "wallerror"
else:
mode = "all"
self.initDB()
try:
if mode in ["crawl", "wallwarning", "all"]:
if mode in ["crawl", "wallwarning", "wallerror", "all"]:
self.crawl()
if mode in ["status", "all", "wallwarning", "warning"]:
if mode in [
"status",
"all",
"wallwarning",
"warning",
"wallerror",
"error",
]:
status_dict = self.status()
if mode == "pack":
self.pack()
......@@ -739,12 +756,13 @@ class WebBot:
self.closeDB()
if status_dict is not None:
if mode in ("wallwarning", "warning"):
if mode in ("wallwarning", "warning", "wallerror", "error"):
filterWarningStatus(
status_dict,
int(self.config.get("INTERVAL")),
self.calculateNotCriticalUrlList(),
float(self.config["WARNING_PERIOD"]),
keep_warning=("warning" in mode),
)
if self.config["FORMAT"] == "json":
status_output = json.dumps(status_dict)
......
......@@ -29,7 +29,7 @@ from .bot import create_bot
help="The bot operation mode to run.",
show_default=True,
default="status",
type=click.Choice(["crawl", "pack", "status", "warning"]),
type=click.Choice(["crawl", "pack", "status", "warning", "error"]),
)
@click.option(
"--sqlite", "-s", help="The path of the sqlite DB. (default: :memory:)"
......
......@@ -974,6 +974,7 @@ class SurykatkaBotStatusTestCase(unittest.TestCase):
"tcp_server": [],
"ssl_certificate": [],
"http_query": [],
"warning": [],
}
def test_status_sqliteMaxVariableNumber(self):
......@@ -1009,6 +1010,7 @@ class SurykatkaBotStatusTestCase(unittest.TestCase):
assert len(result["tcp_server"]) == 0
assert len(result["ssl_certificate"]) == 0
assert len(result["http_query"]) == 0
assert len(result["warning"]) == 0
# +1 for example.org
assert len(result["missing_data"]) == more_than_sqlite_max * 2 + 1
......
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