Update script
This commit is contained in:
parent
2cea0d035f
commit
86762f076f
@ -6,7 +6,7 @@ steps:
|
|||||||
image: alpine
|
image: alpine
|
||||||
commands:
|
commands:
|
||||||
- apk add --no-cache git bash curl yq
|
- apk add --no-cache git bash curl yq
|
||||||
- bash automation/cloudflared-sync.sh
|
- bash automation/cloudflared/cloudflared-sync.sh
|
||||||
environment:
|
environment:
|
||||||
GIT_TOKEN:
|
GIT_TOKEN:
|
||||||
from_secret: GIT_TOKEN
|
from_secret: GIT_TOKEN
|
||||||
@ -23,7 +23,22 @@ steps:
|
|||||||
commands:
|
commands:
|
||||||
- apk add --no-cache git bash
|
- apk add --no-cache git bash
|
||||||
- pip install ruamel.yaml
|
- pip install ruamel.yaml
|
||||||
- bash automation/scrape-sync.sh
|
- bash automation/prometheus/scrape-sync.sh
|
||||||
environment:
|
environment:
|
||||||
GIT_TOKEN:
|
GIT_TOKEN:
|
||||||
from_secret: GIT_TOKEN
|
from_secret: GIT_TOKEN
|
||||||
|
|
||||||
|
external-url-alerts:
|
||||||
|
when:
|
||||||
|
branch: [master]
|
||||||
|
name: External Alert Checks (Pushover)
|
||||||
|
image: python:3.11-alpine
|
||||||
|
commands:
|
||||||
|
- apk add --no-cache git curl bash
|
||||||
|
- pip install pyyaml requests
|
||||||
|
- python3 automation/alerts/external-alert-checker.py
|
||||||
|
environment:
|
||||||
|
PUSHOVER_USER:
|
||||||
|
from_secret: PUSHOVER_USER
|
||||||
|
PUSHOVER_TOKEN:
|
||||||
|
from_secret: PUSHOVER_TOKEN
|
||||||
61
automation/alerts/external-alert-checker.py
Normal file
61
automation/alerts/external-alert-checker.py
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
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()
|
||||||
Loading…
x
Reference in New Issue
Block a user