From: Stephen L Johnson Date: Mon, 3 Jan 2000 17:28:32 +0000 (+0000) Subject: hostname and service name were not being added to www-spong-ack URL on X-Git-Tag: spong-2_6b~5 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0c6bcbb7c0a9fcdb0b356b6f8e05a98a9e01e235;p=spong.git hostname and service name were not being added to www-spong-ack URL on Service Display web page. --- diff --git a/src/lib/Spong/Service.pm b/src/lib/Spong/Service.pm index ff1ba15..b373c86 100755 --- a/src/lib/Spong/Service.pm +++ b/src/lib/Spong/Service.pm @@ -31,8 +31,7 @@ package Spong::Service; # ServiceList object for loading the information about it from the database. sub new { - my( $proto, $host, $service ) = @_; - my( $class ) = ref($proto) || $proto; + my( $class, $host, $service ) = @_; my $self = {}; # A hack to get around a local problem. @@ -48,7 +47,7 @@ sub new { $self->{'message'} = ""; $self->{'stime'} = ""; - bless ($self,$class); + bless $self; return $self; } @@ -109,12 +108,14 @@ sub rtime { my $var = 'rtime'; sub stime { my $var = 'stime'; if( $_[0]->{$var} eq "" ) { $_[0]->summary(); } return $_[0]->{$var}; } -# These functions handle the loading of of the service data from the -# database files -sub filename { - my( $self ) = shift; - my( $file ); +# These are both lazy loading functions. If we don't have summary and message +# information already loaded, then go out and grab it from the database and +# return that information to the user. + +sub summary { + my $self = shift; + my $file; # This is a local hack to get around the procs/jobs problems, first look # for the jobs service, if it is not there, look for procs... @@ -128,40 +129,52 @@ sub filename { $file = $self->host()."/services/".$self->name()."-".$self->rcolor(); } - return $file; -} -sub load { - my( $self ) = shift; - my $file = $self->filename(); - - open( FILE, "$main::SPONGDB/$file" ); - my $header = ; chomp $header; - # If a timestamp is present, read it and set start time - if ($header =~ /^timestamp (\d+) (\d+)/ ) { - $self->{'stime'} = $1; - $header = ; chomp $header; + if( ! $self->{'summary'} ) { + open( FILE, "$main::SPONGDB/$file" ); + my $header = ; chomp $header; + # If a timestamp is present, read it and set start time + if ($header =~ /^timestamp (\d+) (\d+)/ ) { + $self->{'stime'} = $1; + $header = ; chomp $header; + } + ($self->{'rtime'}, $self->{'summary'}) = ( $header =~ /^(\d+) (.*)$/ ); + while( ) { $self->{'message'} .= $_; } + close( FILE ); } - ($self->{'rtime'}, $self->{'summary'}) = ( $header =~ /^(\d+) (.*)$/ ); - while( ) { $self->{'message'} .= $_; } - close( FILE ); -} - -# These are both lazy loading functions. If we don't have summary and message -# information already loaded, then go out and grab it from the database and -# return that information to the user. -sub summary { - my $self = shift; - - if( ! $self->{'summary'} ) { $self->load(); } return $self->{'summary'}; } sub message { my $self = shift; + my $file; + + # This is a local hack to get around the procs/jobs problems, first look + # for the jobs service, if it is not there, look for procs... + + if( $self->name() eq "jobs" ) { + $file = $self->host()."/services/".$self->name()."-".$self->rcolor(); + if( ! -f $file ) { + $file = $self->host()."/services/procs-".$self->rcolor(); + } + } else { + $file = $self->host()."/services/".$self->name()."-".$self->rcolor(); + } + + if( ! $self->{'message'} ) { + open( FILE, "$main::SPONGDB/$file" ); + my $header = ; chomp $header; + # If timestamp header present, read it and set start time + if ($header =~ /^timestamp (\d+) (\d+)/ ) { + $self->{'stime'} = $1; + $header = ; chomp $header; + } + ($self->{'rtime'}, $self->{'summary'}) = ( $header =~ /^(\d+) (.*)$/ ); + while( ) { $self->{'message'} .= $_; } + close( FILE ); + } - if( ! $self->{'message'} ) { $self->load(); } return $self->{'message'}; } @@ -235,7 +248,7 @@ sub display_text { } elsif( $format eq "full" ) { $self->display_text( "standard" ); print "\nStatus unchanged in " . - $self->format_duration($self->stime(),$self->rtime) . "\n"; + &format_duration($self->stime(),$self->rtime) . "\n"; print "-"x78, "\n"; print $self->message(), "\n"; } @@ -313,7 +326,7 @@ sub display_html { print POSIX::strftime( "%H:%M, %D", localtime($self->rtime()) ); print "
Duration: "; - print $self->format_duration($self->stime(),$self->rtime()); + print &format_duration($self->stime(),$self->rtime()); print "
Summary: ", $self->summary(), "
\n"; print "
", $self->message(), "
\n"; @@ -360,7 +373,7 @@ sub escape { } sub format_duration { - my($self,$stime,$rtime) = @_; + my($stime,$rtime) = @_; my $duration = $rtime - $stime; my $units = "seconds";