# (1) Rewritten so that it answered both updates and queries (Ed Jul 22, 1997)
# (2) Added code to handle "*-purple" named status files (Stephen L Johnson Jun 03, 1999)
-
use lib "@@LIBDIR@@";
use Spong::HostList;
# updates however, as we need to send back some information. Query
# requests are simple one line messages.
- my $header = <CLIENT>; chomp $header; $header =~ s/\r//;
+ my $header = <CLIENT>; chomp $header;
my( $query, $hosts, $type, $view, $other ) =
( $header =~ /^(\w+)\s+\[([^\]]*)\]\s+(\w+)\s+(\w+)\b\s*(.*)$/ );
if( $query eq "config" ) { &show_config( @args ); }
if( $query eq "info" ) { &show_info( @args ); }
if( $query eq "service" ) { &show_service( @args, $other ); }
- if( $query eq "histservice" ) { &show_hist_service( @args, $other ); }
close( CLIENT );
select $output;
# color, then update the history table and state file as well.
if( ! -f "$SPONGDB/$host/services/$service-$color" ) {
- # Update the history file
$data = "status $time $service $color $sum\n";
&save_data( ">>", "$SPONGDB/$host/history/current", $data);
-
- if ( $STATUS_HISTORY ) {
- # Save the status update information
- $data = "timestamp $start $time\ncolor $color\n$time $sum\n$message\n";
- &save_data( ">>", "$SPONGDB/$host/history/status/$time-$service",
- $data);
- }
}
&debug( "[$$] updating status for $host/$service/$color" );
}
}
-sub show_hist_service {
- my( $hosts, $type, $view, $other ) = @_;
- my( $service, $time ) = split(/ /,$other);
- my( $h );
- eval { $h = Spong::HistoryService->new( $hosts, $service, $time ); };
- if ( $h ) {
- $h->summary();
- $h->display( $type, $view );
- } else {
- print &fmt_error($type,"Invalid request, object $hosts $other does not exist"),"\n";
- }
-}
-
if ( $cmd eq "status" ) {
- # Remove current np files if event is a change in status (i.e. dur = 0)
- if ( $duration == 0 ) {
- &remove_np_files($host,$service);
- }
-
if ($color eq 'red' && $duration != 0) {
if ( -f $smessage ) {
&debug("color is red, calling smessage for escalations");
} else {
&error( "could not send message, $smessage not found" );
}
- } } elsif ( $SEND_MESSAGE eq "RED-CHANGE" ) {
+ }
+
+ # Remove current np file if service has recovered
+ # Normally this would be done in spong-message, but spong-messsage
+ # is not called when $SEND_MESSAGE = "RED" for recovery events
+ if ( $duration == 0 && $color ne 'red' ) {
+ &remove_np_files($host,$service);
+ }
+
+ } elsif ( $SEND_MESSAGE eq "RED-CHANGE" ) {
# If status has changed and either color is red, call spong-message
if ( ( -f "$SPONGDB/$host/services/$service-red"
or $color eq "red" )