From: Andrew Ruthven Date: Sun, 29 Mar 2009 02:43:31 +0000 (+1300) Subject: Add ping6 as a network check. X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9074940dd9341871ccddea24f57a52cea9d38756;p=spong.git Add ping6 as a network check. --- diff --git a/src/lib/Spong/HostList.pm b/src/lib/Spong/HostList.pm index e446d54..5cc9c77 100644 --- a/src/lib/Spong/HostList.pm +++ b/src/lib/Spong/HostList.pm @@ -205,8 +205,9 @@ sub display_text { # foreach $service ( $host->service_names() ) { $services{$service}++;}} if( grep( /^ping$/, keys %main::SERVICES ) ) { push( @names, "ping" ); } + if( grep( /^ping6$/, keys %main::SERVICES ) ) { push( @names, "ping6" ); } foreach $service ( sort keys %main::SERVICES ) { - push( @names, $service ) unless $service eq "ping"; } + push( @names, $service ) unless $service =~ /ping(6)?/; } # Print the horizontal axis of the table (names of the services) @@ -318,8 +319,9 @@ sub display_html { } if( grep( /^ping$/, (@s) ) ) { push( @names, "ping" ); } + if( grep( /^ping6$/, (@s) ) ) { push( @names, "ping6" ); } foreach $service ( sort (@s) ) { - push( @names, $service ) unless $service eq "ping"; } + push( @names, $service ) unless $service =~ /ping(6)?/; } # Print the horizontal axis of the table (names of the services) diff --git a/src/lib/Spong/Network/plugins/check_ping6 b/src/lib/Spong/Network/plugins/check_ping6 new file mode 100755 index 0000000..afd94de --- /dev/null +++ b/src/lib/Spong/Network/plugins/check_ping6 @@ -0,0 +1,52 @@ +# Register the function the plugin registry +$PLUGINS{'ping6'} = \&check_ping6; + +# This routine checks connectivity. It first trys to "ping6" the machine via +# a TCP echo using the Net::Ping module, if it can't reach it via that +# mechanism, then it resorts to the command line ping program. Using the +# Net::Ping speeds things up quite a bit... + +# $Id: check_ping,v 1.10 2001/08/06 23:08:59 sljohnson Exp $ + +use Spong::SafeExec qw(safe_exec); + +sub check_ping6 { + my( $host ) = @_; + my( $color, $rt, $summary, $message ) = ( "green", "", "", "" ); + my( @down ); + + if( @{$HOSTS{$host}->{'ipv6_addr'}} ) { + @hostlist = @{$HOSTS{$host}->{'ipv6_addr'}}; + } else { + @hostlist = ( $host ); + } + + foreach $host ( @hostlist ) { + my $myping = $PING6; + my $pingok = 0; + $myping =~ s/HOST/$host/g; + + $message = safe_exec($myping); + { local $/; undef $/; + + if( $message =~ /bytes from/ ) { $pingok = 1; } + if( $message =~ /is alive/ ) { $pingok = 1; } + if( $message =~ /octets from/ ) { $pingok = 1; } + } + + if( ! $pingok ) { + $color = "red"; + $message .= "\n"; + push( @down, $host ); + } + } + + + $summary = "ping6 failed for " . join( ',', @down ) if $color eq "red"; + $summary = "ping6 ok" if $color eq "green"; + + &debug( "ping6 - $host - $color, $summary" ); + return( $color, $summary, $message ); +} + +1;