This commit is contained in:
parent
9987533f8a
commit
8de8cdd277
2 changed files with 49 additions and 0 deletions
48
check_consul.py
Normal file
48
check_consul.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import json
|
||||
import base64
|
||||
import urllib.request
|
||||
import sys
|
||||
|
||||
def check_state(repo_name):
|
||||
# Da das Skript auf dem Host läuft, nutzen wir localhost:8500
|
||||
url = f"http://localhost:8500/v1/kv/terraform/states/{repo_name}"
|
||||
|
||||
print(f"--- Suche Key in Consul: terraform/states/{repo_name} ---")
|
||||
try:
|
||||
req = urllib.request.Request(url)
|
||||
with urllib.request.urlopen(req, timeout=5) as response:
|
||||
data = json.loads(response.read().decode('utf-8'))
|
||||
|
||||
# Consul liefert immer eine Liste zurück
|
||||
if isinstance(data, list) and len(data) > 0:
|
||||
kv_pair = data[0]
|
||||
raw_value = kv_pair.get("Value")
|
||||
|
||||
if not raw_value:
|
||||
print("Status: Key existiert, aber der Inhalt (Value) ist komplett leer!")
|
||||
return
|
||||
|
||||
# Base64 decodieren
|
||||
decoded_bytes = base64.b64decode(raw_value)
|
||||
state_json = json.loads(decoded_bytes.decode('utf-8'))
|
||||
|
||||
# Schöne, strukturierte JSON-Ausgabe auf der Konsole
|
||||
print("SUCCESS: Daten erfolgreich geladen und decodiert!\n")
|
||||
print(json.dumps(state_json, indent=2))
|
||||
|
||||
else:
|
||||
print("Status: Unerwartetes Antwortformat von Consul.")
|
||||
|
||||
except urllib.error.HTTPError as e:
|
||||
if e.code == 404:
|
||||
print(f"ERROR: Key 'terraform/states/{repo_name}' wurde in Consul nicht gefunden (404).")
|
||||
print("Wurde die Pipeline für dieses Repo seit dem Umbau schon gestartet?")
|
||||
else:
|
||||
print(f"HTTP Fehler: {e.code}")
|
||||
except Exception as e:
|
||||
print(f"Allgemeiner Fehler: {str(e)}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Standardmässig prüfen wir boday_tf, man kann aber auch ein Argument übergeben
|
||||
repo = sys.argv[1] if len(sys.argv) > 1 else "boday_tf"
|
||||
check_state(repo)
|
||||
1
showlogs.sh
Normal file
1
showlogs.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
docker exec -it local-k3s-platform kubectl logs -l app=cloudmon --tail=50
|
||||
Loading…
Reference in a new issue