diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2015-04-07 08:29:34 +0000 |
---|---|---|
committer | <> | 2015-04-13 18:52:43 +0000 |
commit | b2ccf8dd31d1457ae9f0ae270054117179220370 (patch) | |
tree | 4ccd4a16d5e9ef5869630ba624e822665a6e248c /scripts/lib/NTP/Util.pm | |
parent | bdab5265fcbf3f472545073a23f8999749a9f2b9 (diff) | |
download | ntp-master.tar.gz |
Imported from /home/lorry/working-area/delta_ntp/ntp-4.2.8p2.tar.gz.HEADntp-4.2.8p2master
Diffstat (limited to 'scripts/lib/NTP/Util.pm')
-rw-r--r-- | scripts/lib/NTP/Util.pm | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/scripts/lib/NTP/Util.pm b/scripts/lib/NTP/Util.pm index 66f2453..cd2f9e5 100644 --- a/scripts/lib/NTP/Util.pm +++ b/scripts/lib/NTP/Util.pm @@ -93,18 +93,27 @@ sub do_dns { sub ntp_peers { my ($host) = @_; - my $cmd = "$ntpq_path -np $host |"; + $host ||= ''; + my $cmd = "$ntpq_path -npw $host |"; open my $fh, $cmd or croak "Could not start ntpq: $!"; <$fh> for 1 .. 2; - my @columns = qw(remote refid st t when poll reach delay offset jitter); + my @columns = qw(tally host refid st t when poll reach delay offset jitter); my @peers; while (<$fh>) { - if (/(?:[\w\.\*-]+\s*){10}/) { + if (/^([ x+#*o-])((?:[\w.*:-]+\s+){10}|([\w.*:-]+\s+))$/) { my $col = 0; - push @peers, { map {; $columns[ $col++ ] => $_ } split /(?<=.)\s+/ }; + my @line = ($1, split /\s+/, $2); + if( @line == 2 ) { + defined ($_ = <$fh>) or last; + s/^\s+//; + push @line, split /\s+/; + } + my $r = { map {; $columns[ $col++ ] => $_ } @line }; + $r->{remote} = $r->{tally} . $r->{host}; + push @peers, $r; } else { #TODO return error (but not needed anywhere now) @@ -135,3 +144,5 @@ sub ntp_sntp_line { close $fh or croak "running sntp failed: $! (exit status $?)"; return ($offset, $stratum); } + +1; |