Commit fe0adc9f authored by Romain Courteaud's avatar Romain Courteaud

Status: report missing expected data

parent 2eaeb1f3
......@@ -33,6 +33,7 @@ import json
import email.utils
from collections import OrderedDict
from .ssl import hasValidSSLCertificate, reportSslCertificate
import datetime
__version__ = "0.5.0"
......@@ -163,15 +164,18 @@ class WebBot:
# Report the bot status
result_dict["bot_status"] = []
try:
status = reportStatus(self._db).get()
bot_status = reportStatus(self._db).get()
except self._db.Status.DoesNotExist:
pass
result_dict["bot_status"].append(
{"text": "", "date": rfc822(datetime.datetime.utcnow())}
)
else:
result_dict["bot_status"].append(
{"text": status.text, "date": rfc822(status.timestamp)}
{"text": bot_status.text, "date": rfc822(bot_status.timestamp)}
)
# Report the list of DNS server status
checked_resolver_ip_dict = {}
query = reportNetwork(
self._db,
port="53",
......@@ -181,6 +185,7 @@ class WebBot:
resolver_ip_list = []
result_dict["dns_server"] = []
for network_change in query.dicts().iterator():
checked_resolver_ip_dict[network_change["ip"]] = True
if network_change["state"] == "open":
resolver_ip_list.append(network_change["ip"])
result_dict["dns_server"].append(
......@@ -192,6 +197,7 @@ class WebBot:
)
domain_list = self.calculateFullDomainList()
checked_domain_dict = {}
# Report list of DNS query
query = reportDnsQuery(
self._db,
......@@ -202,6 +208,7 @@ class WebBot:
server_ip_dict = {}
result_dict["dns_query"] = []
for dns_change in query.dicts().iterator():
checked_domain_dict[dns_change["domain"]] = True
result_dict["dns_query"].append(
{
"domain": dns_change["domain"],
......@@ -219,6 +226,24 @@ class WebBot:
if dns_change["domain"] not in server_ip_dict[server_ip]:
server_ip_dict[server_ip].append(dns_change["domain"])
result_dict["missing_data"] = []
for resolver_ip in self.config["NAMESERVER"].split():
if resolver_ip not in checked_resolver_ip_dict:
result_dict["missing_data"].append(
{
"text": resolver_ip,
"date": result_dict["bot_status"][0]["date"],
}
)
for domain in domain_list:
if domain not in checked_domain_dict:
result_dict["missing_data"].append(
{
"text": domain,
"date": result_dict["bot_status"][0]["date"],
}
)
# Report the list of CDN status
query = reportNetwork(
self._db,
......
......@@ -561,10 +561,15 @@ class SurykatkaBotStatusTestCase(unittest.TestCase):
checkSslChange(bot, [])
checkHttpCodeChange(bot, [])
assert len(result["bot_status"]) == 1
assert result["bot_status"][0]["text"] == ""
assert result == {
"bot_status": [],
"bot_status": result["bot_status"],
"dns_server": [],
"dns_query": [],
"missing_data": [
{"text": resolver_ip, "date": result["bot_status"][0]["date"]}
],
"http_server": [],
"ssl_certificate": [],
"http_query": [],
......@@ -595,14 +600,15 @@ class SurykatkaBotStatusTestCase(unittest.TestCase):
bot.initDB()
result = bot.status()
assert result == {
"bot_status": [],
"dns_server": [],
"dns_query": [],
"http_server": [],
"ssl_certificate": [],
"http_query": [],
}
assert len(result["bot_status"]) == 1
assert result["bot_status"][0]["text"] == ""
assert len(result["dns_server"]) == 0
assert len(result["dns_query"]) == 0
assert len(result["http_server"]) == 0
assert len(result["ssl_certificate"]) == 0
assert len(result["http_query"]) == 0
# +1 for example.org
assert len(result["missing_data"]) == more_than_sqlite_max * 2 + 1
def suite():
......
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