Linux operating system and many applications create special files commonly referred to as “logs” to record their operational events. These system logs or application-specific log files are an essential tool when it comes to understanding and troubleshooting the behavior of the operating system and third-party applications. However, log files are not precisely what you would call “light” or “easy” reading, and analyzing raw log files by hand is often time-consuming and tedious. For that reason, any utility that can convert raw log files into a more user-friendly log digest is a great boon for sysadmins.
logwatch is an open-source log parser and analyzer written in Perl, which can parse and convert raw log files into a structured format, making a customizable report based on your use cases and requirements. In logwatch, the focus is on producing more easily consumable log summary, not on real-time log processing and monitoring. As such, logwatch is typically invoked as an automated cron task with desired time and frequency, or manually from the command line whenever log processing is needed. Once a log report is generated, logwatch can email the report to you, save it to a file, or display it on the screen.
A logwatch report is fully customizable in terms of verbosity and processing coverage. The log processing engine of logwatch is extensible, in a sense that if you want to enable logwatch for a new application, you can write a log processing script (in Perl) for the application’s log file, and plug it under logwatch.
One downside of logwatch is that it does not include in its report detailed timestamp information available in original log files. You will only know that a particular event was logged in a requested range of time, and you will have to access original log files to get exact timing information.
Installing Logwatch
On Debian and derivatives:
# aptitude install logwatch
On Red Hat-based distributions:
# yum install logwatch
Configuring Logwatch
During installation, the main configuration file (logwatch.conf
) is placed in /etc/logwatch/conf. Configuration options defined in this file override system-wide settings defined in /usr/share/logwatch/default.conf/logwatch.conf
.
If logwatch is launched from the command line without any arguments, the custom options defined in /etc/logwatch/conf/logwatch.conf
will be used. However, if any command-line arguments are specified with logwatch command, those arguments in turn override any default/custom settings in /etc/logwatch/conf/logwatch.conf
.
In this article, we will customize several default settings of logwatch by editing /etc/logwatch/conf/logwatch.conf
file.
Detail = <Low, Med, High, or a number>
“Detail” directive controls the verbosity of a logwatch report. It can be a positive integer, or High, Med, Low, which correspond to 10, 5, and 0, respectively.
MailTo = youremailaddress@yourdomain.com
“MailTo” directive is used if you want to have a logwatch report emailed to you. To send a logwatch report to multiple recipients, you can specify their email addresses separated with a space. To be able to use this directive, however, you will need to configure a local mail transfer agent (MTA) such as sendmail or Postfix on the server where logwatch is running.
Range = <Yesterday|Today|All>
“Range” directive specifies the time duration of a logwatch report. Common values for this directive are Yesterday, Today or All. When “Range = All
” is used, “Archive = yes
” directive is also needed, so that all archived versions of a given log file (e.g., /var/log/maillog
, /var/log/maillog.X
, or /var/log/maillog.X.gz
) are processed.
Besides such common range values, you can also use more complex range options such as the following.
- Range = “2 hours ago for that hour”
- Range = “-5 days”
- Range = “between -7 days and -3 days”
- Range = “since September 15, 2014”
- Range = “first Friday in October”
- Range = “2014/10/15 12:50:15 for that second”
To be able to use such free-form range examples, you need to install Date::Manip Perl module from CPAN. Refer to this post for CPAN module installation instructions.
Service = <service-name-1>
Service = <service-name-2>
. . .
“Service” option specifies one or more services to monitor using logwath. All available services are listed in /usr/share/logwatch/scripts/services, which cover essential system services (e.g., pam, secure, iptables, syslogd), as well as popular application services such as sudo, sshd, http, fail2ban, samba. If you want to add a new service to the list, you will have to write a corresponding log processing Perl script, and place it in this directory.
If this option is used to select specific services, you need to comment out the line “Service = All” in /usr/share/logwatch/default.conf/logwatch.conf.

Format = <text|html>
“Format” directive specifies the format (e.g., text or HTML) of a logwatch report.
Output = <file|mail|stdout>
“Output” directive indicates where a logwatch report should be sent. It can be saved to a file (file), emailed (mail), or shown to screen (stdout).
Lire la suite…