mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
NS1 support for TCP healthchecks
This commit is contained in:
@@ -856,18 +856,13 @@ class Ns1Provider(BaseProvider):
|
||||
host = record.fqdn[:-1]
|
||||
_type = record._type
|
||||
|
||||
request = r'GET {path} HTTP/1.0\r\nHost: {host}\r\n' \
|
||||
r'User-agent: NS1\r\n\r\n'.format(path=record.healthcheck_path,
|
||||
host=record.healthcheck_host)
|
||||
|
||||
return {
|
||||
ret = {
|
||||
'active': True,
|
||||
'config': {
|
||||
'connect_timeout': 2000,
|
||||
'host': value,
|
||||
'port': record.healthcheck_port,
|
||||
'response_timeout': 10000,
|
||||
'send': request,
|
||||
'ssl': record.healthcheck_protocol == 'HTTPS',
|
||||
},
|
||||
'frequency': 60,
|
||||
@@ -881,12 +876,23 @@ class Ns1Provider(BaseProvider):
|
||||
'rapid_recheck': False,
|
||||
'region_scope': 'fixed',
|
||||
'regions': self.monitor_regions,
|
||||
'rules': [{
|
||||
}
|
||||
|
||||
if record.healthcheck_protocol != 'TCP':
|
||||
# IF it's HTTP we need to send the request string
|
||||
path = record.healthcheck_path
|
||||
host = record.healthcheck_host
|
||||
request = r'GET {path} HTTP/1.0\r\nHost: {host}\r\n' \
|
||||
r'User-agent: NS1\r\n\r\n'.format(path=path, host=host)
|
||||
ret['config']['send'] = request
|
||||
# We'll also expect a HTTP response
|
||||
ret['rules'] = [{
|
||||
'comparison': 'contains',
|
||||
'key': 'output',
|
||||
'value': '200 OK',
|
||||
}],
|
||||
}
|
||||
}]
|
||||
|
||||
return ret
|
||||
|
||||
def _monitor_is_match(self, expected, have):
|
||||
# Make sure what we have matches what's in expected exactly. Anything
|
||||
|
||||
@@ -717,6 +717,13 @@ class TestNs1ProviderDynamic(TestCase):
|
||||
monitor = provider._monitor_gen(self.record, value)
|
||||
self.assertTrue(monitor['config']['ssl'])
|
||||
|
||||
self.record._octodns['healthcheck']['protocol'] = 'TCP'
|
||||
monitor = provider._monitor_gen(self.record, value)
|
||||
# No http send done
|
||||
self.assertFalse('send' in monitor['config'])
|
||||
# No http response expected
|
||||
self.assertFalse('rules' in monitor)
|
||||
|
||||
def test_monitor_is_match(self):
|
||||
provider = Ns1Provider('test', 'api-key')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user