feat: add various infrastructure check and automation scripts
This commit is contained in:
54
scripts/update_kuma_discord_webhook.py
Normal file
54
scripts/update_kuma_discord_webhook.py
Normal file
@@ -0,0 +1,54 @@
|
||||
import paramiko
|
||||
import sys
|
||||
import json
|
||||
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
c = paramiko.SSHClient()
|
||||
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
c.connect('140.44.4.11', username='root', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10)
|
||||
|
||||
def run_sql(pod, sql):
|
||||
cmd = f"kubectl exec -i -n monitoring {pod} -- mariadb --socket=/app/data/run/mariadb.sock -u root"
|
||||
stdin, stdout, stderr = c.exec_command(cmd)
|
||||
stdin.write(sql)
|
||||
stdin.close()
|
||||
return stdout.read().decode().strip(), stderr.read().decode().strip()
|
||||
|
||||
_, o, _ = c.exec_command("kubectl get pod -n monitoring -l app.kubernetes.io/name=uptime-kuma -o jsonpath='{.items[0].metadata.name}'")
|
||||
pod = o.read().decode().strip()
|
||||
print("Kuma Pod:", pod)
|
||||
|
||||
out, _ = run_sql(pod, "USE kuma; SELECT id, name, config FROM notification WHERE id=1;")
|
||||
print("Current config for notif 1:")
|
||||
print(out)
|
||||
|
||||
# Update config with active webhook
|
||||
cfg = {
|
||||
"name": "Discord Infra Alerts (#infra-alerts)",
|
||||
"type": "discord",
|
||||
"isDefault": True,
|
||||
"telegramServerUrl": "https://api.telegram.org",
|
||||
"discordChannelType": "channel",
|
||||
"disableUrl": False,
|
||||
"discordSuppressNotifications": False,
|
||||
"discordMessageFormat": "normal",
|
||||
"discordWebhookUrl": "https://discord.com/api/webhooks/1566076777963593772/wKN30N0ZXVJKGP-prZ1_P9cp_u7Oakmh8R4bVh0qr8RFpyeGcJZrHfPQBJxtfzQqb4dn",
|
||||
"applyExisting": True
|
||||
}
|
||||
cfg_json = json.dumps(cfg).replace("'", "''")
|
||||
|
||||
update_sql = f"""USE kuma;
|
||||
UPDATE notification
|
||||
SET name='Discord Infra Alerts (#infra-alerts)', is_default=1, active=1, config='{cfg_json}'
|
||||
WHERE id=1;
|
||||
"""
|
||||
|
||||
out, err = run_sql(pod, update_sql)
|
||||
print("Update result err:", err)
|
||||
|
||||
# Restart pod so kuma caches updated webhook
|
||||
_, o, _ = c.exec_command("kubectl rollout restart deploy/uptime-kuma-2-1756668961 -n monitoring")
|
||||
print("Restarting deployment:", o.read().decode().strip())
|
||||
|
||||
c.close()
|
||||
|
||||
Reference in New Issue
Block a user