24 lines
1.1 KiB
Bash
Executable file
24 lines
1.1 KiB
Bash
Executable file
#!/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 -
|