#!/usr/bin/perl -w
##########################################################################
# $Id: automount,v 1.1 2002/03/29 15:32:14 kirk Exp $
##########################################################################
# $Log: automount,v $
# Revision 1.1  2002/03/29 15:32:14  kirk
# Added some filters found in RH's release
#
# Revision 1.1  2000/15/04 11:19:33  gerald
# Added support for a few more messages...
#
# First Version 1.0  2000/07/04 00:53:43  gerald
#
##########################################################################

########################################################
# This was written and is maintained by:
#    Gerald Teschl <gerald@esi.ac.at>
#
# Please send all comments, suggestions, bug reports,
#    etc, to gerald@esi.ac.at and kirk@kaybee.org.
#
########################################################

$Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'};

while (defined($ThisLine = <STDIN>)) {
    if ( ($ThisLine =~ /^using kernel protocol version .*$/) or
	($ThisLine =~ /^expired .*$/) or
	($ThisLine =~ /^>> mount: .*$/) ) {
	# don't care about these
    }
    elsif ( ($ThisMount) = ($ThisLine =~ /^attempting to mount entry (.*)$/) ) {
	# store Mount
	$Mount= $ThisMount;
	$MountAttempts++;
    }
    elsif ($ThisLine =~ /^mount\(nfs\): nfs: mount failure .*:.* on .*$/) {
	$Failed{$Mount}{'nfsm'}++;
    }
    elsif ($ThisLine =~ /^mount\(nfs\): entry .* lookup failure$/) {
	$Failed{$Mount}{'nfsl'}++;
    }
    elsif ( $ThisLine =~ /^mount\(generic\): failed to mount .* on .*$/) {
	$Failed{$Mount}{'mnt'}++;
    }
    elsif ( ($ThisMount) = ( $ThisLine =~ /^(.*): mount failed!$/) ) {
	$FailedStartup{$ThisMount}++;
    }
    elsif ( $ThisLine =~ /^lookup\(file\): lookup for .* failed$/) {
	$Failed{$Mount}{'file'}++;
    }
    elsif ( ($ThisMount) = ($ThisLine =~ /^starting automounter version .* path = (.*), maptype = .*, mapname = .*$/) ) {
	$StartStop{$ThisMount}{'start'}++;
    }
    elsif ( ($ThisMount) = ($ThisLine =~ /^shutting down, path = (.*)$/) ) {
	$StartStop{$ThisMount}{'stop'}++;
    }
    else {
	# Report any unmatched entries...
	chomp($ThisLine);
	$OtherList{$ThisLine}++;
    }
}

if ( ($#OtherList >= 0) or (keys %Failed) ) {

    print "\n\n --------------------- Automount Begin ------------------------ \n";
 
    if (keys %FailedStartup) {
	print "\nFailed Startups:\n";
	foreach $ThisOne (keys %FailedStartup) {
	    print "   $ThisOne       " . $FailedStartup{$ThisOne} . " Time(s)\n";
	}
    }

    if (keys %Failed) {
	print "\nFailed mounts:\n";
	foreach $ThisOne (keys %Failed) {
	    print "   $ThisOne       ";
	    if ($Failed{$ThisOne}{'nfsm'}) {
	    	print "NFS Mount Failure $Failed{$ThisOne}{'nfsm'} Time(s)"; }
	    if ($Failed{$ThisOne}{'nfsl'}) {
	    	print "NFS Lookup Failure $Failed{$ThisOne}{'nfsl'} Time(s)"; }
	    if ($Failed{$ThisOne}{'mnt'}) {
	    	print "Mount Failure $Failed{$ThisOne}{'mnt'} Time(s)"; }
	    if ($Failed{$ThisOne}{'file'}) {
	    	print "File Lookup Failure $Failed{$ThisOne}{'file'} Time(s)"; }
	    print "\n";
	}
    }

    if ( ($Detail >= 10) and (keys %StartStop) ) {
	print "\nStatistics:\n";
	print "   Total number of mount attempts: $MountAttempts\n";
	foreach $ThisOne (keys %StartStop) {
	    print "   $ThisOne: Started $StartStop{$ThisOne}{'start'} and stopped $StartStop{$ThisOne}{'stop'} Time(s)\n";
	}
    }

    if (keys %OtherList) {     print "\n**Unmatched Entries**\n";
	foreach $ThisOne (keys %OtherList) {
     	  print "$ThisOne: $OtherList{$ThisOne} Time(s)\n";
     	}
    }                                                                               	
    print "\n\n ---------------------- Automount End ------------------------- \n\n";

}
    
exit(0);



