diff --git a/automation/alerts/external_alert_checker.py b/automation/alerts/external_alert_checker.py deleted file mode 100644 index 4d679bd..0000000 --- a/automation/alerts/external_alert_checker.py +++ /dev/null @@ -1,61 +0,0 @@ -import requests -import yaml -import os -import subprocess - -# === CONFIG === -PUSHOVER_TOKEN = os.getenv("PUSHOVER_TOKEN") -PUSHOVER_USER = os.getenv("PUSHOVER_USER") -REPOS = { - "dev-tools": "https://git.dvirlabs.com/dvirlabs/dev-tools.git", - "infra": "https://git.dvirlabs.com/dvirlabs/infra.git" -} -BASE_DIR = "./repos" - -def clone_repos(): - os.makedirs(BASE_DIR, exist_ok=True) - for name, url in REPOS.items(): - repo_path = os.path.join(BASE_DIR, name) - if os.path.exists(repo_path): - subprocess.run(["git", "-C", repo_path, "pull"]) - else: - subprocess.run(["git", "clone", url, repo_path]) - -def send_pushover(message): - requests.post("https://api.pushover.net/1/messages.json", data={ - "token": PUSHOVER_TOKEN, - "user": PUSHOVER_USER, - "message": message - }) - -def check_targets(): - for repo in os.listdir(BASE_DIR): - repo_path = os.path.join(BASE_DIR, repo, "manifests") - if not os.path.isdir(repo_path): - continue - for app in os.listdir(repo_path): - file_path = os.path.join(repo_path, app, "monitoring.yaml") - if not os.path.exists(file_path): - continue - with open(file_path) as f: - config = yaml.safe_load(f) - if not config.get("enabled"): - continue - external = config.get("external_check") - if not external: - continue - url = external.get("url") - alerts = external.get("alerts", []) - try: - r = requests.get(url, timeout=5) - code = r.status_code - for alert in alerts: - if code == alert["code"]: - send_pushover(alert["message"]) - break - except Exception as e: - send_pushover(f"❗ {config.get('app')} unreachable: {e}") - -if __name__ == "__main__": - clone_repos() - check_targets() diff --git a/automation/alerts/generate_monitor_workflow.py b/automation/alerts/generate_monitor_workflow.py index 11b3900..81c4f13 100644 --- a/automation/alerts/generate_monitor_workflow.py +++ b/automation/alerts/generate_monitor_workflow.py @@ -38,16 +38,17 @@ def extract_urls(): if not ext or not ext.get("url"): continue app_name = cfg.get("app", app) - for alert in ext.get("alerts", []): + for code, sev in ext.get("expected_codes", {}).items(): urls.append({ "url": ext["url"], "name": app_name, - "code": alert["code"], - "message": alert["message"], - "severity": alert.get("severity", "info") + "code": code, + "message": f"⚠️ {app_name} down ({code})", + "severity": sev }) return urls + def severity_to_priority(sev): return { "critical": 2,