From: Stephen L Johnson Date: Wed, 10 May 2000 04:08:49 +0000 (+0000) Subject: display_text() function finished for all view modes (code by Andrew Ruthven ) --- diff --git a/src/lib/Spong/HostGroups.pm b/src/lib/Spong/HostGroups.pm index f13328e..3c42878 100755 --- a/src/lib/Spong/HostGroups.pm +++ b/src/lib/Spong/HostGroups.pm @@ -117,7 +117,60 @@ sub display { sub display_text { my( $self, $format ) = @_; - if( $format eq "standard" ) { + if( $format eq "brief" ) { + my( %services, $host, $service, @names ); + + # Compute the total list of services running on the various hosts, and + # sort them alphabetically (except always put ping first). + +# foreach $host ( $self->hosts() ) { +# foreach $service ( $host->service_names() ) { $services{$service}++;}} + + if( grep( /^ping$/, keys %main::SERVICES ) ) { push( @names, "ping" ); } + foreach $service ( sort keys %main::SERVICES ) { + push( @names, $service ) unless $service eq "ping"; } + + # Print the horizontal axis of the table (names of the services) + + print "-"x30, "-"x(($#names+1)*3), "\n"; + foreach my $cnt ( 0..5 ) { + if( $cnt == 0 ) { print "Key: . = green, ? = purple "; } + if( $cnt == 1 ) { print " Y = yellow, R = red "; } + if( $cnt == 2 ) { print " B = blue "; } + if( $cnt == 3 ) { print " "x30; } + if( $cnt == 4 ) { print " "x30; } + if( $cnt == 5 ) { print "Group:", " "x24; } + print substr( "status", (length("status") - 6 + $cnt), 1 )," "; + print "\n"; + } + print "-"x30, "-"x(($#names+1)*3), "\n"; + + # Now go through each host, and fill in the table. + + foreach $group ( $self->groups() ) { + print substr( $group->name(), 0, 29 ); + print " "x(30-length(substr($group->name(), 0, 29))); + + my ($color); + foreach $service ( @names ) { + my ($servicecolor) = $group->services_color( $service ); + $color = $servicecolor if ($COLORS{$servicecolor} > $COLORS{$color}); + } + + if( $color ) { + if( $color eq "green" ) { print ". "; } + if( $color eq "purple" ) { print "? "; } + if( $color eq "yellow" ) { print "Y "; } + if( $color eq "red" ) { print "R "; } + if( $color eq "blue" ) { print "B "; } + } else { + print " "; + } + print "\n"; + } + print "\n"; + + } elsif( $format eq "standard" ) { my( %services, $host, $service, @names ); # Compute the total list of services running on the various hosts, and @@ -133,12 +186,12 @@ sub display_text { # Print the horizontal axis of the table (names of the services) print "-"x30, "-"x(($#names+1)*3), "\n"; - foreach $cnt ( 0..4 ) { + foreach my $cnt ( 0..4 ) { if( $cnt == 0 ) { print "Key: . = green, ? = purple "; } if( $cnt == 1 ) { print " Y = yellow, R = red "; } if( $cnt == 2 ) { print " B = blue "; } if( $cnt == 3 ) { print " "x30; } - if( $cnt == 4 ) { print "Host:", " "x25; } + if( $cnt == 4 ) { print "Group:", " "x24; } foreach $service ( @names ) { if( length($service) - 5 + $cnt >= 0 ) { print substr( $service, (length($service) - 5 + $cnt), 1 )," "; @@ -152,30 +205,49 @@ sub display_text { # Now go through each host, and fill in the table. - foreach $host ( $self->hosts() ) { - print substr( $host->name(), 0, 29 ); - print " "x(30-length(substr($host->name(), 0, 29))); - foreach $service ( @names ) { - my $servobj = $host->service( $service ); - if( $servobj ) { - $servobj->display_text( "really_brief" ); - } else { + foreach $group ( $self->groups() ) { + print substr( $group->name(), 0, 29 ); + print " "x(30-length(substr($group->name(), 0, 29))); + + foreach my $service ( @names ) { + my ($color) = $group->services_color( $service ); + if( $color ) { + if( $color eq "green" ) { print ". "; } + if( $color eq "purple" ) { print "? "; } + if( $color eq "yellow" ) { print "Y "; } + if( $color eq "red" ) { print "R "; } + if( $color eq "blue" ) { print "B "; } + } else { print " "; } - } + } print "\n"; } print "\n"; + } elsif( $format eq "full" ) { + my( $service, @names ); - # This goes through each host, and has each one print a textual record - # of the problem it is currently having, this would include a summary - # of the problem services, date/time the problem occurred, and contact - # information (as well as acknowledgments if they are available). + # Compute the total list of services running on the various hosts, and + # sort them alphabetically (except always put ping first). + + if( grep( /^ping$/, keys %main::SERVICES ) ) { push( @names, "ping" ); } + foreach $service ( sort keys %main::SERVICES ) { + push( @names, $service ) unless $service eq "ping"; } + + # Print the horizontal axis of the table (names of the services) - foreach $host ( $self->hosts() ) { - $host->display_problem( "text" ); print "\n"; + # Now go through each host, and fill in the table. + + foreach $group ( $self->groups() ) { + print "-"x30, "-"x(($#names+1)*3), "\n"; + print "Group: " . substr( $group->name(), 0, 29 ) . "\n"; + + $group->display_text("standard"); } + print "\n"; + + } }