Commit 121b28c4 authored by Łukasz Nowak's avatar Łukasz Nowak

promise: Explain some status codes in check_surykatka_json

"Extended" status codes, like 524, 526 and others, come from surykatka
itself and shall be amended with additional explanation
parent 8b3d3510
...@@ -15,6 +15,14 @@ except ImportError: ...@@ -15,6 +15,14 @@ except ImportError:
@implementer(interface.IPromise) @implementer(interface.IPromise)
class RunPromise(GenericPromise): class RunPromise(GenericPromise):
EXTENDED_STATUS_CODE_MAPPING = {
'520': 'Too many redirects',
'523': 'Connection error',
'524': 'Connection timeout',
'526': 'SSL Error',
}
def __init__(self, config): def __init__(self, config):
super(RunPromise, self).__init__(config) super(RunPromise, self).__init__(config)
# Set frequency compatible to default surykatka interval - 2 minutes # Set frequency compatible to default surykatka interval - 2 minutes
...@@ -151,10 +159,18 @@ class RunPromise(GenericPromise): ...@@ -151,10 +159,18 @@ class RunPromise(GenericPromise):
return return
error_list = [] error_list = []
for entry in entry_list: for entry in entry_list:
if str(entry['status_code']) != str(status_code): entry_status_code = str(entry['status_code'])
if entry_status_code != status_code:
status_code_explanation = self.EXTENDED_STATUS_CODE_MAPPING.get(
entry_status_code)
if status_code_explanation:
status_code_explanation = '%s (%s)' % (
entry_status_code, status_code_explanation)
else:
status_code_explanation = entry_status_code
error_list.append( error_list.append(
'IP %s got status code %s instead of %s' % ( 'IP %s got status code %s instead of %s' % (
entry['ip'], entry['status_code'], status_code)) entry['ip'], status_code_explanation, status_code))
db_ip_list = [q['ip'] for q in entry_list] db_ip_list = [q['ip'] for q in entry_list]
if len(ip_list): if len(ip_list):
if set(ip_list) != set(db_ip_list): if set(ip_list) != set(db_ip_list):
......
...@@ -382,6 +382,65 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -382,6 +382,65 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
"15:11:12 -0000" "15:11:12 -0000"
) )
def _test_bad_code_explanation(self, status_code, explanation):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'status-code': '301',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000'
}
)
self.writeSurykatkaJson("""{
"http_query": [
{
"date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.1",
"status_code": %s,
"url": "https://www.erp5.com/"
}
],
"ssl_certificate": [
{
"date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com",
"ip": "127.0.0.1",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000"
},
{
"date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com",
"ip": "127.0.0.2",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000"
}
]
}
""" % status_code)
self.configureLauncher()
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"http_query: Problem with https://www.erp5.com/ : IP 127.0.0.1 got "
"status code %s instead of 301 ssl_certificate: Certificate for "
"https://www.erp5.com/ will expire on Mon, 13 Jul 2020 12:00:00 "
"-0000, which is more than 15 days, UTC now is Fri, 27 Dec 2019 "
"15:11:12 -0000" % explanation
)
def test_bad_code_explanation_520(self):
self._test_bad_code_explanation(520, '520 (Too many redirects)')
def test_bad_code_explanation_523(self):
self._test_bad_code_explanation(523, '523 (Connection error)')
def test_bad_code_explanation_524(self):
self._test_bad_code_explanation(524, '524 (Connection timeout)')
def test_bad_code_explanation_526(self):
self._test_bad_code_explanation(526, '526 (SSL Error)')
def test_bad_ip(self): def test_bad_ip(self):
self.writeSurykatkaPromise( self.writeSurykatkaPromise(
{ {
......
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