1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
#!@@PERL@@ -w
#
# Plugin to monitor NTP states
#
# Parameters understood:
#
# config (required)
# autoconf (optional - used by lrrd-config)
#
# $Log$
# Revision 1.2 2004/11/21 20:23:36 jimmyo
# Better autoconf handling.
#
# Revision 1.1 2004/11/21 19:35:23 jimmyo
# Corrected file name.
#
# Revision 1.2 2004/09/08 15:25:33 ilmari
# Use @@PERL@@ in all perl shebang lines.
#
# Revision 1.1 2004/01/30 15:07:38 jimmyo
# Added generic plugins ntp_ and ntp_states to manual family (SF#887000).
#
#
#
#
# Magic markers - optional - used by installation scripts and
# lrrd-config:
#
#%# family=manual
#%# capabilities=autoconf
#
use strict;
use Net::hostent;
use Socket;
my %stateval = (
' ' => 1, # reject
'x' => 2, # falsetick
'.' => 3, # excess
'-' => 4, # outlyer
'+' => 5, # candidate
'#' => 6, # selected
'*' => 7, # sys.peer
'o' => 8, # pps.peer
);
if ($ARGV[0] and $ARGV[0] eq "autoconf") {
`ntpq -c help >/dev/null 2>/dev/null`;
if ($? eq "0") {
if (`ntpq -c "hostnames no" -c peers | wc -l` > 0) {
print "yes\n";
exit 0;
} else {
print "no (could not read peer list)\n";
exit 0;
}
} else {
print "no (ntpq not found)\n";
exit 1;
}
}
if ($ARGV[0] and $ARGV[0] eq "config") {
print "graph_title NTP states\n";
print "graph_args --base 1000 --vertical-label msec --lower-limit 0\n";
foreach (`ntpq -c "hostnames no" -c peers`) {
next unless /^.(\d+\.\d+\.\d+\.\d+)/;
next if /^.224\.0\.1\.1/;
my $addr = $1;
my $host = gethostbyaddr(inet_aton($addr));
$host = defined $host ? $host->name : $addr;
my $name = $host;
$host =~ s/[\.-]/_/g;
print "$host.label $name\n";
print "$host.draw LINE2\n";
}
exit 0;
}
foreach (`ntpq -c "hostnames no" -c peers`) {
next unless /^(.)(\d+\.\d+\.\d+\.\d+)/;
next if /^.224\.0\.1\.1/;
my $state = $1;
my $addr = $2;
my $host = gethostbyaddr(inet_aton($addr));
$host = defined $host ? $host->name : $addr;
$host =~ s/[\.-]/_/g;
print "$host.value ", exists $stateval{$state} ? $stateval{$state} : 0, "\n";
}
exit 0;
# vim:syntax=perl
|