# (2) Converted checks to new plugin mechanism (Stephen Johnson May 28, 1999)
# Added user-configurable escalation mechanism
#
-# $Id: spong-network.pl,v 1.26 2000/12/19 05:27:35 sljohnson Exp $
+# $Id: spong-network.pl,v 1.27 2000/12/19 20:01:57 sljohnson Exp $
use Carp;
use lib "@@LIBDIR@@";
foreach $host ( @HOSTS_LIST ) {
&debug( "checking network services on $host" );
- foreach my $check ( split(/\s+/,$HOSTS{$host}->{'services'}) ) {
- $0 = "spong-network (checking $host/$check)";
- # Reset the critical error count
- $HOSTS{$host}->{'service'}->{$check}->{'count'} = 0;
- &debug( "checking $host/$check", 9 );
- &do_check($host,$check);
+ my $stopafter = 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+)(:)$/) {
+ $check = $1;
+ $stopafter = 1;
+ } else {
+ $check = $_;
+ }
+
+ $0 = "spong-network (checking $host/$check)";
+ # 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') {
+ debug("Check $check failed for host $host," .
+ " skipping remaining tests", 3);
+ last;
+ }
}
}
if ($crit_count < $CRIT_WARN_LEVEL) {
$color = 'yellow' if $laststatus eq 'green';
$skip_status = 1;
+ $HOSTS{$host}->{'service'}->{$service}->{'laststatus'} = 'yellow';
} else {
$HOSTS{$host}->{'service'}->{$service}->{'laststatus'} = 'red';
}
select((select(SOCK), $| = 1)[0]);
print SOCK "$data";
recv( SOCK, $line, 256, 0 ); # just grab a chunk from the service.
- alarm(0);
};
+ alarm(0);
close( SOCK ) || die "close: $!"; # close even if our alarm went off
if ( $@ =~ /^(.*) at/ ) { $err = $1; }
$services .= $service;
}
- $services = "ping $services" if ( $ping );
+ $services = "ping $services" if ( $ping && $services !~ /ping/ );
$HOSTS{$host}->{'services'} = $services;
}
}
my (%checks,$check);
foreach $host ( @HOSTS_LIST ) {
foreach $check (split(/\s+/,$HOSTS{$host}->{'services'})) {
+ # Strip any ':' from service names
+ $check =~ s/://g;
$checks{$check} = 1;
}
}