Rsyslog Eigene Regeln: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
Die Seite wurde neu angelegt: „ =Eigene Regeln= ==Einfache Regeln== ===Programname=== *Logfile for tftpd if $programname == 'in.tftpd' then /var/log/tftpd.log ===facility-text=== *60-meinl…“
 
Keine Bearbeitungszusammenfassung
 
(Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt)
Zeile 1: Zeile 1:
=Eigene Regeln=
=Eigene Regeln=
==Einfache Regeln==
==Einfache Regeln==
Zeile 15: Zeile 14:


===contains===
===contains===
Prevent rsyslog logging to /var/log/syslog
*[[rsyslog firewall Regel]]
*10-iptables.conf
if $msg contains '-iptables-' then /var/log/firewall
& ~


==expressions in parenthesis==
==expressions in parenthesis==
Zeile 27: Zeile 23:
* and
* and
* or
* or


<b>legacy rsyslog</b>
<b>legacy rsyslog</b>
Zeile 39: Zeile 32:


Neues Format.  
Neues Format.  


Generator für eine Konfigurationsdatei: http://www.rsyslog.com/rsyslog-configuration-builder/
Generator für eine Konfigurationsdatei: http://www.rsyslog.com/rsyslog-configuration-builder/
Zeile 50: Zeile 42:
   
   
  *.*;auth,authpriv.none          /var/log/syslog;MyOwnFormat
  *.*;auth,authpriv.none          /var/log/syslog;MyOwnFormat
Im Raw format
===Logs sowohl lokal als auch remote speichern===
Um Logs sowohl lokal als auch an einen Remote-Host zu senden, kann die Konfiguration wie folgt angepasst werden:
* Beispiel: Authentifizierungs- und Sicherheitsmeldungen lokal und remote speichern
if $syslogfacility-text == 'auth' or $syslogfacility-text == 'authpriv' then {
    action(type="omfwd" target="server_host" port="514" protocol="tcp")
    action(type="omfile" file="/var/log/auth.log")
}
Ersetzen Sie `server_host` durch die IP-Adresse oder den Hostnamen des Remote-Servers.
* Beispiel: Nur Meldungen einer bestimmten Anwendung (z.B. `apache2`) senden
if $programname == 'apache2' then {
    action(type="omfwd" target="server_host" port="514" protocol="tcp")
    action(type="omfile" file="/var/log/apache2.log")
}
* Lokale Speicherung aller anderen Logs sicherstellen
*.*;auth,authpriv.none -/var/log/syslog
==Remote Logging nur für bestimmte Logs==
Um sicherzustellen, dass nur bestimmte Logs an einen Remote-Host gesendet werden, während andere Logs lokal gespeichert werden:
* Beispiel: Nur lokale3-Meldungen an den Remote-Host senden
if $syslogfacility-text == 'local3' then {
    action(type="omfwd" target="server_host" port="514" protocol="tcp")
    action(type="omfile" file="/var/log/meinelog")
}
==Remote Logging aktivieren==
Um Remote Logging zu aktivieren, muss der Server so konfiguriert sein, dass er Logs empfängt, und der Client so konfiguriert sein, dass er Logs sendet.
* Server-Host Konfiguration:
module(load="imtcp")
input(type="imtcp" port="514")
* Client-Host Konfiguration:
*.* @@server_host:514
==Testen der Konfiguration==
Um sicherzustellen, dass die Konfiguration funktioniert:
1. Senden Sie eine Testnachricht vom Client-Host:
echo "Test log message" | logger
2. Überprüfen Sie auf dem Server-Host, ob die Nachricht empfangen wurde:
tail -f /var/log/syslog
Mit diesen Beispielen und Anleitungen sollte es einfacher sein, `rsyslog` entsprechend Ihren Anforderungen zu konfigurieren.

Aktuelle Version vom 18. Juli 2024, 05:36 Uhr

Eigene Regeln

Einfache Regeln

Programname

  • Logfile for tftpd
if $programname == 'in.tftpd' then /var/log/tftpd.log

facility-text

  • 60-meinlog.conf
if $syslogfacility-text == 'local3'  then /var/log/meinelog
  • systemctl restart rsyslog.service
  • echo "Hallo Welt" | logger -p local3.warn
  • tail -n 1 -f /var/log/meinelog
Sep  5 14:21:04 bajor root: Hallo Welt

contains

expressions in parenthesis

  • not, unary minus
  • *, /, % (modulus, as in C)
  • +, -, & (string concatenation)
  • ==, !=, <>, <, >, <=, >=, contains (strings!), startswith (strings!)
  • and
  • or

legacy rsyslog

Beginnen mit einem $-Zeichen. Zum Setzen von Konfigurationsparametern.

$FileOwner syslog

RainerScript

Neues Format.

Generator für eine Konfigurationsdatei: http://www.rsyslog.com/rsyslog-configuration-builder/

Templates - Anpassen des Ausgabeformates

$template MyOwnFormat,"Debug line with all properties:\nFROMHOST: '%FROMHOST%', HOSTNAME: '%HOSTNAME%', PRI: %PRI%,\nsyslogtag '%syslogtag%',
programname: '%programname%', APP-NAME: '%APP-NAME%', PROCID: '%PROCID%', MSGID:  '%MSGID%',\nTIMESTAMP: '%TIMESTAMP%', STRUCTURED-DATA: '%STRUCTURED-DATA%',
\nmsg: '%msg%'\nescaped msg: '%msg:::drop-cc%'\nrawmsg: '%rawmsg%'\n\n"

*.*;auth,authpriv.none          /var/log/syslog;MyOwnFormat

Im Raw format

Logs sowohl lokal als auch remote speichern

Um Logs sowohl lokal als auch an einen Remote-Host zu senden, kann die Konfiguration wie folgt angepasst werden:

  • Beispiel: Authentifizierungs- und Sicherheitsmeldungen lokal und remote speichern
if $syslogfacility-text == 'auth' or $syslogfacility-text == 'authpriv' then {
    action(type="omfwd" target="server_host" port="514" protocol="tcp")
    action(type="omfile" file="/var/log/auth.log")
}

Ersetzen Sie `server_host` durch die IP-Adresse oder den Hostnamen des Remote-Servers.

  • Beispiel: Nur Meldungen einer bestimmten Anwendung (z.B. `apache2`) senden
if $programname == 'apache2' then {
    action(type="omfwd" target="server_host" port="514" protocol="tcp")
    action(type="omfile" file="/var/log/apache2.log")
}
  • Lokale Speicherung aller anderen Logs sicherstellen
  • .*;auth,authpriv.none -/var/log/syslog

Remote Logging nur für bestimmte Logs

Um sicherzustellen, dass nur bestimmte Logs an einen Remote-Host gesendet werden, während andere Logs lokal gespeichert werden:

  • Beispiel: Nur lokale3-Meldungen an den Remote-Host senden
if $syslogfacility-text == 'local3' then {
    action(type="omfwd" target="server_host" port="514" protocol="tcp")
    action(type="omfile" file="/var/log/meinelog")
}

Remote Logging aktivieren

Um Remote Logging zu aktivieren, muss der Server so konfiguriert sein, dass er Logs empfängt, und der Client so konfiguriert sein, dass er Logs sendet.

  • Server-Host Konfiguration:
module(load="imtcp")
input(type="imtcp" port="514")
  • Client-Host Konfiguration:
  • .* @@server_host:514

Testen der Konfiguration

Um sicherzustellen, dass die Konfiguration funktioniert: 1. Senden Sie eine Testnachricht vom Client-Host:

echo "Test log message" | logger

2. Überprüfen Sie auf dem Server-Host, ob die Nachricht empfangen wurde:

tail -f /var/log/syslog

Mit diesen Beispielen und Anleitungen sollte es einfacher sein, `rsyslog` entsprechend Ihren Anforderungen zu konfigurieren.