Configuring logwatch for monitoring services and resources on CentOS

Datetime:2016-08-22 23:45:26          Topic: Centos           Share

If you're a linux user or systems administrator, you may find yourself curious as to the overall daily activities on a particular computer system. While there are tons of monitoring tools for linux (i.e. nagios, etc.), sometimes you just need to keep a daily archive of log overviews from a single machine, or a few machines.

If you're working with a large number of machines, then this is probably not the solution you're looking for.

I like logwatch for my workstation and master database server. It allows me to add custom scripts to monitor custom applications that aren't part of the included scripts from the yum package. Here's a brief example of how I have logwatch configured for my workstation.

Install Logwatch and a few other goodies...

sudo yum -y install logwatch perl-Sys-MemInfo perl-Sys-CPU fortune

Modify the logwatch.conf Configuration

# /usr/share/logwatch/default.conf/services/logwatch.conf
LogDir = /var/log
TmpDir = /var/cache/logwatch
MailTo = myemail@mydomain.com
MailFrom = logwatch
Print = No
Range = yesterday
Detail = 10
# exclude a specific service (example)
#Service = "-eximstats"
# monitor a specific service (example)
#Service = "mysql"
Service = All
mailer = "sendmail -t"

Add a custom script to the logwatch report.

The 'fortune' script from Kirk Bauer is always a fun example. CentOS doesn't seem to include that actual code in the file, even though it includes the file (odd decision by the package maintainer), but I managed to dig it up from a system running on an older version of Fedora, which did include the code via yum package.

sudoedit /usr/share/logwatch/scripts/services/zz-fortune
##########################################################################
# $Id: zz-fortune,v 1.14 2008/03/24 23:31:27 kirk Exp $
##########################################################################
# Named 'zz-fortune' so that it will be the last to execute...

#######################################################
## Copyright (c) 2008 Kirk Bauer
## Covered under the included MIT/X-Consortium License:
##    http://www.opensource.org/licenses/mit-license.php
## All modifications and contributions by other persons to
## this script are assumed to have been donated to the
## Logwatch project and thus assume the above copyright
## and licensing terms.  If you want to make contributions
## under your own copyright or a different license this
## must be explicitly stated in the contribution an the
## Logwatch project reserves the right to not accept such
## contributions.  If you have made significant
## contributions to this script and want to claim
## copyright please contact logwatch-devel@lists.sourceforge.net.
#########################################################

my $env = ( $ENV{'REAL_LANG'} ? "LANG=".$ENV{'REAL_LANG'}." " : "" ).
      ( $ENV{'REAL_LC_ALL'} ? "LC_ALL=".$ENV{'REAL_LC_ALL'}." " : "" );

if (($ENV{'PRINTING'} eq "y" ) && (-f "/usr/games/fortune")) {
      system("$env /usr/games/fortune");
      print "n";
}
elsif (($ENV{'PRINTING'} eq "y" ) && (-f "/usr/bin/fortune")) {
      system("$env /usr/bin/fortune");
      print "n";
}

# vi: shiftwidth=3 tabstop=3 syntax=perl et
# Local Variables:
# mode: perl
# perl-indent-level: 3
# indent-tabs-mode: nil
# End:

Verify that the crontab script works

Execute the following command, and then check your email.

/etc/cron.daily/0logwatch

If all is configured correctly, then you should receive a daily logwatch report, and inside you'll find a random 'fortune cookie' of the day.





About List