#!@@PERL@@ -w # # Plugin to monitor NTP states # # Parameters understood: # # config (required) # autoconf (optional - used by lrrd-config) # # Config variables: # # lowercase - lowercase hostnames after lookup # # $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 = lc $host if exists $ENV{"lowercase"}; $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 = lc $host if exists $ENV{"lowercase"}; $host =~ s/[\.-]/_/g; print "$host.value ", exists $stateval{$state} ? $stateval{$state} : 0, "\n"; } exit 0; # vim:syntax=perl