From 264cd22e6008970e8adcfe110a4b740fa02b7d41 Mon Sep 17 00:00:00 2001 From: Viranch Mehta Date: Mon, 1 Nov 2021 14:48:33 -0700 Subject: [PATCH] Add policy and frequency params for NS1 health-checks --- docs/dynamic_records.md | 6 +++++- octodns/provider/ns1.py | 14 ++++++++++++-- tests/test_octodns_provider_ns1.py | 8 ++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/docs/dynamic_records.md b/docs/dynamic_records.md index 69338db..e207458 100644 --- a/docs/dynamic_records.md +++ b/docs/dynamic_records.md @@ -203,8 +203,10 @@ Sonar check regions (sonar_regions) possible values: | Key | Description | Default | |--|--|--| +| policy | One of:
  1. `all` - down if every region is down
  2. `quorum` - down if majority regions are down
  3. `one` - down if any region is down
| `quorum` | +| frequency | Frequency (in seconds) of health-check | 60 | | connect_timeout | Timeout (in seconds) before we give up trying to connect | 2 | -| response_timeout | Timeout (in seconds) after connecting to wait for output. | 10 | +| response_timeout | Timeout (in seconds) after connecting to wait for output | 10 | ```yaml @@ -212,6 +214,8 @@ Sonar check regions (sonar_regions) possible values: octodns: ns1: healthcheck: + policy: quorum + frequency: 60 connect_timeout: 2 response_timeout: 10 ``` \ No newline at end of file diff --git a/octodns/provider/ns1.py b/octodns/provider/ns1.py index 63cf227..c30c9e2 100644 --- a/octodns/provider/ns1.py +++ b/octodns/provider/ns1.py @@ -1053,6 +1053,16 @@ class Ns1Provider(BaseProvider): return monitor_id, self._feed_create(monitor) + def _healthcheck_policy(self, record): + return record._octodns.get('ns1', {}) \ + .get('healthcheck', {}) \ + .get('policy', 'quorum') + + def _healthcheck_frequency(self, record): + return record._octodns.get('ns1', {}) \ + .get('healthcheck', {}) \ + .get('frequency', 60) + def _healthcheck_connect_timeout(self, record): return record._octodns.get('ns1', {}) \ .get('healthcheck', {}) \ @@ -1086,14 +1096,14 @@ class Ns1Provider(BaseProvider): self._healthcheck_response_timeout(record) * 1000, 'ssl': record.healthcheck_protocol == 'HTTPS', }, - 'frequency': 60, + 'frequency': self._healthcheck_frequency(record), 'job_type': 'tcp', 'name': f'{host} - {_type} - {value}', 'notes': self._encode_notes({ 'host': host, 'type': _type, }), - 'policy': 'quorum', + 'policy': self._healthcheck_policy(record), 'rapid_recheck': False, 'region_scope': 'fixed', 'regions': self.monitor_regions, diff --git a/tests/test_octodns_provider_ns1.py b/tests/test_octodns_provider_ns1.py index b7753d9..abc741b 100644 --- a/tests/test_octodns_provider_ns1.py +++ b/tests/test_octodns_provider_ns1.py @@ -925,6 +925,14 @@ class TestNs1ProviderDynamic(TestCase): # No http response expected self.assertFalse('rules' in monitor) + record._octodns['ns1']['healthcheck']['policy'] = 'all' + monitor = provider._monitor_gen(record, value) + self.assertEquals('all', monitor['policy']) + + record._octodns['ns1']['healthcheck']['frequency'] = 300 + monitor = provider._monitor_gen(record, value) + self.assertEquals(300, monitor['frequency']) + record._octodns['ns1']['healthcheck']['connect_timeout'] = 1 monitor = provider._monitor_gen(record, value) self.assertEquals(1000, monitor['config']['connect_timeout'])