initial commit
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
commit
75891c3271
129 changed files with 8046 additions and 0 deletions
52
roles/goaccess/templates/goaccess-report.sh.j2
Normal file
52
roles/goaccess/templates/goaccess-report.sh.j2
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#!/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)"
|
||||
Loading…
Add table
Add a link
Reference in a new issue