From: Stephen L Johnson Date: Mon, 6 Aug 2001 23:08:59 +0000 (+0000) Subject: converted program to use SafeExec module X-Git-Tag: spong-2_4_6~6 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=883fe784f374b386cd0be076bd733f0d108b790a;p=spong.git converted program to use SafeExec module --- diff --git a/src/lib/Spong/Network/plugins/check_ntp b/src/lib/Spong/Network/plugins/check_ntp index 2a97fe6..54e7df9 100755 --- a/src/lib/Spong/Network/plugins/check_ntp +++ b/src/lib/Spong/Network/plugins/check_ntp @@ -6,29 +6,33 @@ $PLUGINS{'ntp'} = \&check_ntp; # 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 ); diff --git a/src/lib/Spong/Network/plugins/check_ping b/src/lib/Spong/Network/plugins/check_ping index 096728d..21c9a55 100755 --- a/src/lib/Spong/Network/plugins/check_ping +++ b/src/lib/Spong/Network/plugins/check_ping @@ -6,55 +6,47 @@ $PLUGINS{'ping'} = \&check_ping; # 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( ) { - $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;