From: Stephen L Johnson Date: Wed, 29 Dec 1999 04:19:34 +0000 (+0000) Subject: New class added. Inherits from Service.pm class. X-Git-Tag: spong-2_6b~12 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dd1ce9a8173eeaf710fbc93c51b6faa2b55b1d0d;p=spong.git New class added. Inherits from Service.pm class. --- diff --git a/src/lib/Spong/HistoryService.pm b/src/lib/Spong/HistoryService.pm new file mode 100755 index 0000000..3b910a9 --- /dev/null +++ b/src/lib/Spong/HistoryService.pm @@ -0,0 +1,155 @@ +#!/usr/local/bin/perl +# +# This object represents a service in the History Service directory. This +# object inherits from the Service class. The filename function is overridden +# so we get the correct status information. The new function is overloaded +# becuase we needed the status time field to build the file name + +# History +# (1) Created (Dec 27, 1999 Stephen L Johnson) + +package Spong::HistoryService; + +use Spong::Service; +@ISA = ("Spong::Service"); + +# This is an overloaded new function for the HistoryService close. It +# needs the update time in addition to host and service names + +sub new { + my( $proto, $host, $service, $time ) = @_; + my( $class ) = ref($proto) || $proto; + my $self = $class->SUPER::new($host,$service); # Call the service new() + + $self->{'time'} = $time; # Add the stuff I need + + my $file = $self->filename(); + if (! -f "$main::SPONGDB/$file" ) { # If no file record found + return undef; # Return undef + } + + bless ($self,$class); # reconsecrate + return $self; +} + +# These functions handle the loading of of the service data from the +# database files + +sub filename { + 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()."/history/status/".$self->{'time'}."-".$self->{'name'}; + if( ! -f "$main::SPONGDB/$file" ) { + $file = $self->host()."/history/status/".$self->{'time'}."-procs"; + } + } else { + $file = $self->host()."/history/status/".$self->{'time'}."-".$self->{'name'}; + } + + return $file; +} + +# Overridden html display function + +sub display_html { + my( $self, $format ) = @_; + my $host = $self->host; + my $name = $self->name(); + my $color = $self->color(); + my( $d1, $m1, $y1 ) = (localtime( $self->rtime()))[3,4,5]; + my( $d2, $m2, $y2 ) = (localtime())[3,4,5]; + + if( $format eq "brief" ) { + print "\n"; + + if( $main::WWW_USE_IMAGES == 1 ) { + print "$color"; + } else { + print ""; + print "
"; + print "___
\n"; + } + print "
"; + } elsif( $format eq "standard_table" ) { + print "\n"; + print "$name\n"; + print "\n"; + + if( $main::WWW_USE_IMAGES == 1 ) { + print "\n"; + print "$color"; + } else { + print ""; + print "
"; + print ""; + print "___"; + print "
\n"; + } + + print "\n"; + print ""; + + if( $d1 == $d2 && $m1 == $m2 && $y1 == $y2 ) { + print POSIX::strftime( "%H:%M", localtime($self->rtime()) ), " "; + } else { + print POSIX::strftime( "%D", localtime($self->rtime()) ), " "; + } + + print "\n"; + print "", $self->summary(), "\n"; + } elsif( $format eq "standard" ) { + print "\n"; + print "\n"; + print "\n"; + print "\n"; + print "\n"; + + $self->display_html( "standard_table" ); + + print "
Service UpdatedSummary
\n"; + } elsif( $format eq "full" ) { + print "", $self->host(), "/", $self->name(); + print "\n"; + + print ""; + print ""; + print "
 

"; + + print "Date: "; + print POSIX::strftime( "%H:%M, %D", localtime($self->rtime()) ); + + print "
Summary: ", $self->summary(), "
\n"; + print "


", $self->message(), "
\n"; + } +} + +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 ($header =~ /^color (\S+)/) { + $self->color($1); + $header = ; chomp $header; + } + + ($self->{'rtime'}, $self->{'summary'}) = ( $header =~ /^(\d+) (.*)$/ ); + while( ) { $self->{'message'} .= $_; } + close( FILE ); +} + + +1; +