[Logwatch-Devel] patch to sendmail-largeboxes 1.6 + logwatch.pl --splithosts bug

David Baldwin david.baldwin at anu.edu.au
Tue Dec 6 00:00:52 MST 2005


Removes report generation for non-local hosts when --splithosts is in effect, 
and adds a few extras as below. Would be useful to have a function in 
Logwatch.pm to exit if LOGWATCH_ONLYHOST is non-local for general use by zz-* 
scripts.

There is a --splithosts bug in logwatch.pl - try
# logwatch --splithosts --service sendmail-largeboxes

Doesn't generate the 'hostlist' file since no logfiles to process for only that 
service. A klugy workaround would be to initialize 'hostlist' with the name of 
the local host, but it shouldn't be too hard to detect the file doesn't exist 
and run reports anyway without LOGWATCH_ONLYHOST set.

Anyway, the patch does a few things:
* removes report generation for non-local hosts when --splithosts is in effect.
* generates a header saying what the threshold size is
* adds a configurable mailbox size threshold option in 
conf/sevices/sendmail-largeboxes.conf - this can be specified in bytes (default) 
or with KB, MB or GB appended.
* adds a title in conf/sevices/sendmail-largeboxes.conf - this was a pain 
previously because the report just appeared without titles. Maybe the default 
title should be the service name for all reports if none specified?

One useful side effect is that you can set the threshold to 0 - this is useful 
for a server where all mail should be relayed elsewhere, but an account may be 
missed. If it was 'root' for example you would know it sooner rather than later.

David.
-- 
=====================================================================+
David Baldwin                   mailto:David.Baldwin at anu.edu.au      |
Supercomputer Facility          URL: http://www.anu.edu.au/~u8611156 |
II Services, Huxley Building    Ph:  {intl+61+2 | (02)} 6125 0321    |
Australian National University  FAX: {intl+61+2 | (02)} 6125 8199    |
Canberra ACT 0200, AUSTRALIA  *======================================+
-------------- next part --------------
--- scripts/services/sendmail-largeboxes        24 Feb 2005 17:08:05 -0000      1.6
+++ scripts/services/sendmail-largeboxes        5 Dec 2005 23:25:41 -0000
@@ -2,11 +2,34 @@
 # $Id: sendmail-largeboxes,v 1.6 2005/02/24 17:08:05 kirk Exp $
 ##########################################################################
 
+use strict;
+use POSIX;
+
+my $SPOOLDIR = '';
+my $sizethresh = defined $ENV{sendmail_largeboxes_size} ? uc $ENV{sendmail_largeboxes_size} : 40960000;
+my $title = "Large Mailbox threshold: $sizethresh";
+my $sizebytes = $sizethresh;
+if ($sizethresh =~ /^(\d+)TB?$/i) {
+  $sizebytes = $1 * 1024 ** 4;
+} elsif ($sizethresh =~ /^(\d+)GB?$/i) {
+  $sizebytes = $1 * 1024 ** 3;
+} elsif ($sizethresh =~ /^(\d+)MB?$/i) {
+  $sizebytes = $1 * 1024 ** 2;
+} elsif ($sizethresh =~ /^(\d+)KB?$/i) {
+  $sizebytes = $1 * 1024;
+}
+$title .= ($sizethresh ne $sizebytes) ? " ($sizebytes bytes)\n" : "\n";
+
+# $hostname may be fully-qualified name
+my ($OSname, $hostname, $release, $version, $machine) = POSIX::uname();
+$hostname =~ s/\..*//;
+exit (0) if ($ENV{'LOGWATCH_ONLY_HOSTNAME'} and ($ENV{'LOGWATCH_ONLY_HOSTNAME'} ne $hostname));
+
 if (-e "/var/mail") {
        $SPOOLDIR = "/var/mail";
-       } elsif ( -e "/var/spool/mail") {
+} elsif ( -e "/var/spool/mail") {
        $SPOOLDIR = "/var/spool/mail";
-       } else {
+} else {
        print "Can't find spool directory\n";
 }
 
@@ -17,8 +40,9 @@
 
        for my $filename (@files) {
                my $checksize = (stat("$SPOOLDIR/$filename"))[7];
-               if ($checksize > 40960000) { #This is 40MBish should probably be a configurable -mgt
-                       print "Warning: Large mailbox: $filename ($checksize)\n";
+               if ($checksize >= $sizebytes) {
+                       print "$title Warning: Large mailbox: $filename ($checksize)\n";
+                       $title = "";  # only print at start of report
                }
        }
 }
--- conf/services/sendmail-largeboxes.conf      24 Feb 2005 17:05:20 -0000      1.4
+++ conf/services/sendmail-largeboxes.conf      5 Dec 2005 23:25:40 -0000
@@ -17,9 +17,17 @@
 # Yes = True  = On  = 1
 # No  = False = Off = 0
 
+# service title
+Title = "sendmail-largeboxes (large mail spool files)"
+
 # Which logfile group...
 LogFile = NONE
 
+# Mailbox size threshold
+#   can add units KB, MB, GB, TB
+#   can set to 0 to report spool files being created where they shouldn't
+
+$sendmail_largeboxes_size = 40MB
 ########################################################
 # This was written and is maintained by:
 #    Colin Smith <Colin.Smith at fantasie.org.uk>


More information about the Logwatch-Devel mailing list