#!/usr/bin/perl -w # GRAPHIC JOBS REPORT # 10/04/06 - Greg Ercolano erco@seriss.com # # Request: 'all jobs' report shown as simple HTML graph # use strict; $ |= 1; # disable output buffering $ENV{PATH} = (defined($ENV{OS}) && $ENV{OS} eq "Windows_NT" ) ? "c:/rush/bin;$ENV{PATH}" # windows : "/usr/local/rush/bin:$ENV{PATH}"; # unix sub LoadAllJobs($$$) { my ($headers, $jobs, $errors) = @_; # OPEN 'LIST ALL JOBS' REPORT my $cmd = "rush -laj"; unless ( open(LAJ, "$cmd 2>&1|") ) { push(@{$errors}, "'$cmd': $!\n"); return(-1); } # STATUS JOBID TITLE OWNER %DONE %FAIL BUSY ELAPSED REMARKS # -------- ---------------- ------------------------- -------------- ----- ----- ---- ---------- -------- # Fail ontario.9 BOUNCING_BALL erco %0 %100 0 189:23:16 # Done ontario.10 BOUNCING_BALL erco %100 %0 0 189:21:42 # *** NO RESPONSE FROM: # *** geneva nt-1 tahoe sup erie huron # *** indy winxp64 how crystal # PARSE THROUGH 'rush -laj' OUTPUT while ( ) { chomp($_); # HEADER? if ( /^STATUS/ ) { @{$headers} = split(/\s+/, $_); next; } # DOT SEPARATOR if ( /^------/ ) { next; } # ERROR? if ( /^rush:/ || /^\*\*\*/ ) { push(@{$errors}, $_); next; } # JOB ENTRY? # Parse fields into hash, eg: $jobs{}{} # my @fields = split(/\s+/,$_); my $jobid = $fields[1]; my $i = 0; foreach my $field ( @{$headers} ) { $$jobs{$jobid}{$field} = $fields[$i++]; } } close(LAJ); return(0); } ### ### MAIN ### { # LOAD THE 'ALL JOBS' DATA INTO HASH my @headers; # header names my %jobs; # job data my @errors; # error message(s) if any LoadAllJobs(\@headers, \%jobs, \@errors); # PRINT CGI-BIN STYLE HTML HEADER print <<"EOF"; Content-type: text/html

All Jobs

EOF # PRINT THE JOB DATA foreach my $jobid ( keys(%jobs) ) { my $status= $jobs{$jobid}{'STATUS'}; my $owner = $jobs{$jobid}{'OWNER'}; my $done = $jobs{$jobid}{'%DONE'}; $done =~ s/%//; $done += 0; my $fail = $jobs{$jobid}{'%FAIL'}; $fail =~ s/%//; $fail += 0; my $togo = (100-$done-$fail); my $busy = $jobs{$jobid}{'BUSY'}; $busy += 0; my $title = $jobs{$jobid}{'TITLE'}; my $spc = " "; # COMPLETION GRAPH my $completion_table = "
Status Jobid Owner Title Completion Busy
". (($done>0)?"":""). # %done (($fail>0)?"":""). # %fail (($togo>0)?"":""). # %to go "
$spc$spc$spc
"; # BUSY GRAPH my $busy_table; if ( $busy == 0 ) { $busy_table = "
$spc
"; } else { $busy_table = ""; for ( my $i=0; $i<$busy; $i++ ) { $busy_table .= ""; } $busy_table .= "
$spc
"; } # DATA ENTRY print << "EOF"; $status $jobid $owner $title $completion_table $busy_table EOF } print "\n"; # PRINT ERRORS (IF ANY) if ( $#errors >= 0 ) { print "

Errors:

\n";
	foreach ( @errors )
	    { print "$_\n"; }
	print "

\n"; } # HTML END print "\n"; exit(0); }