Commit fe0adc9f authored by Romain Courteaud's avatar Romain Courteaud

Status: report missing expected data

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