Commit f280dfdd authored by Łukasz Nowak's avatar Łukasz Nowak

promise: Drop UTC-now from surykatka output

This will lead to minimise amount of entries, and they will be only shown
when the status would change.
parent f09df509
...@@ -75,18 +75,18 @@ class RunPromise(GenericPromise): ...@@ -75,18 +75,18 @@ class RunPromise(GenericPromise):
delta = self.utcnow - last_bot_datetime delta = self.utcnow - last_bot_datetime
# sanity check # sanity check
if delta < datetime.timedelta(minutes=0): if delta < datetime.timedelta(minutes=0):
appendError('Last bot datetime %s is in future, UTC now %s', appendError('Last bot datetime %s is in future',
last_bot_datetime_string, self.utcnow_string) last_bot_datetime_string,)
return return
if delta > datetime.timedelta(minutes=15): if delta > datetime.timedelta(minutes=15):
appendError( appendError(
'Last bot datetime %s is more than 15 minutes old, UTC now %s', 'Last bot datetime %s is more than 15 minutes old',
last_bot_datetime_string, self.utcnow_string) last_bot_datetime_string,)
return return
self.appendInfoMessage( self.appendInfoMessage(
'%s: OK Last bot status from %s, UTC now is %s' % '%s: OK Last bot status from %s' %
(key, last_bot_datetime_string, self.utcnow_string)) (key, last_bot_datetime_string,))
def senseSslCertificate(self): def senseSslCertificate(self):
key = 'ssl_certificate' key = 'ssl_certificate'
...@@ -137,17 +137,15 @@ class RunPromise(GenericPromise): ...@@ -137,17 +137,15 @@ 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 on %s will expire on %s, which is less than %s days, ' 'Certificate on %s will expire on %s, which is less than %s days' %
'UTC now is %s', entry['ip'], entry['not_after'], certificate_expiration_days)
entry['ip'], entry['not_after'], certificate_expiration_days,
self.utcnow_string)
return return
else: else:
self.appendInfoMessage( self.appendInfoMessage(
'%s: OK Certificate on %s will expire on %s, which is more than ' '%s: OK Certificate on %s will expire on %s, which is more than '
'%s days, UTC now is %s' % '%s days' % (
(key, entry['ip'], entry['not_after'], certificate_expiration_days, key, entry['ip'], entry['not_after'],
self.utcnow_string)) certificate_expiration_days))
return return
def senseHttpQuery(self): def senseHttpQuery(self):
...@@ -245,11 +243,8 @@ class RunPromise(GenericPromise): ...@@ -245,11 +243,8 @@ class RunPromise(GenericPromise):
if test_utcnow: if test_utcnow:
self.utcnow = datetime.datetime.fromtimestamp( self.utcnow = datetime.datetime.fromtimestamp(
time.mktime(email.utils.parsedate(test_utcnow))) time.mktime(email.utils.parsedate(test_utcnow)))
self.utcnow_string = test_utcnow
else: else:
self.utcnow = datetime.datetime.utcnow() self.utcnow = datetime.datetime.utcnow()
self.utcnow_string = email.utils.formatdate(time.mktime(
self.utcnow.timetuple()))
self.json_file = self.getConfig('json-file', '') self.json_file = self.getConfig('json-file', '')
if not os.path.exists(self.json_file): if not os.path.exists(self.json_file):
......
...@@ -114,8 +114,7 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin): ...@@ -114,8 +114,7 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin):
self.launcher.run() self.launcher.run()
self.assertPassedMessage( self.assertPassedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"bot_status: OK Last bot status from Fri, 13 Dec 2222 08:10:11 -0000, " "bot_status: OK Last bot status from Fri, 13 Dec 2222 08:10:11 -0000"
"UTC now is Wed, 13 Dec 2222 09:11:12 -0000"
) )
def test_no_loop(self): def test_no_loop(self):
...@@ -167,7 +166,7 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin): ...@@ -167,7 +166,7 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin):
self.assertFailedMessage( self.assertFailedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"bot_status: ERROR Last bot datetime Sat, 13 Dec 2223 08:10:11 -0000 is " "bot_status: ERROR Last bot datetime Sat, 13 Dec 2223 08:10:11 -0000 is "
"in future, UTC now Wed, 13 Dec 2222 09:11:12 -0000" "in future"
) )
def test_bot_status_old(self): def test_bot_status_old(self):
...@@ -193,7 +192,7 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin): ...@@ -193,7 +192,7 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin):
self.assertFailedMessage( self.assertFailedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"bot_status: ERROR Last bot datetime Sat, 13 Dec 2223 08:10:11 -0000 is " "bot_status: ERROR Last bot datetime Sat, 13 Dec 2223 08:10:11 -0000 is "
"more than 15 minutes old, UTC now Wed, 13 Dec 2223 09:26:12 -0000" "more than 15 minutes old"
) )
def test_not_bot_status(self): def test_not_bot_status(self):
...@@ -287,8 +286,7 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -287,8 +286,7 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : http_query: OK status code 302 on IPs " "https://www.erp5.com/ : http_query: OK status code 302 on IPs "
"127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate on 127.0.0.1 will " "127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate on 127.0.0.1 will "
"expire on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, " "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): def test_maximum_elapsed_time(self):
...@@ -349,11 +347,10 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -349,11 +347,10 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : http_query: OK status code 302 on IPs " "https://www.erp5.com/ : http_query: OK status code 302 on IPs "
"127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate on 127.0.0.1 will " "127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate on 127.0.0.1 will "
"expire on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, " "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 " "elapsed_time: OK IP 127.0.0.1 replied in 4.00s which is shorter than "
"127.0.0.1 replied in 4.00s which is shorter than maximum 5.00s " "maximum 5.00s elapsed_time: OK IP 127.0.0.2 replied in 4.00s which is "
"elapsed_time: OK IP 127.0.0.2 replied in 4.00s which is shorter than " "shorter than maximum 5.00s"
"maximum 5.00s"
) )
def test_maximum_elapsed_time_too_long(self): def test_maximum_elapsed_time_too_long(self):
...@@ -417,8 +414,7 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -417,8 +414,7 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
"6.00s which is longer than maximum 5.00s elapsed_time: ERROR IP " "6.00s which is longer than maximum 5.00s elapsed_time: ERROR IP "
"127.0.0.2 failed to reply http_query: OK status code 302 on IPs " "127.0.0.2 failed to reply http_query: OK status code 302 on IPs "
"127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate on 127.0.0.1 will " "127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate on 127.0.0.1 will "
"expire on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, " "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_no_total_seconds(self): def test_maximum_elapsed_time_no_total_seconds(self):
...@@ -476,8 +472,7 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -476,8 +472,7 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : http_query: OK status code 302 on IPs " "https://www.erp5.com/ : http_query: OK status code 302 on IPs "
"127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate on 127.0.0.1 will " "127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate on 127.0.0.1 will "
"expire on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, " "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): def test_http(self):
...@@ -577,8 +572,7 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -577,8 +572,7 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : http_query: OK with status code 302 " "https://www.erp5.com/ : http_query: OK with status code 302 "
"ssl_certificate: OK Certificate on 127.0.0.1 will expire on Mon, 13 " "ssl_certificate: OK Certificate on 127.0.0.1 will expire on Mon, 13 "
"Jul 2020 12:00:00 -0000, which is more than 15 days, UTC now is Fri, " "Jul 2020 12:00:00 -0000, which is more than 15 days"
"27 Dec 2019 15:11:12 -0000"
) )
def test_no_http_query_data(self): def test_no_http_query_data(self):
...@@ -618,8 +612,7 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -618,8 +612,7 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : http_query: ERROR No data elapsed_time: ERROR " "https://www.erp5.com/ : http_query: ERROR No data elapsed_time: ERROR "
"No data ssl_certificate: OK Certificate on 127.0.0.1 will expire on " "No data ssl_certificate: OK Certificate on 127.0.0.1 will expire on "
"Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, UTC now " "Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days"
"is Fri, 27 Dec 2019 15:11:12 -0000"
) )
def test_no_ssl_certificate_data(self): def test_no_ssl_certificate_data(self):
...@@ -765,8 +758,7 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -765,8 +758,7 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : http_query: ERROR IP 127.0.0.1 got status code " "https://www.erp5.com/ : http_query: ERROR IP 127.0.0.1 got status code "
"302 instead of 301 ssl_certificate: OK Certificate on 127.0.0.1 will " "302 instead of 301 ssl_certificate: OK Certificate on 127.0.0.1 will "
"expire on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, " "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): def _test_bad_code_explanation(self, status_code, explanation):
...@@ -811,8 +803,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -811,8 +803,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : http_query: ERROR IP 127.0.0.1 got status code " "https://www.erp5.com/ : http_query: ERROR IP 127.0.0.1 got status code "
"%s instead of 301 ssl_certificate: OK Certificate on 127.0.0.1 will " "%s instead of 301 ssl_certificate: OK Certificate on 127.0.0.1 will "
"expire on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, " "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,) "" % (explanation,)
) )
def test_bad_code_explanation_520(self): def test_bad_code_explanation_520(self):
...@@ -883,8 +875,7 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -883,8 +875,7 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
"https://www.erp5.com/ : http_query: ERROR expected IPs 127.0.0.1 " "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: " "127.0.0.2 differes from got 127.0.0.1 127.0.0.4 ssl_certificate: "
"OK Certificate on 127.0.0.1 will expire on Mon, 13 Jul 2020 12:00:00 " "OK Certificate on 127.0.0.1 will expire on Mon, 13 Jul 2020 12:00:00 "
"-0000, which is more than 15 days, UTC now is Fri, 27 Dec 2019 " "-0000, which is more than 15 days"
"15:11:12 -0000"
) )
def test_bad_ip_status_code(self): def test_bad_ip_status_code(self):
...@@ -944,7 +935,7 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -944,7 +935,7 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
"302 instead of 301 http_query: ERROR expected IPs 127.0.0.1 127.0.0.2 " "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 " "differes from got 127.0.0.1 127.0.0.4 ssl_certificate: OK Certificate "
"on 127.0.0.1 will expire on Mon, 13 Jul 2020 12:00:00 -0000, which is " "on 127.0.0.1 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" "more than 15 days"
) )
def test_https_no_cert(self): def test_https_no_cert(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