# 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.
$self->{'message'} = "";
$self->{'stime'} = "";
- bless ($self,$class);
+ bless $self;
return $self;
}
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...
$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 = <FILE>; chomp $header;
- # If a timestamp is present, read it and set start time
- if ($header =~ /^timestamp (\d+) (\d+)/ ) {
- $self->{'stime'} = $1;
- $header = <FILE>; chomp $header;
+ if( ! $self->{'summary'} ) {
+ open( FILE, "$main::SPONGDB/$file" );
+ my $header = <FILE>; chomp $header;
+ # If a timestamp is present, read it and set start time
+ if ($header =~ /^timestamp (\d+) (\d+)/ ) {
+ $self->{'stime'} = $1;
+ $header = <FILE>; chomp $header;
+ }
+ ($self->{'rtime'}, $self->{'summary'}) = ( $header =~ /^(\d+) (.*)$/ );
+ while( <FILE> ) { $self->{'message'} .= $_; }
+ close( FILE );
}
- ($self->{'rtime'}, $self->{'summary'}) = ( $header =~ /^(\d+) (.*)$/ );
- while( <FILE> ) { $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 = <FILE>; chomp $header;
+ # If timestamp header present, read it and set start time
+ if ($header =~ /^timestamp (\d+) (\d+)/ ) {
+ $self->{'stime'} = $1;
+ $header = <FILE>; chomp $header;
+ }
+ ($self->{'rtime'}, $self->{'summary'}) = ( $header =~ /^(\d+) (.*)$/ );
+ while( <FILE> ) { $self->{'message'} .= $_; }
+ close( FILE );
+ }
- if( ! $self->{'message'} ) { $self->load(); }
return $self->{'message'};
}
} 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";
}
print POSIX::strftime( "%H:%M, %D", localtime($self->rtime()) );
print "<br><b>Duration:</b> ";
- print $self->format_duration($self->stime(),$self->rtime());
+ print &format_duration($self->stime(),$self->rtime());
print "<br><b>Summary:</b> ", $self->summary(), "<br>\n";
print "<hr noshade><pre>", $self->message(), "</pre>\n";
}
sub format_duration {
- my($self,$stime,$rtime) = @_;
+ my($stime,$rtime) = @_;
my $duration = $rtime - $stime;
my $units = "seconds";