--- generate-overview.pl 2002/07/24 15:14:08 1.5 +++ generate-overview.pl 2003/11/03 10:30:48 1.16 @@ -27,6 +27,9 @@ # Target can be skipped in overview report with skip-overview +my $path; +my $gBaseURL; + BEGIN { # $gInstallRoot = (($0 =~ m:^(.*/):)[0] || "./") . "."; require '/etc/cricket/cricket-conf.pl'; @@ -34,7 +37,9 @@ # You need to update this to point to the URL # you use to access Cricket. # $gBaseURL = "http://localhost/~cricket/grapher.cgi"; - $gBaseURL = "http://romul.pliva.hr/cgi-bin/cricket/grapher.cgi"; + my $hostname = `hostname -f`; + chomp($hostname); + $gBaseURL = "/cgi-bin/cricket/grapher.cgi"; # change this to destination directory $path = "/data/mon/"; @@ -42,6 +47,7 @@ #use lib "$gInstallRoot/../lib"; use lib "$Common::global::gInstallRoot/lib"; +use strict; use File::Basename; use LWP::UserAgent; @@ -55,11 +61,17 @@ use Common::Options; use Common::Log; +# +# Set this option to 0 if you don't want JavaScript roll-up/roll-down +# of images to be created +# +my $dynamic_js = 1; + Common::Options::commonOptions( 'baseURL=s' => \$gBaseURL ); initConst(); $Common::global::gCT = new ConfigTree::Cache; -$gCT = $Common::global::gCT; +my $gCT = $Common::global::gCT; $gCT->Base($Common::global::gConfigRoot); $gCT->Warn(\&Warn); @@ -105,8 +117,160 @@ } Info("Dumping HTML for $key to $filename."); open(OUT,"> $filename") || die "can't open output html '$filename': $!"; - print OUT "$key"; + print OUT "$key"; + print OUT ' + ' if ($filename =~ m/Daily/i); + print OUT ''; + my $html=<<'HTMLEND'; + + + + + +HTMLEND + if ($dynamic_js) { + my $cookie_name = $key; + $cookie_name =~ s/[^a-zA-Z0-9]//g; + $html =~ s/##cookie_name##/$cookie_name/g; + print OUT $html; + } + print OUT $html_file{$key}; + $html = <<'HTMLEND'; +
+ + +HTMLEND + + if ($dynamic_js) { + my $cookie_name = $key; + $cookie_name =~ s/[^a-zA-Z0-9]//g; + $html =~ s/##cookie_name##/$cookie_name/g; + print OUT $html; + } + print OUT ""; close(OUT); @@ -114,14 +278,40 @@ exit; +sub do_html { + my ($desc,$url,$img) = @_; + if ($dynamic_js) { + my $html =<<'HTMLEND'; + +##desc## + + + + +HTMLEND + $html =~ s/##desc##/$desc/; + $html =~ s/##url##/$url/; + $html =~ s/##img##/$img/; + $html =~ s/##id##/$dynamic_js/g; + $dynamic_js++; # increment usage counter + return $html; + } else { + return "$desc

\n"; + } +} + sub localHandleTargetInstance { my($Name, $target) = @_; - $targetpath = $target->{'auto-target-path'}; - $targetname = $target->{'auto-target-name'}; + my $targetpath = $target->{'auto-target-path'}; + my $targetname = $target->{'auto-target-name'}; - if (! defined($target->{'skip-overview'})) - { + my @skip_views = split(/[\s,]+/,$target->{'skip-view'}) if ($target->{'skip-view'}); +print "### ",join("|",@skip_views),"\n"; + + if (defined($target->{'skip-overview'})) { + Info("Skipping target $targetname."); + } else { Info("Working on target $targetname."); my($reqRanges,@ranges); @@ -140,7 +330,7 @@ foreach $range (@ranges) { - $rangeLabel = rangeToLabel($range); + my $rangeLabel = rangeToLabel($range); my($paramtarget) = "$targetpath/$targetname"; @@ -157,18 +347,21 @@ # find the ds names based on the target type my($ttype) = lc($target->{'target-type'}); - my($ttRef) = $main::gCT->configHash($Name, 'targettype', $ttype, $target); + my($ttRef) = $gCT->configHash($Name, 'targettype', $ttype, $target); # If there are views defined, then we generate graphs # for each view. my($dslist); - if (defined($ttRef->{'view'})) - { + if (defined($ttRef->{'view'})) { my($v); - foreach $v (split(/\s*,\s*/, $ttRef->{'view'})) - { + foreach $v (split(/\s*,\s*/, $ttRef->{'view'})) { + my ($view_name,undef) = split(/\s*:\s*/,$v); + if (grep(/$view_name/,@skip_views)) { + Info("Skip view $v"); + next; + } # views are like this: "cpu: cpu1load cpu5load" my($vname, $dss) = split(/\s*:\s*/, $v, 2); @@ -176,26 +369,28 @@ $dslist =~ s/\s*$//; $dslist =~ s/\s+/,/g; - $URL = "$gBaseURL?type=png&target=$paramtarget"; + my $URL = "$gBaseURL?type=png&target=$paramtarget"; $URL .= "&dslist=$dslist&range=$paramrange"; my $desc = "$paramtarget $vname"; + $desc .= " ".$target->{'short-desc'}."" if (defined $target->{'short-desc'}); if ($paraminst ne "") { $URL .= "&inst=$paraminst"; } Info("Retrieving graph for $desc"); # getURL($URL,"$path/$name-$vname-$rangeLabel.png"); - $tmp_URL = "$gBaseURL?target=$paramtarget&range=d:w:m:y&view=$vname"; - $html{"$rangeLabel\t$paramtarget"}.="$desc

\n"; + my $tmp_URL = "$gBaseURL?target=$paramtarget&range=d:w:m:y&view=$vname"; + $html{"$rangeLabel\t$paramtarget"}.=do_html($desc,$tmp_URL,$URL); } } else { $dslist = $ttRef->{'ds'}; # squeeze out any extra spaces $dslist = join(',', split(/\s*,\s*/, $dslist)); - $URL = "$gBaseURL?type=png&target=$paramtarget"; + my $URL = "$gBaseURL?type=png&target=$paramtarget"; $URL .= "&dslist=$dslist&range=$paramrange"; my $desc ="$paraminst $rangeLabel"; + $desc .= " ".$target->{'short-desc'}."" if (defined $target->{'short-desc'}); if ($paraminst ne "") { $URL .= "&inst=$paraminst"; } @@ -203,8 +398,8 @@ Info("Retrieving graph for $desc"); # getURL($URL,"$path/$name-$rangeLabel.png"); - $tmp_URL = "$gBaseURL?target=$paramtarget&range=d:w:m:y"; - $html{"$rangeLabel\t$paramtarget"}.="$desc:

"; + my $tmp_URL = "$gBaseURL?target=$paramtarget&range=d:w:m:y"; + $html{"$rangeLabel\t$paramtarget"}.=do_html($desc,$tmp_URL,$URL); } } }