53 lines
1.2 KiB
Text
53 lines
1.2 KiB
Text
|
|
#!/usr/bin/env bash
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
REPORTS_DIR="/srv/goaccess/reports"
|
||
|
|
DATA_DIR="/srv/goaccess/data"
|
||
|
|
CONF="/srv/goaccess/goaccess.conf"
|
||
|
|
|
||
|
|
SITES=(
|
||
|
|
{% for site in goaccess_sites %}
|
||
|
|
"{{ site }}"
|
||
|
|
{% endfor %}
|
||
|
|
)
|
||
|
|
|
||
|
|
# Fetch logs once from journald
|
||
|
|
LOGS=$(journalctl CONTAINER_NAME=caddy --since "2 hours ago" --output=cat 2>/dev/null || true)
|
||
|
|
|
||
|
|
# Skip if no logs
|
||
|
|
if [[ -z "$LOGS" ]]; then
|
||
|
|
echo "No Caddy logs found, skipping."
|
||
|
|
exit 0
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Generate per-site reports
|
||
|
|
for site in "${SITES[@]}"; do
|
||
|
|
db_path="${DATA_DIR}/${site}"
|
||
|
|
mkdir -p "$db_path"
|
||
|
|
|
||
|
|
echo "$LOGS" \
|
||
|
|
| jq -c "select(.request.host == \"${site}\")" 2>/dev/null \
|
||
|
|
| goaccess \
|
||
|
|
--log-format=CADDY \
|
||
|
|
--persist \
|
||
|
|
--restore \
|
||
|
|
--db-path="$db_path" \
|
||
|
|
-o "${REPORTS_DIR}/${site}.html" \
|
||
|
|
- || echo "Warning: GoAccess failed for ${site}"
|
||
|
|
done
|
||
|
|
|
||
|
|
# Generate combined "all sites" report
|
||
|
|
all_db="${DATA_DIR}/all"
|
||
|
|
mkdir -p "$all_db"
|
||
|
|
|
||
|
|
echo "$LOGS" \
|
||
|
|
| goaccess \
|
||
|
|
--log-format=CADDY \
|
||
|
|
--persist \
|
||
|
|
--restore \
|
||
|
|
--db-path="$all_db" \
|
||
|
|
-o "${REPORTS_DIR}/index.html" \
|
||
|
|
- || echo "Warning: GoAccess failed for combined report"
|
||
|
|
|
||
|
|
echo "Reports generated at $(date -Iseconds)"
|