From 3bb7af4758057d21aeb33a6dbab32d0a2a1c01ba Mon Sep 17 00:00:00 2001 From: Simon Rieger Date: Mon, 24 Mar 2025 17:56:43 +0100 Subject: [PATCH] add convert caddy logs to gource script --- convert_caddy_logs_to_gource.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 convert_caddy_logs_to_gource.sh diff --git a/convert_caddy_logs_to_gource.sh b/convert_caddy_logs_to_gource.sh new file mode 100755 index 0000000..42b50df --- /dev/null +++ b/convert_caddy_logs_to_gource.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Pfad zur Caddy-Logdatei +CADDY_LOG_FILE="$1" + +# Überprüfen, ob die Logdatei existiert +if [ ! -f "$CADDY_LOG_FILE" ]; then + echo "Die Datei $CADDY_LOG_FILE existiert nicht." + exit 1 +fi + +# Konvertierung der Logs ins Gource-Format mit Farben für HTTP-Statuscodes +echo "Konvertiere Caddy-Logs in Gource-kompatibles Format..." +jq -r ' + .[] | + select(.msg.request.remote_ip and .msg.request.host and .msg.request.uri and .timestamp and .msg.status) | + "\(.timestamp)|\(.msg.request.remote_ip)|A|\(.msg.request.host)\(.msg.request.uri)|\( + if .msg.status >= 200 and .msg.status < 300 then "00FF00" # Grün für 2xx (Erfolg) + elif .msg.status >= 300 and .msg.status < 400 then "FFFF00" # Gelb für 3xx (Weiterleitung) + elif .msg.status >= 400 and .msg.status < 500 then "FF4500" # Orange für 4xx (Clientfehler) + elif .msg.status >= 500 then "FF0000" # Rot für 5xx (Serverfehler) + else "FFFFFF" # Weiß für unbekannte Statuscodes + end)" +' "$CADDY_LOG_FILE" | gource --realtime --log-format custom -