From d9486349d88e4dffb1706b80d7ccbab7c5a06499 Mon Sep 17 00:00:00 2001 From: Stephen L Johnson Date: Thu, 2 Dec 1999 07:21:10 +0000 Subject: [PATCH] Added error checking to query routines to prevent query process from dying. --- src/spong-server.pl | 79 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 73 insertions(+), 6 deletions(-) diff --git a/src/spong-server.pl b/src/spong-server.pl index 61252a5..3962349 100755 --- a/src/spong-server.pl +++ b/src/spong-server.pl @@ -238,6 +238,8 @@ sub listen_for_queries { &debug( "[$$] showing $query information for $hosts [$type:$view]" ); if( $query eq "problems" ) { &show_problems( @args ); } +# Disabled for now into all of Herbies web enchanges are added +# if( $query eq "warnings" ) { &show_warnings( @args ); } if( $query eq "summary" ) { &show_summary( @args ); } if( $query eq "history" ) { &show_history( @args ); } if( $query eq "host" ) { &show_host( @args ); } @@ -473,6 +475,11 @@ sub show_problems { my( $hosts, $type, $view ) = @_; Spong::HostList->new( hostlist($hosts) )->display_problems( $type, $view );} +sub show_warnings { + my( $hosts, $type, $view ) = @_; + Spong::HostList->new( hostlist($hosts) )->display_problems( $type, $view ); + Spong::HostList->new( hostlist($hosts) )->display_warnings( $type, $view );} + sub show_summary { my( $hosts, $type, $view ) = @_; Spong::HostList->new( hostlist( $hosts ) )->display( $type, $view ); } @@ -506,28 +513,75 @@ sub show_acks { sub show_host { my( $hosts, $type, $view ) = @_; - Spong::Host->new( $hosts )->display( $type, $view ); } + my( $h ); + eval { $h = Spong::Host->new( $hosts ); }; + if ( $h ) { + $h->display( $type, $view ); + } else { + print &fmt_error($type,"Invalid request, object $hosts does not exist"),"\n"; + } +} sub show_services { my( $hosts, $type, $view ) = @_; - Spong::Host->new( $hosts )->services()->display( $type, $view ); } + my( $h ); + eval { $h = Spong::Host->new( $hosts )->services(); }; + if ( $h ) { + $h->display( $type, $view ); + } else { + print &fmt_error($type,"Invalid request, object $hosts services does not exist"), + "\n"; + } +} sub show_stats { my( $hosts, $type, $view ) = @_; - Spong::Host->new( $hosts )->stats_list()->display( $type, $view ); } + my( $h ); + eval { $h = Spong::Host->new( $hosts )->stats_list(); }; + if ( $h ) { + $h->display( $type, $view ); + } else { + print &fmt_error($type,"Invalid request, object $hosts stats does not exist"), + "\n"; + } +} sub show_config { my( $hosts, $type, $view ) = @_; - Spong::Host->new( $hosts )->config()->display( $type, $view ); } + my( $h ); + eval { $h = Spong::Host->new( $hosts )->config(); }; + if ( $h ) { + $h->display( $type, $view ); + } else { + print &fmt_error($type,"Invalid request, object $hosts config does not exist"), + "\n"; + } +} sub show_info { my( $hosts, $type, $view ) = @_; - Spong::Host->new( $hosts )->info()->display( $type, $view ); } + my( $h ); + eval { $h = Spong::Host->new( $hosts )->info(); }; + if ( $h ) { + $h->display( $type, $view ); + } else { + print &fmt_error($type,"Invalid request, object $hosts info does not exist"), + "\n"; + } +} sub show_service { my( $hosts, $type, $view, $other ) = @_; - Spong::Host->new( $hosts )->service( $other )->display( $type, $view ); } + my( $h ); + eval { $h = Spong::Host->new( $hosts )->service($other); }; + if ( $h ) { + $h->display( $type, $view ); + } else { + print &fmt_error($type,"Invalid request, object $hosts $other does not exist"), + "\n"; + } +} @@ -725,6 +779,19 @@ sub debug { print STDOUT scalar localtime, " ", $_[0], "\n" if $main::debug; } sub error { warn scalar localtime(), " Error: ", $_[0], "\n"; } +# Formatting function for query error reports +sub fmt_error { + my( $type, $text ) = @_; + + # Add HTML tags if view is html + if ($type eq 'html') { + $text = "" . $text . ""; + } + + return $text; +} + + # Signal handlers... sub exit_handler { -- 2.30.2