Update the script to get the app name from monitoring.yaml

and remove the old script beacause i have github actions
This commit is contained in:
dvirlabs 2025-06-29 06:34:17 +03:00
parent 522022f56d
commit b777aa08ea
2 changed files with 5 additions and 65 deletions

View File

@ -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()

View File

@ -38,16 +38,17 @@ def extract_urls():
if not ext or not ext.get("url"): if not ext or not ext.get("url"):
continue continue
app_name = cfg.get("app", app) app_name = cfg.get("app", app)
for alert in ext.get("alerts", []): for code, sev in ext.get("expected_codes", {}).items():
urls.append({ urls.append({
"url": ext["url"], "url": ext["url"],
"name": app_name, "name": app_name,
"code": alert["code"], "code": code,
"message": alert["message"], "message": f"⚠️ {app_name} down ({code})",
"severity": alert.get("severity", "info") "severity": sev
}) })
return urls return urls
def severity_to_priority(sev): def severity_to_priority(sev):
return { return {
"critical": 2, "critical": 2,