/[cricket]/parse_ntpq.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /parse_ntpq.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Fri Jul 19 07:34:38 2002 UTC (17 years, 1 month ago) by dpavlin
Branch: MAIN
File MIME type: text/plain
monitor ntp servers using ntpq (with multiple servers which has multiple
server/peers -- each ntp server has just one target file)
Based on work of Matthew.Stier@fnc.fujitsu.com

1 dpavlin 1.1 #!/usr/bin/perl -w
2    
3     # Based on work of Matthew.Stier@fnc.fujitsu.com
4    
5     use strict;
6    
7     my $gInstallRoot;
8     BEGIN {
9     $gInstallRoot = (($0 =~ m:^(.*/):)[0] || "./") . "..";
10     }
11    
12    
13     use lib "$gInstallRoot/lib";
14     use strict;
15    
16     # Test for the number of arguments
17     if ($#ARGV != 1) {
18     print STDERR "usage: $0 host peer\n";
19     exit 1;
20     }
21    
22     # Get the server
23     my($server) = shift @ARGV;
24     # Get the peer
25     my($peer) = shift @ARGV;
26    
27     my @targets;
28    
29     # Get the ntpq data
30     open(NTPQ,"/usr/bin/ntpq -pn $server |") || die "ntpq: $!";
31    
32     if ($peer eq "--config") {
33     print "target --default--\n\tserver = $server\n\n";
34     }
35    
36     my $skip_header = 1;
37     # Step through remaining lines
38     while (<NTPQ>) {
39     chomp;
40     next if (! /^=+$/ && $skip_header);
41     $skip_header = 0;
42    
43     # Break lines into fields
44     my($remote, $refid, $stratum, $t, $when, $poll, $reach,
45     $delay, $offset, $jitter) = (split ' ', substr($_, 1), 10);
46     # Print delay, offset, and jitter
47     print "$delay\n$offset\n$jitter\n" if ( $remote eq $peer );
48     if ($peer eq "--config" && $reach && $reach > 0 && $remote ne "127.127.1.1") {
49     print "target $server-$remote\n\tpeer = $remote\n\tskip-overview = 1\n\n";
50     push @targets,"$server-$remote";
51     }
52     }
53    
54     if ($peer eq "--config") {
55     print "target $server-overview\n\tmtargets = \"",join("; ",@targets),"\"";
56     }

  ViewVC Help
Powered by ViewVC 1.1.26