74 lines
2.7 KiB
Python
74 lines
2.7 KiB
Python
import requests
|
|
import json
|
|
import urllib3
|
|
urllib3.disable_warnings()
|
|
|
|
token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhcmdvY2QiLCJzdWIiOiJob21lcGFnZTphcGlLZXkiLCJuYmYiOjE3OTQ1MDIwNzgsImlhdCI6MTc5NDUwMjA3OCwianRpIjoiZjQ2NzU0NjMtODRhOS00MjI0LWI3ODItNmY5ODQxYWEwY2UxIn0.aHhrny2RBG-vAJAyXMvan0jw65jkP3bguqEduaG78O0"
|
|
headers = {
|
|
"Authorization": f"Bearer {token}",
|
|
"Content-Type": "application/json"
|
|
}
|
|
|
|
try:
|
|
resp = requests.get("https://argo.snarfnet.net/api/v1/applications", headers=headers, verify=False, timeout=10)
|
|
data = resp.json()
|
|
items = data.get("items", [])
|
|
print(f"Total Applications: {len(items)}\n")
|
|
|
|
out_of_sync = []
|
|
synced = []
|
|
|
|
for app in items:
|
|
name = app.get("metadata", {}).get("name")
|
|
sync_status = app.get("status", {}).get("sync", {}).get("status")
|
|
health_status = app.get("status", {}).get("health", {}).get("status")
|
|
dest_server = app.get("spec", {}).get("destination", {}).get("server")
|
|
dest_ns = app.get("spec", {}).get("destination", {}).get("namespace")
|
|
repo = app.get("spec", {}).get("source", {}).get("repoURL")
|
|
path = app.get("spec", {}).get("source", {}).get("path")
|
|
|
|
# Check operation or sync conditions/messages
|
|
operation_state = app.get("status", {}).get("operationState", {})
|
|
op_phase = operation_state.get("phase")
|
|
op_msg = operation_state.get("message")
|
|
conditions = app.get("status", {}).get("conditions", [])
|
|
|
|
info = {
|
|
"name": name,
|
|
"sync": sync_status,
|
|
"health": health_status,
|
|
"dest_ns": dest_ns,
|
|
"dest_server": dest_server,
|
|
"repo": repo,
|
|
"path": path,
|
|
"op_phase": op_phase,
|
|
"op_msg": op_msg,
|
|
"conditions": conditions
|
|
}
|
|
|
|
if sync_status != "Synced" or health_status not in ["Healthy", None]:
|
|
out_of_sync.append(info)
|
|
else:
|
|
synced.append(info)
|
|
|
|
print(f"=== OUT OF SYNC / DEGRADED APPS ({len(out_of_sync)}) ===")
|
|
for a in out_of_sync:
|
|
print(f"\nApp: {a['name']}")
|
|
print(f" Sync: {a['sync']} | Health: {a['health']}")
|
|
print(f" Dest: {a['dest_ns']} on {a['dest_server']}")
|
|
print(f" Path: {a['path']}")
|
|
if a['op_phase']:
|
|
print(f" Op Phase: {a['op_phase']}")
|
|
if a['op_msg']:
|
|
print(f" Op Msg: {a['op_msg']}")
|
|
if a['conditions']:
|
|
print(f" Conditions: {a['conditions']}")
|
|
|
|
print(f"\n=== SYNCED APPS ({len(synced)}) ===")
|
|
for a in synced:
|
|
print(f" {a['name']}: Sync={a['sync']}, Health={a['health']}, NS={a['dest_ns']}")
|
|
|
|
except Exception as e:
|
|
print("Error querying Argo CD API:", e)
|
|
|