diff --git a/octodns/provider/azuredns.py b/octodns/provider/azuredns.py index 93478b8..6629d6c 100644 --- a/octodns/provider/azuredns.py +++ b/octodns/provider/azuredns.py @@ -282,7 +282,7 @@ def _get_monitor(record): port=record.healthcheck_port, path=record.healthcheck_path, ) - host = record.healthcheck_host + host = record.healthcheck_host() if host: monitor.custom_headers = [MonitorConfigCustomHeadersItem( name='Host', value=host diff --git a/octodns/provider/dyn.py b/octodns/provider/dyn.py index f7a15d2..da56a2e 100644 --- a/octodns/provider/dyn.py +++ b/octodns/provider/dyn.py @@ -705,7 +705,7 @@ class DynProvider(BaseProvider): label) extra.append(Update(record, record)) continue - if _monitor_doesnt_match(monitor, record.healthcheck_host, + if _monitor_doesnt_match(monitor, record.healthcheck_host(), record.healthcheck_path, record.healthcheck_protocol, record.healthcheck_port): @@ -828,13 +828,13 @@ class DynProvider(BaseProvider): self.traffic_director_monitors[label] = \ self.traffic_director_monitors[fqdn] del self.traffic_director_monitors[fqdn] - if _monitor_doesnt_match(monitor, record.healthcheck_host, + if _monitor_doesnt_match(monitor, record.healthcheck_host(), record.healthcheck_path, record.healthcheck_protocol, record.healthcheck_port): self.log.info('_traffic_director_monitor: updating monitor ' 'for %s', label) - monitor.update(record.healthcheck_host, + monitor.update(record.healthcheck_host(), record.healthcheck_path, record.healthcheck_protocol, record.healthcheck_port) @@ -845,7 +845,7 @@ class DynProvider(BaseProvider): monitor = DSFMonitor(label, protocol=record.healthcheck_protocol, response_count=2, probe_interval=60, retries=2, port=record.healthcheck_port, - active='Y', host=record.healthcheck_host, + active='Y', host=record.healthcheck_host(), timeout=self.MONITOR_TIMEOUT, header=self.MONITOR_HEADER, path=record.healthcheck_path) diff --git a/octodns/provider/ns1.py b/octodns/provider/ns1.py index a910459..9313d0d 100644 --- a/octodns/provider/ns1.py +++ b/octodns/provider/ns1.py @@ -929,7 +929,7 @@ class Ns1Provider(BaseProvider): if record.healthcheck_protocol != 'TCP': # IF it's HTTP we need to send the request string path = record.healthcheck_path - host = record.healthcheck_host + host = record.healthcheck_host(value=value) 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 diff --git a/octodns/provider/route53.py b/octodns/provider/route53.py index ad59eb0..f1b3b40 100644 --- a/octodns/provider/route53.py +++ b/octodns/provider/route53.py @@ -1084,7 +1084,7 @@ class Route53Provider(BaseProvider): try: ip_address(text_type(value)) # We're working with an IP, host is the Host header - healthcheck_host = record.healthcheck_host + healthcheck_host = record.healthcheck_host(value=value) except (AddressValueError, ValueError): # This isn't an IP, host is the value, value should be None healthcheck_host = value @@ -1257,7 +1257,7 @@ class Route53Provider(BaseProvider): # For CNAME, healthcheck host by default points to the CNAME value healthcheck_host = rrset['ResourceRecords'][0]['Value'] else: - healthcheck_host = record.healthcheck_host + healthcheck_host = record.healthcheck_host() healthcheck_path = record.healthcheck_path healthcheck_protocol = record.healthcheck_protocol diff --git a/octodns/record/__init__.py b/octodns/record/__init__.py index 42e9ed5..3ab8263 100644 --- a/octodns/record/__init__.py +++ b/octodns/record/__init__.py @@ -183,15 +183,11 @@ class Record(EqualityTupleMixin): def included(self): return self._octodns.get('included', []) - @property - def healthcheck_host(self): + def healthcheck_host(self, value=None): healthcheck = self._octodns.get('healthcheck', {}) if healthcheck.get('protocol', None) == 'TCP': return None - try: - return healthcheck['host'] - except KeyError: - return self.fqdn[:-1] + return healthcheck.get('host', self.fqdn[:-1]) or value @property def healthcheck_path(self): diff --git a/tests/test_octodns_provider_azuredns.py b/tests/test_octodns_provider_azuredns.py index 56a783d..3248b97 100644 --- a/tests/test_octodns_provider_azuredns.py +++ b/tests/test_octodns_provider_azuredns.py @@ -432,7 +432,7 @@ class Test_GetMonitor(TestCase): self.assertEquals(len(headers), 1) headers = headers[0] self.assertEqual(headers.name, 'Host') - self.assertEqual(headers.value, record.healthcheck_host) + self.assertEqual(headers.value, record.healthcheck_host()) # test TCP monitor record._octodns['healthcheck']['protocol'] = 'TCP' diff --git a/tests/test_octodns_provider_ns1.py b/tests/test_octodns_provider_ns1.py index f54c7bd..4ae4757 100644 --- a/tests/test_octodns_provider_ns1.py +++ b/tests/test_octodns_provider_ns1.py @@ -757,6 +757,10 @@ class TestNs1ProviderDynamic(TestCase): self.assertFalse(monitor['config']['ssl']) self.assertEquals('host:unit.tests type:A', monitor['notes']) + record._octodns['healthcheck']['host'] = None + monitor = provider._monitor_gen(record, value) + self.assertTrue(r'\nHost: 3.4.5.6\r' in monitor['config']['send']) + record._octodns['healthcheck']['protocol'] = 'HTTPS' monitor = provider._monitor_gen(record, value) self.assertTrue(monitor['config']['ssl']) diff --git a/tests/test_octodns_provider_route53.py b/tests/test_octodns_provider_route53.py index 1e7210d..1bf3332 100644 --- a/tests/test_octodns_provider_route53.py +++ b/tests/test_octodns_provider_route53.py @@ -1166,6 +1166,31 @@ class TestRoute53Provider(TestCase): }) stubber.add_response('change_tags_for_resource', {}) + health_check_config = { + 'EnableSNI': False, + 'FailureThreshold': 6, + 'FullyQualifiedDomainName': '4.2.3.4', + 'IPAddress': '4.2.3.4', + 'MeasureLatency': True, + 'Port': 8080, + 'RequestInterval': 10, + 'ResourcePath': '/_status', + 'Type': 'HTTP' + } + stubber.add_response('create_health_check', { + 'HealthCheck': { + 'Id': '43', + 'CallerReference': self.caller_ref, + 'HealthCheckConfig': health_check_config, + 'HealthCheckVersion': 1, + }, + 'Location': 'http://url', + }, { + 'CallerReference': ANY, + 'HealthCheckConfig': health_check_config, + }) + stubber.add_response('change_tags_for_resource', {}) + record = Record.new(self.expected, '', { 'ttl': 61, 'type': 'A', @@ -1191,6 +1216,11 @@ class TestRoute53Provider(TestCase): # when allowed to create we do id = provider.get_health_check_id(record, value, True) self.assertEquals('42', id) + + # when allowed to create and when host is None + record._octodns['healthcheck']['host'] = None + id = provider.get_health_check_id(record, value, True) + self.assertEquals('43', id) stubber.assert_no_pending_responses() # A CNAME style healthcheck, without a value diff --git a/tests/test_octodns_record.py b/tests/test_octodns_record.py index a16ee44..315670e 100644 --- a/tests/test_octodns_record.py +++ b/tests/test_octodns_record.py @@ -1015,17 +1015,33 @@ class TestRecord(TestCase): } }) self.assertEquals('/_ready', new.healthcheck_path) - self.assertEquals('bleep.bloop', new.healthcheck_host) + self.assertEquals('bleep.bloop', new.healthcheck_host()) self.assertEquals('HTTP', new.healthcheck_protocol) self.assertEquals(8080, new.healthcheck_port) + # empty host value in healthcheck + new = Record.new(self.zone, 'a', { + 'ttl': 44, + 'type': 'A', + 'value': '1.2.3.4', + 'octodns': { + 'healthcheck': { + 'path': '/_ready', + 'host': None, + 'protocol': 'HTTP', + 'port': 8080, + } + } + }) + self.assertEquals('1.2.3.4', new.healthcheck_host(value="1.2.3.4")) + new = Record.new(self.zone, 'a', { 'ttl': 44, 'type': 'A', 'value': '1.2.3.4', }) self.assertEquals('/_dns', new.healthcheck_path) - self.assertEquals('a.unit.tests', new.healthcheck_host) + self.assertEquals('a.unit.tests', new.healthcheck_host()) self.assertEquals('HTTPS', new.healthcheck_protocol) self.assertEquals(443, new.healthcheck_port) @@ -1044,7 +1060,7 @@ class TestRecord(TestCase): } }) self.assertIsNone(new.healthcheck_path) - self.assertIsNone(new.healthcheck_host) + self.assertIsNone(new.healthcheck_host()) self.assertEquals('TCP', new.healthcheck_protocol) self.assertEquals(8080, new.healthcheck_port) @@ -1059,7 +1075,7 @@ class TestRecord(TestCase): } }) self.assertIsNone(new.healthcheck_path) - self.assertIsNone(new.healthcheck_host) + self.assertIsNone(new.healthcheck_host()) self.assertEquals('TCP', new.healthcheck_protocol) self.assertEquals(443, new.healthcheck_port)