From: Stephen L Johnson Date: Mon, 25 Sep 2000 20:33:10 +0000 (+0000) Subject: added wml display routines X-Git-Tag: spong-2_7_0-beta1~37 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=939be4c7417044826b4e3931374e832cc259d8eb;p=spong.git added wml display routines --- diff --git a/src/lib/Spong/HostList.pm b/src/lib/Spong/HostList.pm index 35ee201..1e4a833 100755 --- a/src/lib/Spong/HostList.pm +++ b/src/lib/Spong/HostList.pm @@ -107,6 +107,7 @@ sub add { push( @{$self->{'hostnames'}}, $name ); } +# Calculate summary color for a service sub services_color { my( $self, $service ) = @_; my( $color ) = ""; @@ -119,6 +120,24 @@ sub services_color { return $color; } +# Calculate an overall summary color for the entire host list +sub summary_color { + my( $self ) = @_; + my( $color ) = ""; + my( $service, @names ); + + foreach $host ( $self->hosts() ) { + foreach $service (keys %main::SERVICES) { + my $servobj = $host->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. # @@ -131,6 +150,7 @@ sub display { $self->display_text( $view ) if $type eq "text"; $self->display_html( $view ) if $type eq "html"; + $self->display_wml( $view ) if $type eq "wml"; } # This displays a summary of all the hosts in this list in a text format @@ -198,6 +218,16 @@ sub display_text { foreach $host ( $self->hosts() ) { $host->display_problem( "text" ); print "\n"; } + } elsif( $format eq "brief" ) { + + # This goes through each host, and has each one print a single summary + # line of the current status of the host. The consists of the overall + # status color and the host name. + + foreach $host ( $self->hosts() ) { + printf "%-6s %s\n",$host->color(),$host->name(); + } + } } @@ -355,4 +385,27 @@ sub display_problems { } } +# This displays a summary of all the hosts in this list in an WML format +# suitable for displaying on WAP enabled devices + +sub display_wml { + my( $self, $format ) = @_; + + # Standard and brief view are equivalent for WML + if( $format eq "standard" || $format eq "brief") { + + foreach $host ($self->hosts() ) { + my $color = substr($host->color(),0,2); + $color =~ tr/a-z/A-Z/; + my $name = $host->name(); + + print "$color"; + print ""; + print " $name
\n"; + } + } + +} + + 1; diff --git a/src/lib/Spong/Service.pm b/src/lib/Spong/Service.pm index f562020..d9b673a 100755 --- a/src/lib/Spong/Service.pm +++ b/src/lib/Spong/Service.pm @@ -192,6 +192,7 @@ sub display { if( $type eq "text" ) { return $self->display_text( $view ); } if( $type eq "html" ) { return $self->display_html( $view ); } + if( $type eq "wml" ) { return $self->display_wml( $view ); } } sub display_text { @@ -320,6 +321,23 @@ sub display_html { } } +sub display_wml { + my( $self, $format ) = @_; + + if ( $format eq "full" ) { + print "
",$self->name()," ",$self->color(),"\n"; + print "
Updated: ", + POSIX::strftime($main::DATETIMEFMT,localtime($self->rtime())),"\n"; + print "
",$self->summary(),"\n"; + print "

\n"; + foreach $line ( split /\r?\n/s,$self->message() ) { + print "
",$line,"\n"; + if ( ++$i >= 15 ) { last; } + } + } + +} + # Returns a message that can be sent to the person who is on call for this # machine which indicates the problem with this machine. @@ -355,7 +373,7 @@ sub add_action_bar { sub escape { my($toencode) = @_; - $toencode=~s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg; + $toencode=~s/([^ a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg; return $toencode; } diff --git a/src/lib/Spong/ServiceList.pm b/src/lib/Spong/ServiceList.pm index 6d9d1f8..2e6a89d 100755 --- a/src/lib/Spong/ServiceList.pm +++ b/src/lib/Spong/ServiceList.pm @@ -165,6 +165,7 @@ sub display { if( $type eq "text" ) { return $self->display_text( $view ); } if( $type eq "html" ) { return $self->display_html( $view ); } + if( $type eq "wml" ) { return $self->display_wml( $view ); } } sub display_text { @@ -219,4 +220,29 @@ sub display_html { } } +# This displays all services in the database for a host in a WML format +# suitable for displaying on a WAP enabled device + +sub display_wml { + my( $self, $format ) = @_; + my( $service ); + my $host = $self->host(); + + if( $format eq "standard" ) { + foreach $service ( $self->services() ) { + my $name = $service->name(); + my $color = substr($service->color(),0,2); + $color =~ tr/a-z/A-Z/; + print "$color"; + print ""; + print " $name
\n"; + } + } +} + + + + + + 1;