[Logwatch-Devel] ntpd (network time protocol daemon)

David Baldwin David.Baldwin at anu.edu.au
Mon Feb 7 15:39:07 MST 2005


Kenneth Porter wrote:
> I realized that there's no service script for the NTP daemon, ntpd. Has 
> anyone got something suitable? Here's some documentation on its log 
> messages:
> 
> <http://www.eecis.udel.edu/~mills/ntp/html/msyslog.html>

I have written something for the NTP shipped with Linux and Solaris. I sent an 
early copy to Kirk, but haven't looked at pre6 at all to see if it got included. 
I have changed it since then anyway, and just cleaned it up a little more. 
Haven't looked at the error messages list above.

I have no idea why my RH8 Linux host won't sync properly :-( It was OK for a 
while, and then lost it again.

# /usr/sbin/logwatch --print --service xntpd

  ################### LogWatch 5.2.2 (06/23/04) ####################
        Processing Initiated: Tue Feb  8 09:26:19 2005
        Date Range Processed: yesterday
      Detail Level of Output: 0
           Logfiles for Host: XXXXX
  ################################################################

  --------------------- XNTPD Begin ------------------------

XNTPD Killed: 1 Time(s)

XNTPD Started: 1 Time(s)

Sync lost: 67 Time(s)

Time Reset 65 times (total: 64.176653 s  average: 0.987333 s)

  ---------------------- XNTPD End -------------------------


  ###################### LogWatch End #########################



code below:

#!/usr/bin/perl -w
##########################################################################
# $Id: xntpd,v 1.0 2004/07/20 15:01:17 kirk Exp $
##########################################################################
# $Log: xntpd,v $
##########################################################################

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

use Logwatch ':all';

$Debug = ValueOrDefault($ENV{'LOGWATCH_DEBUG'}, 0);
$Detail = ValueOrDefault($ENV{'LOGWATCH_DETAIL_LEVEL'}, 0);

# Avoid "Use of uninitialized value" warning messages.
sub ValueOrDefault {
         my ($value, $default) = @_;
         return ($value ? $value : $default);
}

# 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")) {
         exit (0);
}

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

while (defined($ThisLine = <STDIN>)) {
    if ( $Debug >= 5 ) {
       print STDERR "DEBUG($DebugCounter): $ThisLine";
       $DebugCounter++;
    }
    chomp($ThisLine);
    if ( 0 or
        ($ThisLine =~ m/tickadj = /) or # startup
        ($ThisLine =~ m/precision = /) or # startup
        ($ThisLine =~ m/ succeeded/) or # startup
        ($ThisLine =~ m/kernel time discipline status/) or # startup
        ($ThisLine =~ m/frequency initialized/) or # startup
        ($ThisLine =~ m/using kernel phase-lock loop/) # startup
    ) {
       # Ignore these
    } elsif ($ThisLine =~ m/ntpd [\d\-\.\w@]+ ... ... .. ..:..:.. /) {
      $Starts++;
    } elsif ($ThisLine =~ m/ntpd exiting on signal/) {
      $Kills++;
    } elsif ($ThisLine =~ m/synchronisation lost/) {
      $SyncLost++;
    } elsif ( (undef,$TimeStep) = ($ThisLine =~ /time reset(| \(step\)) ([^ ]+) 
s$/ )) {
       push @TimeReset, $TimeStep;
    } elsif ( (undef,$TimeStep) = ($ThisLine =~ /(step|adjust) time server [^ ]+ 
offset ([^ ]+) sec$/ )) {
       push @TimeReset, $TimeStep;
    } elsif ( ($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";
       }
       $name = LookupIP($Host);
       $TwoInst{$name}++;
    } else {
       # Report any unmatched entries...
       push @OtherList, "$ThisLine\n";
    }
}

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

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", at TimeReset;
    }
    $t = 0;
    $t += $_ foreach @TimeReset;
    printf "\nTime Reset ".(@TimeReset)." times (total: %.6f s  average: %.6f 
s)\n", $t, $t/(@TimeReset);
}

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

if ($#OtherList >= 0) {
    print "\n**Unmatched Entries**\n";
    print @OtherList;
}

exit(0);

# vi: shiftwidth=3 tabstop=3 et


More information about the Logwatch-Devel mailing list