Commit 04d93134 authored by Łukasz Nowak's avatar Łukasz Nowak

check_surykatka_json: Always emit check information

Instead of hiding unconfigured checks, emit OK message, which gives
information to the user regarding the full status.
parent 5cf0b54a
...@@ -101,6 +101,7 @@ class RunPromise(GenericPromise): ...@@ -101,6 +101,7 @@ class RunPromise(GenericPromise):
ssl_check = False ssl_check = False
certificate_expiration_days = None certificate_expiration_days = None
if not ssl_check: if not ssl_check:
self.appendMessage('%s: OK No check needed' % (key,))
return return
if certificate_expiration_days is None: if certificate_expiration_days is None:
appendError( appendError(
...@@ -216,8 +217,8 @@ class RunPromise(GenericPromise): ...@@ -216,8 +217,8 @@ class RunPromise(GenericPromise):
appendError('No data') appendError('No data')
return return
if len(ip_set):
self.appendMessage('%s:' % (key,)) self.appendMessage('%s:' % (key,))
if len(ip_set):
for entry in entry_list: for entry in entry_list:
response_ip_set = set([ response_ip_set = set([
q.strip() for q in entry['response'].split(",") if q.strip()]) q.strip() for q in entry['response'].split(",") if q.strip()])
...@@ -231,6 +232,8 @@ class RunPromise(GenericPromise): ...@@ -231,6 +232,8 @@ class RunPromise(GenericPromise):
self.appendMessage( self.appendMessage(
"OK resolver %s returned expected set of IPs %s" % ( "OK resolver %s returned expected set of IPs %s" % (
entry['resolver_ip'], ' '.join(sorted(ip_set)),)) entry['resolver_ip'], ' '.join(sorted(ip_set)),))
else:
self.appendMessage('OK No check configured')
def senseTcpServer(self): def senseTcpServer(self):
key = 'tcp_server' key = 'tcp_server'
...@@ -262,8 +265,8 @@ class RunPromise(GenericPromise): ...@@ -262,8 +265,8 @@ class RunPromise(GenericPromise):
if len(entry_list) == 0: if len(entry_list) == 0:
appendError('No data') appendError('No data')
return return
if len(ip_set) > 0:
self.appendMessage('%s:' % (key,)) self.appendMessage('%s:' % (key,))
if len(ip_set) > 0:
for ip in sorted(ip_set): for ip in sorted(ip_set):
ok = False ok = False
for entry in entry_list: for entry in entry_list:
...@@ -278,6 +281,8 @@ class RunPromise(GenericPromise): ...@@ -278,6 +281,8 @@ class RunPromise(GenericPromise):
else: else:
self.error = True self.error = True
self.appendMessage('ERROR IP %s:%s' % (ip, port)) self.appendMessage('ERROR IP %s:%s' % (ip, port))
else:
self.appendMessage('OK No check configured')
def senseElapsedTime(self): def senseElapsedTime(self):
key = 'elapsed_time' key = 'elapsed_time'
...@@ -304,30 +309,23 @@ class RunPromise(GenericPromise): ...@@ -304,30 +309,23 @@ class RunPromise(GenericPromise):
self.error = True self.error = True
self.appendMessage('%s: ERROR No data' % (key,)) self.appendMessage('%s: ERROR No data' % (key,))
return return
prefix_added = False self.appendMessage('%s:' % (key,))
for entry in entry_list:
if maximum_elapsed_time: if maximum_elapsed_time:
for entry in entry_list:
if 'total_seconds' in entry: if 'total_seconds' in entry:
maximum_elapsed_time = float(maximum_elapsed_time) maximum_elapsed_time = float(maximum_elapsed_time)
if entry['total_seconds'] == 0.: if entry['total_seconds'] == 0.:
if not prefix_added:
self.appendMessage('%s:' % (key,))
prefix_added = True
appendError('IP %s failed to reply' % (entry['ip'])) appendError('IP %s failed to reply' % (entry['ip']))
elif entry['total_seconds'] > maximum_elapsed_time: elif entry['total_seconds'] > maximum_elapsed_time:
if not prefix_added:
self.appendMessage('%s:' % (key,))
prefix_added = True
appendError( appendError(
'IP %s replied > %.2fs' % 'IP %s replied > %.2fs' %
(entry['ip'], maximum_elapsed_time)) (entry['ip'], maximum_elapsed_time))
else: else:
if not prefix_added:
self.appendMessage('%s:' % (key,))
prefix_added = True
self.appendMessage( self.appendMessage(
'OK IP %s replied < %.2fs' % ( 'OK IP %s replied < %.2fs' % (
entry['ip'], maximum_elapsed_time)) entry['ip'], maximum_elapsed_time))
else:
self.appendMessage("OK No check configured")
def sense(self): def sense(self):
""" """
......
...@@ -310,7 +310,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -310,7 +310,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
"http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 " "http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 "
"status_code 302 " "status_code 302 "
"ssl_certificate: OK IP 127.0.0.1 will expire in > 15 days OK IP " "ssl_certificate: OK IP 127.0.0.1 will expire in > 15 days OK IP "
"127.0.0.2 will expire in > 15 days" "127.0.0.2 will expire in > 15 days "
"elapsed_time: OK No check configured"
) )
def test_maximum_elapsed_time(self): def test_maximum_elapsed_time(self):
...@@ -496,19 +497,22 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -496,19 +497,22 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"status_code": 302, "status_code": 302,
"url": "https://www.erp5.com/" "url": "https://www.erp5.com/",
"total_seconds": 4
}, },
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.2", "ip": "127.0.0.2",
"status_code": 302, "status_code": 302,
"url": "https://www.erp5.com/" "url": "https://www.erp5.com/",
"total_seconds": 4
}, },
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "176.31.129.213", "ip": "176.31.129.213",
"status_code": 200, "status_code": 200,
"url": "https://www.erp5.org/" "url": "https://www.erp5.org/",
"total_seconds": 4
} }
], ],
"ssl_certificate": [ "ssl_certificate": [
...@@ -569,7 +573,9 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -569,7 +573,9 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
"http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 " "http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 "
"status_code 302 " "status_code 302 "
"ssl_certificate: OK IP 127.0.0.1 will expire in > 15 days OK IP " "ssl_certificate: OK IP 127.0.0.1 will expire in > 15 days OK IP "
"127.0.0.2 will expire in > 15 days" "127.0.0.2 will expire in > 15 days "
"elapsed_time: OK IP 127.0.0.1 replied < 5.00s OK IP 127.0.0.2 replied "
"< 5.00s"
) )
def test_http(self): def test_http(self):
...@@ -647,7 +653,9 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -647,7 +653,9 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
"127.0.0.1 127.0.0.2 " "127.0.0.1 127.0.0.2 "
"tcp_server: OK IP 127.0.0.1:80 OK IP 127.0.0.2:80 " "tcp_server: OK IP 127.0.0.1:80 OK IP 127.0.0.2:80 "
"http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 " "http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 "
"status_code 302" "status_code 302 "
"ssl_certificate: OK No check needed "
"elapsed_time: OK No check configured"
) )
def test_http_with_header_dict(self): def test_http_with_header_dict(self):
...@@ -712,9 +720,13 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -712,9 +720,13 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.assertPassedMessage( self.assertPassedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
'http://www.erp5.com/ : ' 'http://www.erp5.com/ : '
'dns_query: OK No check configured '
'tcp_server: OK No check configured '
'http_query: OK IP 176.31.129.213 status_code 200 OK IP ' 'http_query: OK IP 176.31.129.213 status_code 200 OK IP '
'176.31.129.213 HTTP Header {"Cache-Control": "max-age=300, public", ' '176.31.129.213 HTTP Header {"Cache-Control": "max-age=300, public", '
'"Vary": "Accept-Encoding"}' '"Vary": "Accept-Encoding"} '
'ssl_certificate: OK No check needed '
'elapsed_time: OK No check configured'
) )
def test_http_with_bad_header_dict(self): def test_http_with_bad_header_dict(self):
...@@ -781,10 +793,14 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -781,10 +793,14 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.assertFailedMessage( self.assertFailedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
'http://www.erp5.com/ : ' 'http://www.erp5.com/ : '
'dns_query: OK No check configured '
'tcp_server: OK No check configured '
'http_query: OK IP 176.31.129.213 status_code 200 ERROR IP ' 'http_query: OK IP 176.31.129.213 status_code 200 ERROR IP '
'176.31.129.213 expected HTTP Header {"Cache-Control": "max-age=300, ' '176.31.129.213 expected HTTP Header {"Cache-Control": "max-age=300, '
'public", "Vary": "Accept-Encoding"} != of {"Cache-Control": ' 'public", "Vary": "Accept-Encoding"} != of {"Cache-Control": '
'"max-age=300, public", "Vary": "Accept-Encoding,Cookie"}' '"max-age=300, public", "Vary": "Accept-Encoding,Cookie"} '
'ssl_certificate: OK No check needed '
'elapsed_time: OK No check configured'
) )
def test_no_ip_list(self): def test_no_ip_list(self):
...@@ -869,10 +885,13 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -869,10 +885,13 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.assertPassedMessage( self.assertPassedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : " "https://www.erp5.com/ : "
"dns_query: OK No check configured "
"tcp_server: OK No check configured "
"http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 " "http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 "
"status_code 302 " "status_code 302 "
"ssl_certificate: OK IP 127.0.0.1 will expire in > 15 days OK IP " "ssl_certificate: OK IP 127.0.0.1 will expire in > 15 days OK IP "
"127.0.0.2 will expire in > 15 days" "127.0.0.2 will expire in > 15 days "
"elapsed_time: OK No check configured"
) )
def test_good_certificate_2_day(self): def test_good_certificate_2_day(self):
...@@ -940,8 +959,11 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -940,8 +959,11 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.assertPassedMessage( self.assertPassedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : " "https://www.erp5.com/ : "
"dns_query: OK No check configured "
"tcp_server: OK No check configured "
"http_query: OK IP 127.0.0.1 status_code 302 " "http_query: OK IP 127.0.0.1 status_code 302 "
"ssl_certificate: OK IP 127.0.0.1 will expire in > 2 days" "ssl_certificate: OK IP 127.0.0.1 will expire in > 2 days "
"elapsed_time: OK No check configured"
) )
def test_expired_certificate_2_day(self): def test_expired_certificate_2_day(self):
...@@ -983,7 +1005,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -983,7 +1005,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
"dns_query: ERROR No data " "dns_query: ERROR No data "
"tcp_server: ERROR No data " "tcp_server: ERROR No data "
"http_query: OK IP 127.0.0.1 status_code 302 " "http_query: OK IP 127.0.0.1 status_code 302 "
"ssl_certificate: ERROR IP 127.0.0.1 will expire in < 2 days" "ssl_certificate: ERROR IP 127.0.0.1 will expire in < 2 days "
"elapsed_time: OK No check configured"
) )
def test_expired_certificate(self): def test_expired_certificate(self):
...@@ -1024,7 +1047,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -1024,7 +1047,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
"dns_query: ERROR No data " "dns_query: ERROR No data "
"tcp_server: ERROR No data " "tcp_server: ERROR No data "
"http_query: OK IP 127.0.0.1 status_code 302 " "http_query: OK IP 127.0.0.1 status_code 302 "
"ssl_certificate: ERROR IP 127.0.0.1 will expire in < 15 days" "ssl_certificate: ERROR IP 127.0.0.1 will expire in < 15 days "
"elapsed_time: OK No check configured"
) )
def test_expired_certificate_before_today(self): def test_expired_certificate_before_today(self):
...@@ -1065,7 +1089,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -1065,7 +1089,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
"dns_query: ERROR No data " "dns_query: ERROR No data "
"tcp_server: ERROR No data " "tcp_server: ERROR No data "
"http_query: OK IP 127.0.0.1 status_code 302 " "http_query: OK IP 127.0.0.1 status_code 302 "
"ssl_certificate: ERROR IP 127.0.0.1 will expire in < 15 days") "ssl_certificate: ERROR IP 127.0.0.1 will expire in < 15 days "
"elapsed_time: OK No check configured")
def test_no_http_query_data(self): def test_no_http_query_data(self):
self.writeSurykatkaPromise( self.writeSurykatkaPromise(
...@@ -1201,7 +1226,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -1201,7 +1226,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
"tcp_server: ERROR No data " "tcp_server: ERROR No data "
"http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 " "http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 "
"status_code 302 " "status_code 302 "
"ssl_certificate: ERROR No data" "ssl_certificate: ERROR No data "
"elapsed_time: OK No check configured"
) )
def test_no_ssl_certificate(self): def test_no_ssl_certificate(self):
...@@ -1249,7 +1275,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -1249,7 +1275,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
"http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 " "http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 "
"status_code 302 " "status_code 302 "
"ssl_certificate: ERROR No key 'ssl_certificate'. If the error " "ssl_certificate: ERROR No key 'ssl_certificate'. If the error "
"persist, please update surykatka." "persist, please update surykatka. "
"elapsed_time: OK No check configured"
) )
def test_bad_code(self): def test_bad_code(self):
...@@ -1310,7 +1337,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -1310,7 +1337,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
"http_query: ERROR IP 127.0.0.1 expected status_code 302 != 301 OK IP " "http_query: ERROR IP 127.0.0.1 expected status_code 302 != 301 OK IP "
"127.0.0.2 status_code 301 " "127.0.0.2 status_code 301 "
"ssl_certificate: OK IP 127.0.0.1 will expire in > 15 days OK IP " "ssl_certificate: OK IP 127.0.0.1 will expire in > 15 days OK IP "
"127.0.0.2 will expire in > 15 days" "127.0.0.2 will expire in > 15 days "
"elapsed_time: OK No check configured"
) )
def _test_bad_code_explanation(self, status_code, explanation): def _test_bad_code_explanation(self, status_code, explanation):
...@@ -1358,7 +1386,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -1358,7 +1386,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
"tcp_server: ERROR No data " "tcp_server: ERROR No data "
"http_query: ERROR IP 127.0.0.1 expected status_code %s != 301 " "http_query: ERROR IP 127.0.0.1 expected status_code %s != 301 "
"ssl_certificate: OK IP 127.0.0.1 will expire in > 15 days OK IP " "ssl_certificate: OK IP 127.0.0.1 will expire in > 15 days OK IP "
"127.0.0.2 will expire in > 15 days" % (explanation,) "127.0.0.2 will expire in > 15 days "
"elapsed_time: OK No check configured" % (explanation,)
) )
def test_bad_code_explanation_520(self): def test_bad_code_explanation_520(self):
...@@ -1432,7 +1461,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -1432,7 +1461,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
"http_query: OK IP 127.0.0.1 status_code 301 OK IP 127.0.0.4 " "http_query: OK IP 127.0.0.1 status_code 301 OK IP 127.0.0.4 "
"status_code 301 " "status_code 301 "
"ssl_certificate: OK IP 127.0.0.1 will expire in > 15 days OK IP " "ssl_certificate: OK IP 127.0.0.1 will expire in > 15 days OK IP "
"127.0.0.2 will expire in > 15 days" "127.0.0.2 will expire in > 15 days "
"elapsed_time: OK No check configured"
) )
def test_bad_ip_status_code(self): def test_bad_ip_status_code(self):
...@@ -1494,7 +1524,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -1494,7 +1524,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
"http_query: ERROR IP 127.0.0.1 expected status_code 302 != 301 OK IP " "http_query: ERROR IP 127.0.0.1 expected status_code 302 != 301 OK IP "
"127.0.0.4 status_code 301 " "127.0.0.4 status_code 301 "
"ssl_certificate: OK IP 127.0.0.1 will expire in > 15 days OK IP " "ssl_certificate: OK IP 127.0.0.1 will expire in > 15 days OK IP "
"127.0.0.2 will expire in > 15 days" "127.0.0.2 will expire in > 15 days "
"elapsed_time: OK No check configured"
) )
def test_https_no_cert(self): def test_https_no_cert(self):
...@@ -1550,7 +1581,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -1550,7 +1581,8 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
"http_query: ERROR IP 127.0.0.1 expected status_code 302 != 301 OK IP " "http_query: ERROR IP 127.0.0.1 expected status_code 302 != 301 OK IP "
"127.0.0.4 status_code 301 " "127.0.0.4 status_code 301 "
"ssl_certificate: ERROR IP 127.0.0.1 no information ERROR IP 127.0.0.2 " "ssl_certificate: ERROR IP 127.0.0.1 no information ERROR IP 127.0.0.2 "
"no information" "no information "
"elapsed_time: OK No check configured"
) )
def test_dns_query_no_entry(self): def test_dns_query_no_entry(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