Logwatch: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
(Die Seite wurde neu angelegt: „=Prinzip von Logwatch= *'''Logwatch''' ist ein Log-Analyse-Tool, das System- und Anwendungsprotokolle automatisch auswertet. *Es generiert '''tägliche Bericht…“)
 
 
(9 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
=Prinzip von Logwatch=
+
```
*'''Logwatch''' ist ein Log-Analyse-Tool, das System- und Anwendungsprotokolle automatisch auswertet.
+
= Logwatch unter Debian 12 mit Postfix, Dovecot, Rspamd, ClamAV und Apache =
*Es generiert '''tägliche Berichte''', die per E-Mail oder in einer Datei gespeichert werden.
 
*Es kann verschiedene '''Log-Quellen''' wie Syslog, Journalctl und Anwendungslogs auswerten.
 
*Die Berichte enthalten eine Zusammenfassung von sicherheitsrelevanten Ereignissen, Fehlern und Systemaktivitäten.
 
  
=Installation von Logwatch=
+
Logwatch wertet standardmäßig klassische Logdateien unter '''/var/log''' aus. Debian 12 (Bookworm) verwendet jedoch '''journald''', welches keine Text-Logs erzeugt.
==Debian/Ubuntu==
 
*'''sudo apt update'''
 
*'''sudo apt install logwatch'''
 
  
==Red Hat/CentOS/Rocky Linux==
+
Damit Logwatch alle gewünschten Dienste auswerten kann, ist es nötig, '''rsyslog''' zusätzlich zu installieren.
*'''sudo dnf install logwatch'''
 
  
=Konfiguration von Logwatch=
+
= rsyslog installieren =
*Die Hauptkonfigurationsdatei befindet sich unter:
 
**'''/etc/logwatch/conf/logwatch.conf'''
 
*Wichtige Konfigurationsoptionen:
 
**'''Output = stdout''' (Anzeige im Terminal)
 
**'''Output = mail''' (Versand per E-Mail)
 
**'''Format = text''' (Textformat)
 
**'''Detail = Low | Medium | High''' (Detailstufe der Berichte)
 
  
=Beispiel: Logwatch-Bericht=
+
'''rsyslog''' schreibt wieder klassische Logdateien.
*Ein typischer Logwatch-Bericht sieht folgendermaßen aus:
 
<pre>
 
################### Logwatch  ####################
 
  Processing Initiated: Sun Mar 10 06:25:01 2024
 
  Detail Level: Medium
 
  =================================================
 
  ---- System Summary ----
 
  Number of logins: 10
 
  Failed login attempts: 2
 
  Disk usage:
 
    /dev/sda1: 40% used
 
  ---- SSHD Summary ----
 
  Failed SSH logins:
 
    192.168.1.100 (2 attempts)
 
  Successful SSH logins:
 
    user1 from 192.168.1.50
 
  ---- Apache Summary ----
 
  Total Accesses: 1450
 
  Errors: 10
 
</pre>
 
*Dieser Bericht enthält Informationen zu:
 
**Anmeldeversuchen
 
**Speicherauslastung
 
**SSH-Verbindungen
 
**Apache-Fehlern
 
  
=Manuelle Ausführung von Logwatch=
+
* apt install rsyslog
*'''sudo logwatch --detail High --output stdout'''
 
*Zeigt einen detaillierten Bericht direkt im Terminal an.
 
  
=E-Mail-Versand einrichten=
+
Nach der Installation werden automatisch die üblichen Logs wie '''/var/log/syslog''' und '''/var/log/mail.log''' erzeugt.
*In der Datei '''/etc/logwatch/conf/logwatch.conf''' kann die E-Mail-Adresse konfiguriert werden:
 
**'''MailTo = admin@example.com'''
 
**'''MailFrom = logwatch@server.local'''
 
*Logwatch sendet den Bericht dann täglich an die angegebene Adresse.
 
  
=Fazit=
+
= Logdateien prüfen =
*Logwatch ist ein einfaches, aber effektives Tool zur automatisierten Log-Analyse.
+
 
*Es hilft, sicherheitsrelevante Ereignisse und Systemfehler schnell zu erkennen.
+
Prüfen, ob folgende Logdateien existieren und beschrieben werden:
*Für erweiterte Anforderungen bieten moderne SIEM-Lösungen wie Wazuh oder ELK umfangreichere Analysefunktionen.
+
 
 +
* ls -l /var/log/mail.log /var/log/syslog /var/log/rspamd/rspamd.log /var/log/clamav/clamav.log /var/log/apache2/access.log /var/log/apache2/error.log
 +
 
 +
Falls '''rspamd''' und '''clamav''' keine Logs in '''/var/log''' erstellen, Konfiguration anpassen:
 +
 
 +
== Rspamd-Logging aktivieren (falls nicht aktiv) ==
 +
 
 +
Datei '''/etc/rspamd/local.d/logging.inc''' erstellen oder ergänzen:
 +
 
 +
type = "file";
 +
filename = "/var/log/rspamd/rspamd.log";
 +
level = "info";
 +
 
 +
Rspamd danach neu starten:
 +
 
 +
* systemctl restart rspamd
 +
 
 +
== ClamAV-Logging aktivieren (falls nicht aktiv) ==
 +
 
 +
Datei '''/etc/clamav/clamd.conf''' ergänzen/anpassen:
 +
 
 +
LogFile /var/log/clamav/clamav.log
 +
LogTime yes
 +
 
 +
ClamAV neu starten:
 +
 
 +
* systemctl restart clamav-daemon
 +
 
 +
= Logwatch konfigurieren =
 +
 
 +
Logwatch benötigt für '''Rspamd''' und '''ClamAV''' zusätzliche Konfigurationsdateien. '''Postfix''', '''Dovecot''' und '''Apache''' funktionieren automatisch.
 +
 
 +
== Rspamd in Logwatch integrieren ==
 +
 
 +
Konfigurationsdatei '''/etc/logwatch/conf/services/rspamd.conf''' erstellen:
 +
 
 +
Title = "Rspamd"
 +
LogFile = /var/log/rspamd/rspamd.log
 +
 
 +
Skript '''/etc/logwatch/scripts/services/rspamd''' erstellen und ausführbar machen:
 +
 
 +
#!/bin/bash
 +
grep -E "(reject|spam|greylist|action)" | sort | uniq -c | sort -nr
 +
 
 +
Ausführbar setzen:
 +
 
 +
* chmod +x /etc/logwatch/scripts/services/rspamd
 +
 
 +
== ClamAV in Logwatch integrieren ==
 +
 
 +
Konfigurationsdatei '''/etc/logwatch/conf/services/clamav.conf''' erstellen:
 +
 
 +
Title = "ClamAV"
 +
LogFile = /var/log/clamav/clamav.log
 +
 
 +
Skript '''/etc/logwatch/scripts/services/clamav''' erstellen und ausführbar machen:
 +
 
 +
#!/bin/bash
 +
grep -E "(FOUND|Infected)" | sort | uniq -c | sort -nr
 +
 
 +
Ausführbar setzen:
 +
 
 +
* chmod +x /etc/logwatch/scripts/services/clamav
 +
 
 +
== Apache in Logwatch prüfen ==
 +
 
 +
Apache wird automatisch von Logwatch ausgewertet, sofern Standardpfade verwendet werden:
 +
 
 +
* /var/log/apache2/access.log
 +
* /var/log/apache2/error.log
 +
 
 +
Keine Anpassungen nötig.
 +
 
 +
= Logwatch testen =
 +
 
 +
Ausgabe von Logwatch sofort auf der Konsole testen:
 +
 
 +
* logwatch --output stdout --detail High
 +
 
 +
Der Bericht enthält nun:
 +
* Postfix (Mail-Versand, Empfang, Fehler)
 +
* Dovecot (Logins, Authentifizierungsfehler)
 +
* Rspamd (Spam- und Greylisting-Berichte)
 +
* ClamAV (Virenmeldungen, Updates)
 +
* Apache (Zugriffe, Fehler, Warnungen)
 +
 
 +
= Hinweis zur aktuellen Situation (2025) =
 +
 
 +
Logwatch besitzt bis heute keine native Unterstützung für '''journald''', was es in Umgebungen mit reinem Journald-Logging weniger zeitgemäß macht.
 +
 
 +
Zeitgemäße Alternativen für Journald wären:
 +
 
 +
* Nutzung von '''journalctl''' direkt
 +
* Grafische Verwaltung über '''Cockpit'''
 +
* Monitoring-Stacks (Grafana mit Loki oder ELK-Stack)
 +
 
 +
Logwatch ist weiterhin nutzbar, wenn klassisches Logging (rsyslog) parallel aktiviert wird, wie oben beschrieben.
 +
```

Aktuelle Version vom 28. März 2025, 06:37 Uhr

```

Logwatch unter Debian 12 mit Postfix, Dovecot, Rspamd, ClamAV und Apache

Logwatch wertet standardmäßig klassische Logdateien unter /var/log aus. Debian 12 (Bookworm) verwendet jedoch journald, welches keine Text-Logs erzeugt.

Damit Logwatch alle gewünschten Dienste auswerten kann, ist es nötig, rsyslog zusätzlich zu installieren.

rsyslog installieren

rsyslog schreibt wieder klassische Logdateien.

  • apt install rsyslog

Nach der Installation werden automatisch die üblichen Logs wie /var/log/syslog und /var/log/mail.log erzeugt.

Logdateien prüfen

Prüfen, ob folgende Logdateien existieren und beschrieben werden:

  • ls -l /var/log/mail.log /var/log/syslog /var/log/rspamd/rspamd.log /var/log/clamav/clamav.log /var/log/apache2/access.log /var/log/apache2/error.log

Falls rspamd und clamav keine Logs in /var/log erstellen, Konfiguration anpassen:

Rspamd-Logging aktivieren (falls nicht aktiv)

Datei /etc/rspamd/local.d/logging.inc erstellen oder ergänzen:

type = "file";
filename = "/var/log/rspamd/rspamd.log";
level = "info";

Rspamd danach neu starten:

  • systemctl restart rspamd

ClamAV-Logging aktivieren (falls nicht aktiv)

Datei /etc/clamav/clamd.conf ergänzen/anpassen:

LogFile /var/log/clamav/clamav.log LogTime yes

ClamAV neu starten:

  • systemctl restart clamav-daemon

Logwatch konfigurieren

Logwatch benötigt für Rspamd und ClamAV zusätzliche Konfigurationsdateien. Postfix, Dovecot und Apache funktionieren automatisch.

Rspamd in Logwatch integrieren

Konfigurationsdatei /etc/logwatch/conf/services/rspamd.conf erstellen:

Title = "Rspamd"
LogFile = /var/log/rspamd/rspamd.log

Skript /etc/logwatch/scripts/services/rspamd erstellen und ausführbar machen:

#!/bin/bash
grep -E "(reject|spam|greylist|action)" | sort | uniq -c | sort -nr

Ausführbar setzen:

  • chmod +x /etc/logwatch/scripts/services/rspamd

ClamAV in Logwatch integrieren

Konfigurationsdatei /etc/logwatch/conf/services/clamav.conf erstellen:

Title = "ClamAV"
LogFile = /var/log/clamav/clamav.log

Skript /etc/logwatch/scripts/services/clamav erstellen und ausführbar machen:

#!/bin/bash
grep -E "(FOUND|Infected)" | sort | uniq -c | sort -nr

Ausführbar setzen:

  • chmod +x /etc/logwatch/scripts/services/clamav

Apache in Logwatch prüfen

Apache wird automatisch von Logwatch ausgewertet, sofern Standardpfade verwendet werden:

  • /var/log/apache2/access.log
  • /var/log/apache2/error.log

Keine Anpassungen nötig.

Logwatch testen

Ausgabe von Logwatch sofort auf der Konsole testen:

  • logwatch --output stdout --detail High

Der Bericht enthält nun:

  • Postfix (Mail-Versand, Empfang, Fehler)
  • Dovecot (Logins, Authentifizierungsfehler)
  • Rspamd (Spam- und Greylisting-Berichte)
  • ClamAV (Virenmeldungen, Updates)
  • Apache (Zugriffe, Fehler, Warnungen)

Hinweis zur aktuellen Situation (2025)

Logwatch besitzt bis heute keine native Unterstützung für journald, was es in Umgebungen mit reinem Journald-Logging weniger zeitgemäß macht.

Zeitgemäße Alternativen für Journald wären:

  • Nutzung von journalctl direkt
  • Grafische Verwaltung über Cockpit
  • Monitoring-Stacks (Grafana mit Loki oder ELK-Stack)

Logwatch ist weiterhin nutzbar, wenn klassisches Logging (rsyslog) parallel aktiviert wird, wie oben beschrieben. ```