Commit 9974ad80 authored by Łukasz Nowak's avatar Łukasz Nowak

promise: Simplify check_surykatka_json messages

Show URL only once and having this in mind simplify messages still keeping
all information.
parent 6298e582
......@@ -39,7 +39,11 @@ class RunPromise(GenericPromise):
else:
emit = self.logger.info
emit(' '.join(self.error_list + self.info_list))
message_list = self.error_list + self.info_list
url = self.getConfig('url')
if url:
message_list.insert(0, '%s :' % (url,))
emit(' '.join(message_list))
def senseBotStatus(self):
key = 'bot_status'
......@@ -105,16 +109,16 @@ class RunPromise(GenericPromise):
self.getConfig('certificate-expiration-days'))
return
if not hostname:
appendError('url %r is incorrect', url)
appendError('url is incorrect')
return
if key not in self.surykatka_json:
appendError(
'No data for %s . If the error persist, please update surykatka.', url)
'No key %r. If the error persist, please update surykatka.' % (key,))
return
entry_list = [
q for q in self.surykatka_json[key] if q['hostname'] == hostname]
if len(entry_list) == 0:
appendError('No data for %s', url)
appendError('No data')
return
for entry in entry_list:
timetuple = email.utils.parsedate(entry['not_after'])
......@@ -123,16 +127,16 @@ class RunPromise(GenericPromise):
if certificate_expiration_time - datetime.timedelta(
days=certificate_expiration_days) < self.utcnow:
appendError(
'Certificate for %s will expire on %s, which is less than %s days, '
'Certificate will expire on %s, which is less than %s days, '
'UTC now is %s',
url, entry['not_after'], certificate_expiration_days,
entry['not_after'], certificate_expiration_days,
self.utcnow_string)
return
else:
self.appendInfoMessage(
'%s: OK Certificate for %s will expire on %s, which is more than %s '
'%s: OK Certificate will expire on %s, which is more than %s '
'days, UTC now is %s' %
(key, url, entry['not_after'], certificate_expiration_days,
(key, entry['not_after'], certificate_expiration_days,
self.utcnow_string))
return
......@@ -153,7 +157,7 @@ class RunPromise(GenericPromise):
entry_list = [q for q in self.surykatka_json[key] if q['url'] == url]
if len(entry_list) == 0:
appendError('No data for %s', url)
appendError('No data')
return
for entry in entry_list:
entry_status_code = str(entry['status_code'])
......@@ -166,26 +170,24 @@ class RunPromise(GenericPromise):
else:
status_code_explanation = entry_status_code
appendError(
'%s : IP %s got status code %s instead of %s' % (
url, entry['ip'], status_code_explanation, status_code))
'IP %s got status code %s instead of %s' % (
entry['ip'], status_code_explanation, status_code))
error = True
db_ip_list = [q['ip'] for q in entry_list]
if len(ip_list):
if set(ip_list) != set(db_ip_list):
appendError(
'%s : expected IPs %s differes from got %s' % (
url, ' '.join(ip_list), ' '.join(db_ip_list)))
'expected IPs %s differes from got %s' % (
' '.join(ip_list), ' '.join(db_ip_list)))
error = True
if error:
return
if len(ip_list) > 0:
self.appendInfoMessage(
'%s: OK %s replied correctly with status code %s on ip list %s' %
(key, url, status_code, ' '.join(ip_list)))
self.appendInfoMessage('%s: OK status code %s on IPs %s' % (
key, status_code, ' '.join(ip_list)))
else:
self.appendInfoMessage(
'%s: OK %s replied correctly with status code %s' %
(key, url, status_code))
self.appendInfoMessage('%s: OK with status code %s' % (
key, status_code))
def senseElapsedTime(self):
key = 'elapsed_time'
......@@ -195,7 +197,9 @@ class RunPromise(GenericPromise):
self.appendErrorMessage(key + ': ERROR ' + msg % args)
if surykatka_key not in self.surykatka_json:
appendError("%r not in %r", surykatka_key, self.json_file)
appendError(
'No key %r. If the error persist, please update surykatka.' % (
surykatka_key,))
return
url = self.getConfig('url')
......@@ -204,7 +208,7 @@ class RunPromise(GenericPromise):
entry_list = [
q for q in self.surykatka_json[surykatka_key] if q['url'] == url]
if len(entry_list) == 0:
appendError('No data for %s', url)
appendError('No data')
return
for entry in entry_list:
if maximum_elapsed_time:
......@@ -212,13 +216,13 @@ class RunPromise(GenericPromise):
maximum_elapsed_time = float(maximum_elapsed_time)
if entry['total_seconds'] > maximum_elapsed_time:
appendError(
'%s : IP %s replied in %.2fs which is longer than '
'IP %s replied in %.2fs which is longer than '
'maximum %.2fs' %
(url, entry['ip'], entry['total_seconds'], maximum_elapsed_time))
(entry['ip'], entry['total_seconds'], maximum_elapsed_time))
else:
self.appendInfoMessage(
'%s: OK %s : IP %s replied in %.2fs which is shorter than '
'maximum %.2fs' % (key, url, entry['ip'],
'%s: OK IP %s replied in %.2fs which is shorter than '
'maximum %.2fs' % (key, entry['ip'],
entry['total_seconds'], maximum_elapsed_time))
def sense(self):
......
......@@ -259,11 +259,10 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.launcher.run()
self.assertPassedMessage(
self.getPromiseResult(self.promise_name),
"http_query: OK https://www.erp5.com/ replied correctly with "
"status code 302 on ip list 127.0.0.1 127.0.0.2 ssl_certificate: "
"OK 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"
"https://www.erp5.com/ : http_query: OK status code 302 on IPs "
"127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate 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"
)
def test_maximum_elapsed_time(self):
......@@ -322,14 +321,12 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.launcher.run()
self.assertPassedMessage(
self.getPromiseResult(self.promise_name),
"http_query: OK https://www.erp5.com/ replied correctly with status "
"code 302 on ip list 127.0.0.1 127.0.0.2 ssl_certificate: OK "
"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 elapsed_time: OK https://www.erp5.com/ : IP "
"127.0.0.1 replied in 4.00s which is shorter than maximum 5.00s "
"elapsed_time: OK https://www.erp5.com/ : IP 127.0.0.2 replied in "
"4.00s which is shorter than maximum 5.00s"
"https://www.erp5.com/ : http_query: OK status code 302 on IPs "
"127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate 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 elapsed_time: OK IP 127.0.0.1 "
"replied in 4.00s which is shorter than maximum 5.00s elapsed_time: OK "
"IP 127.0.0.2 replied in 4.00s which is shorter than maximum 5.00s"
)
def test_maximum_elapsed_time_too_long(self):
......@@ -389,14 +386,12 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"elapsed_time: ERROR https://www.erp5.com/ : IP 127.0.0.1 replied in "
"6.00s which is longer than maximum 5.00s http_query: OK "
"https://www.erp5.com/ replied correctly with status code 302 on ip "
"list 127.0.0.1 127.0.0.2 ssl_certificate: OK 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 elapsed_time: OK https://www.erp5.com/ : IP 127.0.0.2 replied "
"in 4.00s which is shorter than maximum 5.00s"
"https://www.erp5.com/ : elapsed_time: ERROR IP 127.0.0.1 replied in "
"6.00s which is longer than maximum 5.00s http_query: OK status code "
"302 on IPs 127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate 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 elapsed_time: OK IP "
"127.0.0.2 replied in 4.00s which is shorter than maximum 5.00s"
)
def test_maximum_elapsed_time_no_total_seconds(self):
......@@ -452,11 +447,10 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.launcher.run()
self.assertPassedMessage(
self.getPromiseResult(self.promise_name),
"http_query: OK https://www.erp5.com/ replied correctly with status "
"code 302 on ip list 127.0.0.1 127.0.0.2 ssl_certificate: OK "
"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"
"https://www.erp5.com/ : http_query: OK status code 302 on IPs "
"127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate 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"
)
def test_http(self):
......@@ -499,8 +493,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.launcher.run()
self.assertPassedMessage(
self.getPromiseResult(self.promise_name),
"http_query: OK http://www.erp5.com/ replied correctly with "
"status code 302 on ip list 127.0.0.1 127.0.0.2"
"http://www.erp5.com/ : http_query: OK status code 302 on IPs 127.0.0.1 "
"127.0.0.2"
)
def test_no_ip_list(self):
......@@ -554,10 +548,10 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.launcher.run()
self.assertPassedMessage(
self.getPromiseResult(self.promise_name),
"http_query: OK https://www.erp5.com/ replied correctly with status "
"code 302 ssl_certificate: OK 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"
"https://www.erp5.com/ : http_query: OK with status code 302 "
"ssl_certificate: OK Certificate 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"
)
def test_no_http_query_data(self):
......@@ -595,11 +589,10 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"http_query: ERROR No data for https://www.erp5.com/ elapsed_time: "
"ERROR No data for https://www.erp5.com/ ssl_certificate: OK "
"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"
"https://www.erp5.com/ : http_query: ERROR No data elapsed_time: ERROR "
"No data ssl_certificate: OK Certificate 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"
)
def test_no_ssl_certificate_data(self):
......@@ -643,9 +636,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"ssl_certificate: ERROR No data for https://www.erp5.com/ http_query: "
"OK https://www.erp5.com/ replied correctly with "
"status code 302 on ip list 127.0.0.1 127.0.0.2"
"https://www.erp5.com/ : ssl_certificate: ERROR No data http_query: "
"OK status code 302 on IPs 127.0.0.1 127.0.0.2"
)
def test_no_ssl_certificate(self):
......@@ -687,10 +679,9 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"ssl_certificate: ERROR No data for https://www.erp5.com/ . If the "
"error persist, please update surykatka. http_query: OK "
"https://www.erp5.com/ replied correctly with status code 302 on ip "
"list 127.0.0.1 127.0.0.2"
"https://www.erp5.com/ : ssl_certificate: ERROR No key "
"'ssl_certificate'. If the error persist, please update surykatka. "
"http_query: OK status code 302 on IPs 127.0.0.1 127.0.0.2"
)
def test_bad_code(self):
......@@ -745,11 +736,10 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"http_query: ERROR https://www.erp5.com/ : IP 127.0.0.1 got "
"status code 302 instead of 301 ssl_certificate: OK 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"
"https://www.erp5.com/ : http_query: ERROR IP 127.0.0.1 got status code "
"302 instead of 301 ssl_certificate: OK Certificate 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"
)
def _test_bad_code_explanation(self, status_code, explanation):
......@@ -792,11 +782,10 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"http_query: ERROR https://www.erp5.com/ : IP 127.0.0.1 got "
"status code %s instead of 301 ssl_certificate: OK 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
"https://www.erp5.com/ : http_query: ERROR IP 127.0.0.1 got status code "
"%s instead of 301 ssl_certificate: OK Certificate 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):
......@@ -864,11 +853,10 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"http_query: ERROR https://www.erp5.com/ : expected IPs "
"127.0.0.1 127.0.0.2 differes from got 127.0.0.1 127.0.0.4 "
"ssl_certificate: OK 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"
"https://www.erp5.com/ : http_query: ERROR expected IPs 127.0.0.1 "
"127.0.0.2 differes from got 127.0.0.1 127.0.0.4 ssl_certificate: OK "
"Certificate 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"
)
def test_bad_ip_status_code(self):
......@@ -924,10 +912,9 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"http_query: ERROR https://www.erp5.com/ : IP 127.0.0.1 got status "
"code 302 instead of 301 http_query: ERROR https://www.erp5.com/ : "
"expected IPs 127.0.0.1 127.0.0.2 differes from got 127.0.0.1 "
"127.0.0.4 ssl_certificate: OK Certificate for https://www.erp5.com/ "
"https://www.erp5.com/ : http_query: ERROR IP 127.0.0.1 got status code "
"302 instead of 301 http_query: ERROR expected IPs 127.0.0.1 127.0.0.2 "
"differes from got 127.0.0.1 127.0.0.4 ssl_certificate: OK Certificate "
"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"
)
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