Sophie

Sophie

distrib > Mandriva > 2008.1 > i586 > by-pkgid > e28667f4e1cf50e0b002c8a83e0e0d6f > files > 248

logwatch-7.3.6-2mdv2008.1.noarch.rpm


##########################################################################
# $Id: xntpd,v 1.16 2007/04/16 03:11:11 bjorn Exp $
##########################################################################
# $Log: xntpd,v $
# Revision 1.16  2007/04/16 03:11:11  bjorn
# Modified filtering for Listening entries to accommodate interface numbers.
#
# Revision 1.15  2007/04/16 02:34:27  bjorn
# Filtering Listening...Disabled statements.
#
# Revision 1.14  2007/02/17 19:36:11  bjorn
# Reverting back to version 1.12 - ignore changes to 1.13.
#
# Revision 1.13  2007/02/17 16:28:44  bjorn
# Deleted superfluous lines - probably from malformed diff.
#
# Revision 1.12  2007/02/16 03:57:50  bjorn
# Additional filtering, by Ivana Varekova.
#
# Revision 1.11  2005/11/01 15:01:40  bjorn
# Adjustment to synchronized messages in Solaris, by David Baldwin
#
# Revision 1.10  2005/10/19 05:45:12  bjorn
# Filtering redundant failed message, by David Baldwin
#
# Revision 1.9  2005/10/19 05:35:30  bjorn
# Code cleanup, better handling of Unmatched, and additional filtering, by
# David Baldwin
#
# Revision 1.8  2005/10/02 15:00:34  bjorn
# Corrections to last commit
#
# Revision 1.7  2005/10/01 18:30:12  bjorn
# Added filtering for listening and synchronized statements, by Gilles Detillieux
#
# Revision 1.6  2005/09/28 17:39:04  mike
# Patch from David Baldwin, plus a few other tweaks -mgt
#
# Revision 1.5  2005/07/05 22:16:23  mike
# Small patch from Paul Chambers -mgt
#
# Revision 1.4  2005/05/23 17:35:55  bjorn
# Patch for an older ntpd (4.1.1a-9), by Michael Evans
#
# Revision 1.3  2005/05/04 15:52:51  bjorn
# Removed shell path to perl in first line
#
# Revision 1.2  2005/02/24 17:08:05  kirk
# Applying consolidated patches from Mike Tremaine
#
# Revision 1.2  2005/02/16 00:43:28  mgt
# Added #vi tag to everything, updated ignore.conf with comments, added emerge and netopia to the tree from Laurent -mgt
#
# Revision 1.1  2005/02/13 01:25:13  mgt
# Inital code check in from David Baldwin -mgt
#
##########################################################################

########################################################
# This was written and is maintained by:
#    David Baldwin <david.baldwin@anu.edu.au>
#
# Heavily based on sshd script
#
# Please send all comments, suggestions, bug reports,
#    etc, to david.baldwin@anu.edu.au.
########################################################

use strict;
use Logwatch ':all';

my $Debug = $ENV{'LOGWATCH_DEBUG'} || 0;
my $Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'} || 0;

my $DebugCounter = 0;
my $Starts = 0;
my $Kills = 0;
my $SyncLost = 0;
my (@TimeReset,%Interfaces,%Syncs,%TwoInst,%Errors,%OtherList);
my %ConfErrs;

# No sense in running if 'xntpd' doesn't even exist on this system...
unless (( -f "/usr/sbin/ntpd" ) or ( -f "/usr/local/sbin/ntpd") or ( -f "/usr/lib/inet/xntpd")) {
   if ( $Debug >= 5 ) {
      print STDERR "\n\nDEBUG: Exiting XNTPD Filter - no ntpd binary on system\n\n";
   }
   exit (0);
}

if ( $Debug >= 5 ) {
         print STDERR "\n\nDEBUG: Inside XNTPD Filter \n\n";
         $DebugCounter = 1;
}


while (defined(my $ThisLine = <STDIN>)) {
    if ( $Debug >= 5 ) {
       print STDERR "DEBUG($DebugCounter): $ThisLine";
       $DebugCounter++;
    }
    chomp($ThisLine);
    if ( 
        ($ThisLine =~ m/tickadj = /) or # startup
        ($ThisLine =~ m/precision = /) or # startup
        ($ThisLine =~ m/ (succeeded|failed)/) or # startup
        ($ThisLine =~ m/kernel time (discipline|sync) status/) or # startup
        ($ThisLine =~ m/kernel time sync (dis|en)abled /) or # startup
        ($ThisLine =~ m/frequency initialized/) or # startup
        ($ThisLine =~ m/using kernel phase-lock loop/) or # startup
        ($ThisLine =~ m/select([^\)]) error: Interrupted system call/) or
        ($ThisLine =~ m/signal_no_reset: signal \d+ had flags \d+/) or
        ($ThisLine =~ /Deleting interface \#[0-9] [^,]*, [^,]*, interface stats: received=.*, sent=.*, dropped=.*, active_time=.* secs/) or
        ($ThisLine =~ /Invalid argument/) or
        ($ThisLine =~ /Listening on interface .* Disabled/)
    ) {
       # Ignore these
    } elsif ($ThisLine =~ m/ntpd [\d\-\.\w@]+ ... ... .. ..:..:.. /) {
      $Starts++;
    } elsif ($ThisLine =~ m/ntpd exiting on signal/) {
      $Kills++;
    } elsif ($ThisLine =~ m/synchronisation lost/) {
      $SyncLost++;
    } elsif ( my (undef,$TimeStep) = ($ThisLine =~ /time reset(| \(step\)) ([^ ]+) s$/ )) {
       push @TimeReset, $TimeStep;
    } elsif ( my (undef,$TimeStep) = ($ThisLine =~ /(step|adjust) time server [^ ]+ offset ([^ ]+) sec$/ )) {
       push @TimeReset, $TimeStep;
# MEv start no leadin to line
    } elsif ( my (undef,$TimeStep) = ($ThisLine =~ /(offset) ([^ ]+) sec/ )) {
       push @TimeReset, $TimeStep;
# MEv end no leadin to line
    } elsif ( my ($ListenOn) = ($ThisLine =~ /Listening on interface (.*) Enabled/ )) {
       $Interfaces{$ListenOn}++;
    } elsif ( my ($SyncTo,$Stratum) = ($ThisLine =~ /synchronized to ([^ ]+), stratum[ =]([^ ]+)/ )) {
       my $name = $SyncTo;
       if ($Detail > 5 && $SyncTo =~ m/^[\d.]+$/) {
           $name = LookupIP($SyncTo);
       }
       $name .= " stratum " . $Stratum;
       $Syncs{$name}++;
    } elsif ( my ($Host) = ($ThisLine =~ /two instances of default interface for ([^ ]+) in hash table$/ )) {
       if ($Debug >= 5) {
          print STDERR "DEBUG: Found -$1 two instances of default interface\n";
       }
       my $name = LookupIP($Host);
       $TwoInst{$name}++;
    } elsif ( my ($Error) = ($ThisLine =~ /(no server(s reachable| suitable for synchronization found))/ )) {
       $Errors{$Error}++;
    } elsif ( my ($Error) = ($ThisLine =~ /(can't find host \S+|no servers can be used, exiting)/ )) {
       $Errors{$Error}++;
    } elsif ( my ($Error) = ($ThisLine =~ /(sendto\(\S+\): Network is unreachable)/ )) {
       $Errors{$Error}++;
    } elsif ( my ($Error) = ($ThisLine =~ /(getaddrinfo: "\S+" invalid host address, ignored)/ )) {
       $Errors{$Error}++;
    } elsif ( my ($Error) = ($ThisLine =~ /(frequency error \d+ PPM exceeds tolerance \d+ PPM)/ )) {
       $Errors{$Error}++;
    } elsif ( my ($ConfErr) = ($ThisLine =~ /configure: (keyword "[^"]*" unknown, line ignored)/ )) {
       $ConfErrs{$ConfErr}++;
    } else {
       # Report any unmatched entries...
       $OtherList{$ThisLine} += 1;
    }
}

###########################################################

if ($Kills) {
    print "\nXNTPD Killed: " . $Kills . " Time(s)\n";
}
if ($Starts) {
    print "\nXNTPD Started: " . $Starts . " Time(s)\n";
}
if ($SyncLost) {
    print "\nSync lost: " . $SyncLost . " Time(s)\n";
}

if (@TimeReset > 0) {
    if ($Detail > 5) {
       print "\nTime Reset\n";
       print map "  time stepped $_\n",@TimeReset;
    }
    my $t = 0;
    $t += $_ foreach @TimeReset;
    printf "\nTime Reset ".(@TimeReset)." times (total: %.6f s  average: %.6f s)\n", $t, $t/(@TimeReset);
}

if (keys %Interfaces) {
    my $t = 0;
    my $lt = 0;
    print "\nListening on interfaces:\n" if ($Detail > 5);
    foreach my $i (keys %Interfaces) {
       print "  $i - $Interfaces{$i} times\n" if ($Detail > 5);
       unless ($i =~ m/^(wildcard|lo)/) {
          $lt++;
       }
       $t++;
    }
    print "\nTotal interfaces $t (non-local: $lt)\n";
}

if (keys %Syncs) {
    my $t = 0;
    my $ht = 0;
    print "\nSynchronized to:\n" if ($Detail > 5);
    foreach my $h (keys %Syncs) {
       $ht++;
       $t += $Syncs{$h};
       print "  $h - $Syncs{$h} times\n" if ($Detail > 5);
    }
    print "\nTotal synchronizations $t (hosts: $ht)\n";
}

if (keys %TwoInst) {
    print "\nTwo instances error\n";
    foreach my $h (keys %TwoInst) {
      print "  $h - $TwoInst{$h} times\n";
    }
}

if (keys %Errors) {
    print "\nErrors\n";
    print "  $_: $Errors{$_} time(s)\n" foreach sort keys %Errors;
}

if (keys %ConfErrs) {
    print "\n Errors in configuration file\n";
    foreach my $k (keys %ConfErrs) {
      print "  $k ". $ConfErrs{$k} . " time(s)\n";
    }
}

if (keys %OtherList) {
    print "\n**Unmatched Entries**\n";
    print "  $_: $OtherList{$_} time(s)\n" foreach keys %OtherList;
}

exit(0);

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