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
@@ -27,8 +27,8 @@
|
||||
msg: "{{ monitoring_scrape_targets | map(attribute='name') | list | sort }}"
|
||||
|
||||
- name: Установить правила алертов vmalert
|
||||
ansible.builtin.copy:
|
||||
src: alerts.yml
|
||||
ansible.builtin.template:
|
||||
src: alerts.yml.j2
|
||||
dest: "{{ monitoring_dir }}/vmalert/alerts.yml"
|
||||
owner: root
|
||||
group: root
|
||||
@@ -95,3 +95,4 @@
|
||||
group: root
|
||||
mode: "0644"
|
||||
when: xray_checker_subscription_url | length > 0
|
||||
|
||||
+7
-10
@@ -1,3 +1,4 @@
|
||||
#jinja2: variable_start_string:'[[', variable_end_string:']]', block_start_string:'[%', block_end_string:'%]'
|
||||
groups:
|
||||
- name: homelab_alerts
|
||||
rules:
|
||||
@@ -17,11 +18,9 @@ groups:
|
||||
(
|
||||
time() - tlast_over_time(up{job="integrations/node_exporter"}[30m]) > 180
|
||||
)
|
||||
or absent_over_time(up{job="integrations/node_exporter",instance="core-mon"}[30m])
|
||||
or absent_over_time(up{job="integrations/node_exporter",instance="core-net"}[30m])
|
||||
or absent_over_time(up{job="integrations/node_exporter",instance="core-secrets"}[30m])
|
||||
or absent_over_time(up{job="integrations/node_exporter",instance="ger-nod-02"}[30m])
|
||||
or absent_over_time(up{job="integrations/node_exporter",instance="rus-central"}[30m])
|
||||
[% for h in (['core-mon', 'core-net', 'core-secrets', 'rus-central'] + (groups['exit_nodes'] | default([]))) | unique | sort %]
|
||||
or absent_over_time(up{job="integrations/node_exporter",instance="[[ h ]]"}[30m])
|
||||
[% endfor %]
|
||||
for: 1m
|
||||
labels:
|
||||
severity: critical
|
||||
@@ -138,11 +137,9 @@ groups:
|
||||
(
|
||||
time() - tlast_over_time(up{job="integrations/cAdvisor"}[30m]) > 180
|
||||
)
|
||||
or absent_over_time(up{job="integrations/cAdvisor",instance="core-mon"}[30m])
|
||||
or absent_over_time(up{job="integrations/cAdvisor",instance="core-net"}[30m])
|
||||
or absent_over_time(up{job="integrations/cAdvisor",instance="core-secrets"}[30m])
|
||||
or absent_over_time(up{job="integrations/cAdvisor",instance="ger-nod-02"}[30m])
|
||||
or absent_over_time(up{job="integrations/cAdvisor",instance="rus-central"}[30m])
|
||||
[% for h in (['core-mon', 'core-net', 'core-secrets', 'rus-central'] + (groups['exit_nodes'] | default([]))) | unique | sort %]
|
||||
or absent_over_time(up{job="integrations/cAdvisor",instance="[[ h ]]"}[30m])
|
||||
[% endfor %]
|
||||
for: 1m
|
||||
labels:
|
||||
severity: critical
|
||||
@@ -26,23 +26,11 @@ remnawave_metrics_pass: "{{ lookup('env', 'REMNAWAVE_METRICS_PASS', default='')
|
||||
remnawave_webhook_secret: "{{ lookup('env', 'REMNAWAVE_WEBHOOK_SECRET_HEADER', default='') }}"
|
||||
remnawave_api_token: "{{ lookup('env', 'REMNAWAVE_API_TOKEN', default='') }}"
|
||||
|
||||
# Нода Ger-nod-02 / SelfSteal — создаётся через API панели
|
||||
remnawave_node_name: "Ger-nod-02"
|
||||
remnawave_node_address: "150.241.64.209"
|
||||
remnawave_node_netbird_hostname: "ger-nod-02"
|
||||
remnawave_netbird_peers_url: "https://central.gunihome.ru/api/peers"
|
||||
remnawave_xray_checker_user: "homelab"
|
||||
remnawave_node_port: 2222
|
||||
remnawave_node_country: "DE"
|
||||
remnawave_selfsteal_domain: "yali.gunis.top"
|
||||
remnawave_xhttp_path: "/xhttp-yali"
|
||||
remnawave_profile_name: "DE-Yali"
|
||||
remnawave_inbound_tag: "Steal-Yali"
|
||||
remnawave_host_remark: "🇩🇪 ger-nod-02"
|
||||
remnawave_xray_template_name: "Except-RU"
|
||||
remnawave_api_token_name: "infra-automation"
|
||||
|
||||
# Документация WAN egress панели (см. remnanode_panel_egress_ips на ger-nod-02).
|
||||
# Документация WAN egress панели (см. remnanode_panel_egress_ips на выходных нодах).
|
||||
remnawave_panel_egress_ips:
|
||||
- "213.128.28.107" # провайдер 1 (МТС)
|
||||
- "185.160.137.140" # провайдер 2
|
||||
@@ -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