1. My Caddy version (caddy version):
2.0rc3
2. How I run Caddy:
a. System environment:
Ubuntu 20.04 LTS, installed via apt, enabled by default with systemd.
b. My complete Caddyfile or JSON config:
FQDN {
# Set this path to your site's directory.
root * /usr/share/caddy
# Enable the static file server.
file_server
log {
format json
output net unix//var/cache/caddy.socket
}
}
3. The problem I’m having:
I’d like to be able to feed the output from the access log in a custom JSON format via syslog to the matomo live log importer, with the expected json output of:
'{"ip": "$remote_addr",'
'"host": "$host",'
'"path": "$request_uri",'
'"status": "$status",'
'"referrer": "$http_referer",'
'"user_agent": "$http_user_agent",'
'"length": $bytes_sent,'
'"generation_time_milli": $request_time,'
'"date": "$time_iso8601"}';
4. What I already tried:
Output is set to JSON and sent via net unix socket to rsyslog; /etc/rsyslog.d/10-matomo.conf:
$AddUnixListenSocket /var/cache/caddy.socket
$template matomo,"%msg%\n"
if $syslogfacility-text == 'local0' then ^/usr/local/matomo/matomo.sh;matomo
/usr/local/matomo/matomo.sh:
#!/bin/sh
echo "${@}" | /usr/local/matomo/import_logs.py \
--url=https://localhost/matomo/ --token-auth=<SECRET> \
--enable-http-errors --enable-http-redirects --enable-static --enable-bots \
--idsite=1 --recorders=4 --log-format-name=nginx_json -
Of course, there is no data imported as the JSON format is not as expected. Does anyone know if this is possible? I tried getting my head around mmjsonparse to parse the incoming JSON and output the JSON as desired, but couldn’t figure out how to.
Cheers!