From: Stephen L Johnson Date: Fri, 19 Jan 2001 23:47:41 +0000 (+0000) Subject: fixed bug in 'skip_network_checks' logic, $HOST -> $HOSTS X-Git-Tag: spong-2_7_3~5 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df10bae593e58f6d5aa5431eff18f42a2c9d8638;p=spong.git fixed bug in 'skip_network_checks' logic, $HOST -> $HOSTS --- diff --git a/src/spong-network.pl b/src/spong-network.pl index e5e3229..07936b0 100755 --- a/src/spong-network.pl +++ b/src/spong-network.pl @@ -17,7 +17,7 @@ # (2) Converted checks to new plugin mechanism (Stephen Johnson May 28, 1999) # Added user-configurable escalation mechanism # -# $Id: spong-network.pl,v 1.29 2001/01/10 16:24:40 sljohnson Exp $ +# $Id: spong-network.pl,v 1.30 2001/01/19 23:47:41 sljohnson Exp $ use Carp; use lib "@@LIBDIR@@"; @@ -86,14 +86,13 @@ while( 1 ) { foreach $host ( @HOSTS_LIST ) { &debug( "checking network services on $host" ); - if( $HOST{$host}{'skip_network_checks'} ) { + if( $HOSTS{$host}{'skip_network_checks'} ) { &debug('skipping network checks'); next; } my $stopafter = 0; - my $set_clear = 0; - foreach $_ ( split(/[\s,]+/,$HOSTS{$host}->{'services'}) ) { + foreach $_ ( split(/\s+/,$HOSTS{$host}->{'services'}) ) { # ok...if the check has a : on the end, then stop if it # comes back negative if (/^(\w+)(:)$/) { @@ -107,11 +106,12 @@ while( 1 ) { # Reset the critical error count $HOSTS{$host}->{'service'}->{$check}->{'count'} = 0; &debug( "checking $host/$check", 9 ); + &do_check($host,$check); -# # If set_clear, set service to clear status and goto next -# if( $set_clear ) { -# set_clear( $host, $check ); -# next; + # Get the last status of the check + my $laststatus = $HOSTS{$host}{'service'}{$check}{'laststatus'} + || 'green'; + if ($stopafter && $laststatus ne 'green') { # } &do_check($host,$check); @@ -452,74 +452,6 @@ sub load_config_files { # Read in the spong.hosts file. We are a little nasty here in that we do # some junk to scan through the file so that we can maintain the order of - # the hosts as they appear in the file. - - open( HOSTS, $hosts_file ) || die "Can't load $hosts_file: $!"; - while( ) { - $evalme .= $_; - if( /^\s*%HOSTS\s*=\s*\(/ ) { $inhosts = 1; } - if( $inhosts && /^\s*[\'\"]?([^\s\'\"]+)[\'\"]?\s*\=\>\s*\{/ ) { - push( @HOSTS_LIST, $1 ); - } - } - close( HOSTS ); - eval $evalme || die "Invalid spong.hosts file: $@"; - - # Fallback, if we didn't read things correctly... - - if( sort @HOSTS_LIST != sort keys %HOSTS ) { - @HOSTS_LIST = sort keys %HOSTS; } - &debug( "host file loaded" ); -} - -# This is part of the set up code, this sets up the signal handlers, and -# handles any command line arguments that are given to us that tell us to -# signal the current running spong-server program. - -sub handle_signals { - - # Clear out signal mask in case we inherit any blocked sigs - - my $sigset = POSIX::SigSet->new; - sigprocmask(SIG_SETMASK, $sigset ); - - # Set up some signal handlers to handle our death gracefully, and also - # listen for the HUP signal, and if we se that, we re-exec ourself. - - $SIG{'QUIT'} = \&exit_handler; - $SIG{'HUP'} = \&hup_handler; - $SIG{'PIPE'} = \&pipe_handler; - - # If the user gives us the --restart or --kill flags, then we signal the - # currently running spong-network process, and tell it to either die, or - # re-exec itself (which causes it to re-read it's configuration files. - - if( $restart || $kill ) { - open( PID, "$SPONGTMP/spong-network.pid") || die "Can't find pid: $!"; - my $pid = ; chomp $pid; - close PID; - - if( $restart ) { - &debug( "telling pid $pid to restart" ); kill( 'HUP', $pid ); } - if( $kill ) { - &debug( "telling pid $pid to die" ); kill( 'QUIT', $pid );} - - exit(0); - } - - # Check to see if we are already running - &already_running() unless $nosleep; - - # Write our pid to the spong tmp directory. - - system( "echo $$ >$SPONGTMP/spong-network.pid" ) unless $nosleep; -} - - -# This routine check to see if another instance of spong-server is already -# running. If there is another instance, this instance will complain and die - -sub already_running { # if there is a PID file if ( -f "$SPONGTMP/spong-network.pid" ) { # Read the pid