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):
......
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