From 53e70d71731817c2d47f96ef5a3b30a04a9fe19a Mon Sep 17 00:00:00 2001 From: Stephen L Johnson Date: Thu, 8 Feb 2001 22:55:37 +0000 Subject: [PATCH] fixed wrong file version in CVS tree --- src/spong-network.pl | 83 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 73 insertions(+), 10 deletions(-) diff --git a/src/spong-network.pl b/src/spong-network.pl index 07936b0..a113d97 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.30 2001/01/19 23:47:41 sljohnson Exp $ +# $Id: spong-network.pl,v 1.31 2001/02/08 22:55:37 sljohnson Exp $ use Carp; use lib "@@LIBDIR@@"; @@ -52,7 +52,7 @@ if ( ! GetOptions("debug:i" => \$debuglevel, "restart" => \$restart, Spong::Log::set_debug_context( 'debuglevel' => $debuglevel ); $me = "@@BINDIR@@/spong-network"; -$conf_file = $ARGV[0] || "@@ETCDIR@@/spong.conf"; +$conf_file = $ARGV[0] || "/usr/local/spong/etc/spong.conf"; $hosts_file = "@@ETCDIR@@/spong.hosts"; ($HOST) = gethostbyname(&Sys::Hostname::hostname()); $HOST =~ tr/A-Z/a-z/; @@ -92,7 +92,8 @@ while( 1 ) { } my $stopafter = 0; - foreach $_ ( split(/\s+/,$HOSTS{$host}->{'services'}) ) { + my $set_clear = 0; + foreach $_ ( split(/[\s,]+/,$HOSTS{$host}->{'services'}) ) { # ok...if the check has a : on the end, then stop if it # comes back negative if (/^(\w+)(:)$/) { @@ -106,19 +107,13 @@ while( 1 ) { # Reset the critical error count $HOSTS{$host}->{'service'}->{$check}->{'count'} = 0; &debug( "checking $host/$check", 9 ); - &do_check($host,$check); - - # Get the last status of the check - my $laststatus = $HOSTS{$host}{'service'}{$check}{'laststatus'} - || 'green'; - if ($stopafter && $laststatus ne 'green') { -# } &do_check($host,$check); # Get the last status of the check my $laststatus = $HOSTS{$host}{'service'}{$check}{'laststatus'} || 'green'; + if ($stopafter && $laststatus ne 'green') { debug("Check $check failed for host $host," . " skipping remaining tests", 3); @@ -452,6 +447,74 @@ 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 -- 2.30.2