From efa39b5c51fd81ef3be85c729673663f0ab63897 Mon Sep 17 00:00:00 2001 From: Stephen L Johnson Date: Wed, 29 Dec 1999 04:30:02 +0000 Subject: [PATCH] Added code to display Status History entries using histservice command. --- src/spong-server.pl | 25 ++++++++++++++++++++++++- src/www-spong.pl | 20 ++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/spong-server.pl b/src/spong-server.pl index 8b70417..f8f6b11 100755 --- a/src/spong-server.pl +++ b/src/spong-server.pl @@ -12,6 +12,7 @@ # (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; @@ -230,7 +231,7 @@ sub listen_for_queries { # updates however, as we need to send back some information. Query # requests are simple one line messages. - my $header = ; chomp $header; + my $header = ; chomp $header; $header =~ s/\r//; my( $query, $hosts, $type, $view, $other ) = ( $header =~ /^(\w+)\s+\[([^\]]*)\]\s+(\w+)\s+(\w+)\b\s*(.*)$/ ); @@ -254,6 +255,7 @@ sub listen_for_queries { 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; @@ -318,8 +320,16 @@ sub save_status { # 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" ); @@ -597,6 +607,19 @@ sub show_service { } } +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"; + } +} + diff --git a/src/www-spong.pl b/src/www-spong.pl index 55fefba..0b63ff0 100755 --- a/src/www-spong.pl +++ b/src/www-spong.pl @@ -47,6 +47,7 @@ if( $ENV{'SCRIPT_NAME'} eq "" ) { my %opt; my @options = ( "help", "summary:s", "problems:s", "history:s", "host=s", "services=s", "stats=s", "config=s", "info=s", "service=s", + "histservice=s", "brief", "standard", "full" ); $actionbar = 0; @@ -75,6 +76,12 @@ if( $ENV{'SCRIPT_NAME'} eq "" ) { $opt = 1; } + if ( defined $opt{'histservice'} ) { + my( $host, $service, $time ) = split ( ':', $opt{'histservice'} ); + &histservice( $host, "$service $time" ); + $opt=1; + } + if( ! $opt ) { &summary( "all" ); } exit(0); @@ -124,6 +131,8 @@ if( $cmd =~ m!^/info/(.*)$! ) { &info($1); exit;} if( $cmd =~ m!^/service/(.*)/(.*)$! ) { &service( $1, $2 ); exit; } +if( $cmd =~ m!^/histservice/(.*)/(.*)/(.*)$! ) { &histservice( $1, "$2 $3" ); exit; } + # Need to do something when an invalid request comes through... exit(0); @@ -362,6 +371,17 @@ sub service { &footer(); } +sub histservice { + my ($host, $service, $time ) = @_; + my $view = $main::view || "full"; + + &header( 0 ); + print &query( $SPONGSERVER, "histservice", $host, "html", $view, $service, + $time ); + &footer(); +} + + # Just print a little message to stdout showing what valid options are to # the command line interface to spong, and then exit the program. -- 2.30.2