From: Stephen L Johnson Date: Mon, 7 Feb 2000 03:12:20 +0000 (+0000) Subject: added services_color() to return status color for HostList X-Git-Tag: spong-2_7-alpha5~103 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f195af8d8097dfb0e22d4a6558386392974d01f7;p=spong.git added services_color() to return status color for HostList --- diff --git a/src/lib/Spong/HostList.pm b/src/lib/Spong/HostList.pm index 2b683ce..fb2ee4e 100755 --- a/src/lib/Spong/HostList.pm +++ b/src/lib/Spong/HostList.pm @@ -25,6 +25,8 @@ use Spong::Host; package Spong::HostList; +my %COLORS = ( 'blue', 10, 'red', 5, 'yellow', 4, 'green', 3, 'purple', 2 ); + # This constructor expects one of four different types of options. Either an # empty string specifying that no actual hosts will be loaded, the string # "all" to load all the hosts, the string containing a group name that @@ -105,6 +107,18 @@ sub add { push( @{$self->{'hostnames'}}, $name ); } +sub services_color { + my( $self, $service ) = @_; + my( $color ) = ""; + + foreach( $self->hosts() ) { + my $servobj = $_->service($service); + my $hostcolor = $servobj->color() if $servobj; + $color = $hostcolor if $COLORS{$hostcolor} > $COLORS{$color}; + } + return $color; +} + # Display summary. Does both text and html, does rely on both the Host and # Service objects for some help. # @@ -205,7 +219,9 @@ sub display_html { # Print the horizontal axis of the table (names of the services) - print ""; + print "
"; print "\n"; foreach $service ( @names ) { print "\n"; + print "\n"; foreach $service ( @names ) { my $servobj = $host->service( $service ); @@ -232,7 +251,10 @@ sub display_html { my $col = $servobj->color(); if( $main::WWW_USE_IMAGES == 1 ) { - print ""; } else { if( $main::WWW_USE_IMAGES == 1 ) { - print "\n"; + print "\n"; } else { - print "\n"; + print "\n"; } } }
Host\n"; @@ -219,11 +235,14 @@ sub display_html { foreach $host ( $self->hosts() ) { my $hostname = $host->name(); - my $short = $main::HOSTS{$hostname}->{'display_name'}; - $short = (split( /\./, $hostname ))[0] unless $short; + if ( ! $main::WWW_FQDN ) { # If WWW_FQDN not set, use short hostname + my $short = $main::HOSTS{$hostname}->{'display_name'}; + $short = (split( /\./, $hostname ))[0] unless $short; + $hostname = $short; + } - print "
\n"; - print "$short
\n"; + print "$hostname"; my $alt = $servobj->summary(); print "\"$alt\""; @@ -247,9 +269,15 @@ sub display_html { print " - -