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