# (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@@";
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/;
}
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+)(:)$/) {
# 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);
# 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( <HOSTS> ) {
+ $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 = <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