Load uptime config

This commit is contained in:
SebClem 2024-03-29 11:47:54 +01:00
parent a0a47ae4c2
commit 7d49ce1ce3
Signed by: sebclem
GPG Key ID: 5A4308F6A359EA50

View File

@ -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)))
@ -228,6 +233,14 @@ class ActionModule(ActionBase):
"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