Hi Paul,
This is a bit ugly, and we've bastardized the original NTP monitor on Dev central but it seems to work thus far....
!/usr/bin/perl -w
use lib "/config/monitors/CPAN";
use strict;
use Net::NTP;
Add this PM to /config/monitors/CPAN/Net
use Net::IP;
require 5.005;
Derive and untaint programname.
my $programname = '/' . $0;
$programname =~ m/^.*\/([^\/]+)$/;
$programname = $1;
if ($programname eq '') {
die "Bad data in program name\n"
}
Process ID and file where it's to be stored. The format
is significant.
my $node = $ENV{"NODE_IP"};
my $port = $ENV{"NODE_PORT"};
my $pidfile = "/var/run/$programname.$node..$port.pid";
my $pid = "$$";
Maintenence. Clean up any existing EAV.
if (-f $pidfile ) {
open(PID, "<$pidfile");
my $pid = ;
close(PID);
if ( $pid ) {
chomp $pid; $pid =~ m/^(\d+)$/; $pid = $1;
if ( $pid ) {
kill 9, $pid;
}
}
unlink($pidfile);
}
Create a new maintenence file.
open(PID, ">$pidfile");
print PID $pid, "\n";
close(PID);
Create $ipv6 variable to change the $node IPv6 address
to an 'un-shortened' IPv6 address ($fullipv6)
my $ipv6 = new Net::IP ($node);
my $fullipv6 = $ipv6->ip();
Running "bigpipe db bigd.debug enable" can see "addr=2620:0:c10:f501:0:b:a20:97f6:123" when trying to test export (export
NODE_IP="2620:0:c10:f501:0:b:a20:97fa" NODE_PORT="123") - the script failed.
However, if used an IPv4 address it worked, tested on a virtual f5 debugging showed it
was using IPv4 - assumed this was because we were using partitions on production
boxes???
took off the first 6 IPv6 octets as when debugging found this was the same for all
addresses in the pool (this may be different on your box - partition name etc) - the last 2
octets of NODE-IP converted from hex to dec equalled our IPv4 addresses.
$fullipv6 =~ s/2620:0000:0c10:f501:0000:000b://;
removed the colon between the 2 last octets
$fullipv6 =~ s/://;
pulled apart the $fullipv6 string into 4 variables ready to convert into decimal
my ($v1, $v2, $v3, $v4) = unpack 'A2A2A2A2', $fullipv6;
convert each of the hex (IPv6 Octet) variables into decimal
my $ipv4v1 = hex($v1);
my $ipv4v2 = hex($v2);
my $ipv4v3 = hex($v3);
my $ipv4v4 = hex($v4);
my $dec = ".";
create the IPv4 address from the above variables with decimals
my $ipv4addy = ($ipv4v1 . $dec . $ipv4v2 . $dec . $ipv4v3 . $dec . $ipv4v4);
put in the IPv4 address in the place of the old $node variable
if (try_ntp_test($ipv4addy,$port)) {
print "OK\n";
}
unlink($pidfile);
exit(0);
substituted the $node variable with the $ipv4addy variable
sub try_ntp_test {
we just make sure we get a response
and that the server isn't a stratum
16 server (ie, it's lost it's time source).
my ($ipv4addy,$port) = @_;
my %response;
eval {
%response = get_ntp_response($ipv4addy,$port);
};
if ($@) {
return 0;
} else {
if ($response{'Stratum'} =~ /\d+/) {
changed to drop the member if their stratum was 14 or higher
if ($response{'Stratum'} >= 14) {
return 0;
} else {
and it isn't 16
return 1;
}
} else {
return 0;
}
}
}