From 7d49ce1ce39894d9a0e93eb7526096a4a1c00332 Mon Sep 17 00:00:00 2001 From: SebClem Date: Fri, 29 Mar 2024 11:47:54 +0100 Subject: [PATCH] Load uptime config --- plugins/action/load_haproxy_config.py | 28 +++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/plugins/action/load_haproxy_config.py b/plugins/action/load_haproxy_config.py index 9c3cfad..4277ce6 100644 --- a/plugins/action/load_haproxy_config.py +++ b/plugins/action/load_haproxy_config.py @@ -58,7 +58,8 @@ class ActionModule(ActionBase): "domain_maping": [], "dns_hostnames": dict(), # { provider: [ { hostname:"", domain:"", state: "", target: "" } ] } "protected_domain": [], - "backend_config": [] + "backend_config": [], + "uptime_config": [] # [{ name:"", url: "", protected: True, state: "" }] } failed = False @@ -79,6 +80,7 @@ class ActionModule(ActionBase): results['backend_config'] = results['backend_config'] + updated_results['backend_config'] for key, value in updated_results['dns_hostnames'].items(): results['dns_hostnames'][key] = results['dns_hostnames'].get(key, []) + value + results['uptime_config'] = results['uptime_config'] + updated_results['uptime_config'] result = super(ActionModule, self).run(task_vars=task_vars) @@ -180,7 +182,8 @@ class ActionModule(ActionBase): "domain_maping": [], "dns_hostnames": dict(), # { provider: [ { hostname:"", domain:"", state: "", target: "" } ] } "protected_domain": [], - "backend_config": [] + "backend_config": [], + "uptime_config": [] # [{ name:"", url: "", protected: True, state: "" }] } failed = False err_msg = '' @@ -205,6 +208,8 @@ class ActionModule(ActionBase): protected = loaded_data.get("protected", False) additionnal_hostname = loaded_data.get('additionnal_hostname', []) state = loaded_data.get("state", "present") + uptime_raw_config = loaded_data.get("uptime", dict()) + if "backend" not in loaded_data: failed = True err_msg = ('Could not find "backend" in {0}'.format(to_native(filename))) @@ -216,7 +221,7 @@ class ActionModule(ActionBase): results['backend_config'].append(backend) if protected: results['protected_domain'].append('{0}.{1}'.format(main_hostname, domain)) - + if not dns.get("skip", False): if not dns_provider in results['dns_hostnames']: results['dns_hostnames'].update({ dns_provider: []}) @@ -227,7 +232,15 @@ class ActionModule(ActionBase): "target": dns_target, "state": state, }) - + + results['uptime_config'].append({ + "name": main_hostname, + "url": 'https://{0}.{1}/{2}'.format(main_hostname, domain, uptime_raw_config.get("endpoint", "")), + "protected": protected, + "state": uptime_raw_config.get("state", state) + }) + + for host in additionnal_hostname: this_dns = host.get("dns", dns) this_domain = this_dns.get("domain", domain) @@ -235,6 +248,7 @@ class ActionModule(ActionBase): this_dns_target = this_dns.get("target", dns_target) this_protected = host.get('protected', protected) this_state = host.get('state', state) + this_uptime_raw_config = host.get("uptime", dict()) if this_state == "present": full_domain = '{0}.{1}'.format(host.get("hostname"), this_domain) if host.get("hostname") else this_domain @@ -252,4 +266,10 @@ class ActionModule(ActionBase): "target": this_dns_target, "state": this_state }) + results['uptime_config'].append({ + "name": host.get("hostname"), + "url": 'https://{0}/{1}'.format(full_domain, this_uptime_raw_config.get("endpoint", "")), + "protected": this_protected, + "state": this_uptime_raw_config.get("state", this_state) + }) return failed, err_msg, results \ No newline at end of file