From wikistone
Jump to: navigation, search
Line 6: Line 6:
 
Log everything to remote syslog server.
 
Log everything to remote syslog server.
  
−
<pre>
 
 
<pre>
 
<pre>
 
/etc/rsyslog.d/10-logs.conf
 
/etc/rsyslog.d/10-logs.conf

Revision as of 16:33, 20 October 2024

Advanced logging to remote syslog server... Using Pi-Hole as an example source. Documenting here because the reddit and internet searches suck. GPT is hot garbage too, due to old examples being so prevalent.


Basic Log Forwarding

Log everything to remote syslog server.

/etc/rsyslog.d/10-logs.conf

# All logs to remote server
*.*        action(type="omfwd" target="10.0.0.10" port="514" protocol="udp"
                        action.resumeRetryCount="100"
                        queue.type="linkedList" queue.size="10000")


Intermediate Log Forwarding

Forward all text logs from Pi-Hole to remote syslog server.

/etc/rsyslog.d/90-pihole.conf

# Pi-Hole logs to remote server
local1.*        action(type="omfwd" target="10.0.0.10" port="514" protocol="udp"
                        action.resumeRetryCount="100"
                        queue.type="linkedList" queue.size="10000")

# Define log sources:
module(load="imfile" PollingInterval="30")
input(type="imfile" File="/var/log/pihole/pihole.log"
        Tag="pihole"
        PersistStateInterval="100"
        Severity="notice"
        Facility="local1"
        reopenOnTruncate="on")
input(type="imfile" File="/var/log/pihole/pihole-FTL.log"
        Tag="piFTL"
        PersistStateInterval="100"
        Severity="info"
        Facility="local1"
        reopenOnTruncate="on")


Advanced Log Forwarding

Alternatively, just queries from the Pi-Hole log.

/etc/rsyslog.d/90-pihole.conf

# Pi-Hole query logs to remote server
if $syslogfacility-text == 'local1' and $msg contains 'query' then {
        action(type="omfwd" target="10.0.0.10" port="514" protocol="udp" action.resumeRetryCount="100" queue.type="linkedList" queue.size="10000")
        stop
}

module(load="imfile" PollingInterval="30")
input(type="imfile" File="/var/log/pihole/pihole.log"
        Tag="pihole"
        PersistStateInterval="100"
        Severity="notice"
        Facility="local1"
        reopenOnTruncate="on")


Parameters

Parameter Description
Tag The program tag.
PersistStateInterval=[n] Replaces state file, requires number of lines between updates. Default 0 is close of file. (crappy) Lower number means more processing. Higher means fewer updates.
Severity Severity level :: {emerg,alert,crit,err,warning,notice,info,debug} :: {0..7}
Facility syslog facility :: {local[0..15]} :: {0..15}
reopenOnTruncate Re-opens file after it is closed and rotated.


Read Permissions

Ensure rsyslog can read the file. For example, with pi-hole logs, the syslog user needs to be a member of the pihole group.

Error

me@pihole:~$ sudo systemctl status rsyslog
...
Feb 32 00:11:22 pihole rsyslogd[33324]: imfile: error accessing file '/var/log/pihole/pihole.log': Permission denied [v8.2001.0]

Fix

/etc/group
...
pihole:x:997:www-data,syslog


References

https://rsyslog.readthedocs.io/en/latest/configuration/filters.html

https://rsyslog.readthedocs.io/en/latest/configuration/modules/imfile.html

https://www.rsyslog.com/doc/configuration/modules/imfile.html#persiststateinterval

.