feat(remnawave,monitoring): full node/host cleanup on sync and dynamic alerts.yml.j2
This commit is contained in:
1 parent
b2524d1d1e
commit
ae9beee5ca
4 files changed
+44
-30
No files matched your search
@@ -371,20 +371,47 @@ def sync_squad(
|
||||
squad_map = {s["name"]: s["uuid"] for s in squads if s.get("name") and s.get("uuid")}
|
||||
|
||||
target = next((s for s in squads if s.get("name") == squad_name), None)
|
||||
if target and inbound_uuids:
|
||||
if target:
|
||||
cur_inbounds = [i["uuid"] for i in (target.get("inbounds") or []) if i.get("uuid")]
|
||||
missing = [u for u in inbound_uuids if u not in cur_inbounds]
|
||||
if missing:
|
||||
merged = list(dict.fromkeys(cur_inbounds + inbound_uuids))
|
||||
desired_inbounds = list(dict.fromkeys(inbound_uuids))
|
||||
if set(cur_inbounds) != set(desired_inbounds):
|
||||
api.request(
|
||||
"PATCH",
|
||||
"/internal-squads/",
|
||||
{"uuid": target["uuid"], "inbounds": merged},
|
||||
{"uuid": target["uuid"], "inbounds": desired_inbounds},
|
||||
)
|
||||
changes.append(f"updated squad {squad_name} inbounds")
|
||||
return squad_map
|
||||
|
||||
|
||||
def cleanup_removed_nodes_and_hosts(
|
||||
api: RemnawaveAPI,
|
||||
desired_nodes: list[dict[str, Any]],
|
||||
changes: list[str],
|
||||
) -> None:
|
||||
desired_domains = {n["selfsteal_domain"] for n in desired_nodes}
|
||||
desired_node_names = {n["name"] for n in desired_nodes}
|
||||
desired_profile_names = {n["profile_name"] for n in desired_nodes}
|
||||
|
||||
_, hosts_resp = api.request("GET", "/hosts/")
|
||||
for h in _extract_list(hosts_resp):
|
||||
if h.get("address") not in desired_domains and h.get("uuid"):
|
||||
api.request("DELETE", f"/hosts/{h['uuid']}")
|
||||
changes.append(f"deleted host {h.get('address')}")
|
||||
|
||||
_, nodes_resp = api.request("GET", "/nodes/")
|
||||
for n in _extract_list(nodes_resp):
|
||||
if n.get("name") not in desired_node_names and n.get("uuid"):
|
||||
api.request("DELETE", f"/nodes/{n['uuid']}")
|
||||
changes.append(f"deleted node {n.get('name')}")
|
||||
|
||||
_, profiles_resp = api.request("GET", "/config-profiles/")
|
||||
for p in _extract_list(profiles_resp, "configProfiles"):
|
||||
if p.get("name") not in desired_profile_names and p.get("uuid"):
|
||||
api.request("DELETE", f"/config-profiles/{p['uuid']}")
|
||||
changes.append(f"deleted profile {p.get('name')}")
|
||||
|
||||
|
||||
def sync_subscription_settings(
|
||||
api: RemnawaveAPI,
|
||||
sub_page_cfg_name: str,
|
||||
@@ -568,6 +595,7 @@ def main() -> int:
|
||||
)
|
||||
|
||||
squad_map = sync_squad(api, cfg.get("squad_name", "Default-Squad"), inbound_uuids, changes)
|
||||
cleanup_removed_nodes_and_hosts(api, cfg.get("nodes", []), changes)
|
||||
sync_subscription_settings(api, cfg.get("subscription_page_config", "Homelab"), changes)
|
||||
xray_url = sync_users(
|
||||
api,
|
||||
|
||||
Reference in new issue
Block a user