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

check_surykatka_json: Allow to select senses

In some deployments it is important to being able to select only specific
senses on which the promise shall react.
parent 3a000d3a
Pipeline #28104 failed with stage
in 0 seconds
......@@ -27,6 +27,9 @@ class RunPromise(GenericPromise):
self.setPeriodicity(float(self.getConfig('frequency', 2)))
self.failure_amount = int(
self.getConfig('failure-amount', self.getConfig('failure_amount', 1)))
self.enabled_sense_list = self.getConfig(
'enabled-sense-list',
'dns_query tcp_server http_query ssl_certificate elapsed_time').split()
self.result_count = self.failure_amount
self.error = False
self.message_list = []
......@@ -317,11 +320,15 @@ class RunPromise(GenericPromise):
if report == 'bot_status':
self.senseBotStatus()
elif report == 'http_query':
self.senseDnsQuery()
self.senseTcpServer()
self.senseHttpQuery()
self.senseSslCertificate()
self.senseElapsedTime()
for check_name, check_method in [
('dns_query', self.senseDnsQuery),
('tcp_server', self.senseTcpServer),
('http_query', self.senseHttpQuery),
('ssl_certificate', self.senseSslCertificate),
('elapsed_time', self.senseElapsedTime)
]:
if check_name in self.enabled_sense_list:
check_method()
else:
self.appendError(
"Report %r is not supported" % report)
......
......@@ -1028,3 +1028,59 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
"ssl_certificate: OK No check needed "
"elapsed_time: ERROR No data" % {'json_file': self.json_file}
)
def test_all_ok_nothing_enabled(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.allok.com/',
'status-code': '302',
'ip-list': '127.0.0.1 127.0.0.2',
'maximum-elapsed-time': '5',
'enabled-sense-list': '',
}
)
self.runAndAssertPassedMessage(
"https://www.allok.com/ :"
)
def test_all_ok_no_ssl_certificate(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.allok.com/',
'status-code': '302',
'ip-list': '127.0.0.1 127.0.0.2',
'maximum-elapsed-time': '5',
'enabled-sense-list': 'dns_query tcp_server http_query elapsed_time',
}
)
self.runAndAssertPassedMessage(
"https://www.allok.com/ : "
"dns_query: OK resolver's 1.2.3.4: 127.0.0.1 127.0.0.2 "
"tcp_server: OK IP 127.0.0.1:443 OK IP 127.0.0.2:443 "
"http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 "
"status_code 302 "
"elapsed_time: OK IP 127.0.0.1 replied < 5.00s OK IP 127.0.0.2 replied "
"< 5.00s"
)
def test_all_ok_only_ssl_certificate(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.allok.com/',
'status-code': '302',
'ip-list': '127.0.0.1 127.0.0.2',
'maximum-elapsed-time': '5',
'enabled-sense-list': 'ssl_certificate',
}
)
self.runAndAssertPassedMessage(
"https://www.allok.com/ : "
"ssl_certificate: OK IP 127.0.0.1 expires in > 15 days OK IP "
"127.0.0.2 expires in > 15 days"
)
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