
##########################################################################
# $Id: kernel,v 1.30 2005/07/25 22:17:31 bjorn Exp $
##########################################################################
# $Log: kernel,v $
# Revision 1.30  2005/07/25 22:17:31  bjorn
# Moved iptables (and ipchains, ipfwadm) code to its own service (iptables).
#
# Revision 1.29  2005/06/07 18:14:50  bjorn
# Filtering out audit statements, since we now have an "audit" service.
##########################################################################
# Kernel script for LogWatch 
#
# Visit the LogWatch website at
#   http://www.logwatch.org
##########################################################################

use Logwatch ':ip';

$Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'} || 0;

while (defined($ThisLine = <STDIN>)) {
   chomp($ThisLine);
   next if ($ThisLine eq '');

   if (
      # filter out audit messages - these should be parsed by the audit
      # service
      ($ThisLine =~ /^\s*audit\(/)
      # following now in iptables service
      or ($ThisLine =~ /^Packet log: .*PROTO=/)
      or ($ThisLine =~ /IN=.*OUT=.*SRC=.*DST=.*PROTO=/)
      ) { # ignore the above strings
   } elsif ( ($from,$on) = ( $ThisLine =~ /^Warning: possible SYN flood from ([^ ]+) on ([^ ]+):.+ Sending cookies/ ) ) {
      $Fullfrom = LookupIP($from);
      $Fullon = LookupIP($on);
      $SYNflood{$Fullon}{$Fullfrom}++;
   } elsif ($ThisLine =~ /continuing in degraded mode/) {
      print " !! RAID ERROR !!\n$ThisLine\n";
   } elsif ( ( $errormsg ) = ( $ThisLine =~ /(.*?[Ee]rror.{0,17})/ ) ) {
      # filter out smb open/read errors cased by insufficient permissions
      $SkipError = 0;
      $SkipError = 1 if $ThisLine =~ /smb_readpage_sync: .*open failed, error=-13/;
      $SkipError = 1 if $ThisLine =~ /smb_open: .* open failed, result=-13/;
      $SkipError = 1 if $ThisLine =~ /smb_open: .* open failed, error=-13/;
      $Errors{$errormsg}++ if ( (! $SkipError) || ($Detail > 8));
   }
   # OTHER  
   else {
      # XXX For now, going to ignore all other kernel messages as there
      # XXX are practically an infinite number and most of them are obviously
      # XXX not parsed here at this time.
      # filter out smb open/read errors cased by insufficient permissions
      $SkipError = 0;
      $SkipError = 1 if $ThisLine =~ /smb_readpage_sync: .*open failed, error=-13/;
      $SkipError = 1 if $ThisLine =~ /smb_open: .* open failed, result=-13/;
      $SkipError = 1 if $ThisLine =~ /smb_open: .* open failed, error=-13/;
      $Kernel{$ThisLine}++ if ( (! $SkipError) || ($Detail > 8)) ;
   }
}

if (keys %SYNflood) {
   print "\nWarning: SYN flood on:\n";
   foreach $ThisOne (sort compStr keys %SYNflood) {
      print "   " . $ThisOne . " from:\n";
      foreach $Next (sort compStr keys %{$SYNflood{$ThisOne}}) {
         print "      " . $Next . ": $SYNflood{$ThisOne}{$Next} Time(s)\n";   
      }      
   }
}

if (keys %Errors) {
   print "\nWARNING:  Kernel Errors Present\n";
   foreach $Thisone ( sort {$a cmp $b} keys %Errors ) {
      print "   " . $Thisone . "...:  " . $Errors{$Thisone} . " Time(s)\n";
   }
}

# OTHER
if ( ($Detail >= 5) and (keys %Kernel) ) {
   print "\n";
   foreach $ThisOne (sort {$a cmp $b} keys %Kernel) {
      print $Kernel{$ThisOne} . " Time(s): " . $ThisOne . "\n";
   }
}

exit(0);

# vi: shiftwidth=3 tabstop=3 syntax=perl et

