Customizing Logwatch

From Research
Jump to navigation Jump to search

There are two basic customizations we often perform:

  1. increase the header-information with machine-specific info (hardware, admininstrator(s), usage, etc):
  2. adjust the order of the information - we care very much about disk-usage, and prefer it first

Start by ensuring logwatch is actually installed! A mail-transport agent (MTA) like Postfix or nullmailer must be installed and working (to receive the daily logwatch summary).

Logwatch Headers

Use this template, to create /usr/share/logwatch/custom_header (ASCII, plain-text file; previous Gentoo and other distributions used /etc/log.d/custom_header).

Machine info:  Pentium4 2.4GHz, 1GB, GigE, 40GB+120GB, RivaTNT
 Running RedHat 9 Linux
 Located in Podium shared server-room, SFU Surrey campus
 Used by John Doe <john_doe@sfu.ca>
 Into service xxx.  Re-purposed Dec. 15, 2004
 Administered by Gordon Pritchard <gordonp+corsair@sfu.ca>
 Administered by Justin Thomas <Justin_Thomas@sfu.ca>

Another example:

Machine info:  Pentium4 dual-core 3GHz, 2GB, GigE, 80GB, ATI-R300-mobility
 Running Gentoo Linux
 Located in office  525 / The Axis (Beta Space, Surrey Campus)
 Used by Gordon Pritchard <gordonp+zero@sfu.ca)
 Into service September 6, 2005.
 Administered by Gordon Pritchard <gordonp+zero@sfu.ca>



To include this custom header, we now have to modify the main logwatch Perl script logwatch.pl. To help remember which machines have up-to-date kernels, we want logwatch to assist us by printing the kernel-version in the header. Using a Gentoo example, add the bold / red lines to /usr/sbin/logwatch.pl:

  output( $index_par, "\n ################### Logwatch $Version ($VDate) #################### \n", "line");
  }
 
  output( $index_par, "       Processing Initiated: " . localtime(time) . "\n", "line");
  output( $index_par, "       Date Range Processed: $Config{'range'}\n", "line");
  output( $index_par, "                             $print_range\n", "line") if ($Config{'range'} ne 'all');
  output( $index_par, "                             Period is " . GetPeriod() . ".\n", "line")
     if ($Config{'range'} ne 'all');
  output( $index_par, "     Detail Level of Output: $Config{'detail'}\n", "line");
  output( $index_par, "             Type of Output: $Config{'output'}\n", "line");
  output( $index_par, "          Logfiles for Host: $Config{'hostname'}\n", "line");
  output( $index_par, "                     Kernel: " . `/bin/uname -r` . "\n", "line");
  output( $index_par, "\n" . `/bin/cat  $BaseDir/custom_header` . "\n", "line");
  
  if ( $outtype_html ) {
     output( $index_par, "\n", "stop");
  } else {
     output( $index_par, "################################################################## \n", "line");


  • on a RedHat 9 machine, this file is /etc/log.d/scripts/logwatch.pl:
   $printing = 'y';
   print OUTFILE "\n ################### LogWatch $Version ($VDate) #################### \n";
   print OUTFILE "       Processing Initiated: " . localtime(time) . "\n";
   print OUTFILE "       Date Range Processed: $Config{'range'}\n";
   print OUTFILE "     Detail Level of Output: $Config{'detail'}\n";
   print OUTFILE "          Logfiles for Host: $Config{'hostname'}\n";
   print OUTFILE "\n" . `/bin/cat  $BaseDir/custom_header` .  "\n";
   print OUTFILE "################################################################ \n\n";
}




Logwatch Information Order

The scripts located in /etc/log.d/scripts/services/ are run according to their file-name ordering. Simply renaming a file changes it's relationship to other information. We should move zz-disk_space to aa-disk_space to have our disk-usage appear right after the custom header; as root:

zero services # mv /usr/share/logwatch/scripts/services/zz-disk_space /usr/share/logwatch/scripts/services/aa-disk_space

One more thing to do - there is a corresponding configuration file which we simply move (rename) to align with the above:

  • Current Gentoo shown:
zero # mv /usr/share/logwatch/default.conf/services/zz-disk_space.conf /usr/share/logwatch/default.conf/services/aa-disk_space.conf

To test it all, invoke the daily logwatch cron-job manually (Gentoo shown; others similar):

zero # sh /etc/cron.daily/00-logwatch