# second, it is a yellow status. If the host is not synchonized, it is red
# status
+use Spong::SafeExec qw(safe_exec);
sub check_ntp {
- my( $host ) = @_;
- my( $color, $summary, $message ) = ( "green", "ntp ok", "" );
- my( @output,$line );
-
- $message = join(//,`$NTPDATE $host 2>&1`);
- if ( $? != 0 ) {
- $color = "red"; $summary = "NTP server down";
- {
- local $/;
- undef $/;
- if ($message =~ /server (.*), stratum (.*), offset (.*), delay (.*)/) {
- my $offset = $3; my $stratum = $2;
- if ( $stratum eq "16" ) {
- $color = 'yellow';
- $summary = "Server is running, but not synchronized";
- } elsif (abs($offset) >= 1.0) {
- $color = "yellow"; $summary = "server is $offset seconds off";
- }
- }
- }
- }
+ my( $host ) = @_;
+ my( $color, $summary, $message ) = ( "green", "ntp ok", "" );
+
+ $cmd = "$NTPDATE $host 2>&1";
+
+ my $message = safe_exec($cmd);
+
+ if ( $? != 0 ) {
+ $color = "red"; $summary = "NTP server down";
+ {
+ local $/;
+ undef $/;
+ if ($message =~
+ /server (.*), stratum (.*), offset (.*), delay (.*)/) {
+ my $offset = $3; my $stratum = $2;
+ if ( $stratum eq "16" ) {
+ $color = 'yellow';
+ $summary = "Server is running, but not synchronized";
+ } elsif (abs($offset) >= 1.0) {
+ $color = "yellow"; $summary = "server is $offset seconds off";
+ }
+ }
+ }
+ }
&debug( "ntp - $host - $color, $summary" );
return( $color, $summary, $message );
# mechanism, then it resorts to the command line ping program. Using the
# Net::Ping speeds things up quite a bit...
-use Net::Ping;
+# $Id: check_ping,v 1.10 2001/08/06 23:08:59 sljohnson Exp $
+
+use Spong::SafeExec qw(safe_exec);
sub check_ping {
- my( $host ) = @_;
- my( $color, $rt, $summary, $message ) = ( "green", "", "", "" );
- my( @down );
-
- if( @{$HOSTS{$host}->{'ip_addr'}} ) {
- @hostlist = @{$HOSTS{$host}->{'ip_addr'}};
- } else {
- @hostlist = ( $host );
- }
-
- foreach $host ( @hostlist ) {
- my $myping = $PING;
- my $pingok = 0;
- $myping =~ s/HOST/$host/g;
-
- eval {
- local $SIG{'ALRM'} = sub { die };
- alarm(5);
-
- open( PING, "$myping 2>&1 |") || warn "can't call ping: $!";
- while( <PING> ) {
- $message .= $_;
- if( /bytes from/ ) { $pingok = 1; }
- if( /is alive/ ) { $pingok = 1; }
- if( /octets from/ ) { $pingok = 1; }
- }
-
- alarm(0);
- close PING;
- };
- close PING;
- alarm(0);
-
- if( ! $pingok ) {
- $color = "red";
- $message .= "\n";
- push( @down, $host );
- }
-
- }
-
- $summary = "ping failed for " . join( ',', @down ) if $color eq "red";
- $summary = "ping ok" if $color eq "green";
+ my( $host ) = @_;
+ my( $color, $rt, $summary, $message ) = ( "green", "", "", "" );
+ my( @down );
+
+ if( @{$HOSTS{$host}->{'ip_addr'}} ) {
+ @hostlist = @{$HOSTS{$host}->{'ip_addr'}};
+ } else {
+ @hostlist = ( $host );
+ }
+
+ foreach $host ( @hostlist ) {
+ my $myping = $PING;
+ 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 = "ping failed for " . join( ',', @down ) if $color eq "red";
+ $summary = "ping ok" if $color eq "green";
- &debug( "ping - $host - $color, $summary" );
- return( $color, $summary, $message );
+ &debug( "ping - $host - $color, $summary" );
+ return( $color, $summary, $message );
}
1;