Create forward-logs.sh

Signed-off-by: lii5a <liisa.tallinn@gmail.com>
This commit is contained in:
lii5a 2026-02-05 11:50:30 +02:00 committed by GitHub
parent 102107281e
commit 9ab6c941f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

23
forward-logs.sh Normal file
View file

@ -0,0 +1,23 @@
#!/bin/bash
LOGFILE="/app/logs/app.log"
INGEST_URL="$OPENPIPELINE_URL"
TOKEN="$OPENPIPELINE_TOKEN"
echo "Starting log forwarder..."
echo "Sending logs from $LOGFILE to $INGEST_URL"
mkdir -p /app/logs
touch "$LOGFILE"
tail -F "$LOGFILE" | while read line; do
TIMESTAMP=$(date -Iseconds)
JSON=$(printf '{"timestamp":"%s","message":%s,"source":"petclinic","location":"tallinn"}' \
"$TIMESTAMP" "$(printf '%s' "$line" | jq -Rs)")
curl -s -X POST "$INGEST_URL" \
-H "Authorization: Api-Token $TOKEN" \
-H "Content-Type: application/json" \
-d "$JSON" > /dev/null
done