27 |
|
|
28 |
# Target can be skipped in overview report with skip-overview |
# Target can be skipped in overview report with skip-overview |
29 |
|
|
30 |
|
my $path; |
31 |
|
my $gBaseURL; |
32 |
|
|
33 |
BEGIN { |
BEGIN { |
34 |
# $gInstallRoot = (($0 =~ m:^(.*/):)[0] || "./") . "."; |
# $gInstallRoot = (($0 =~ m:^(.*/):)[0] || "./") . "."; |
35 |
require '/etc/cricket/cricket-conf.pl'; |
require '/etc/cricket/cricket-conf.pl'; |
39 |
# $gBaseURL = "http://localhost/~cricket/grapher.cgi"; |
# $gBaseURL = "http://localhost/~cricket/grapher.cgi"; |
40 |
my $hostname = `hostname -f`; |
my $hostname = `hostname -f`; |
41 |
chomp($hostname); |
chomp($hostname); |
42 |
$gBaseURL = "http://$hostname/cgi-bin/cricket/grapher.cgi"; |
$gBaseURL = "/cgi-bin/cricket/grapher.cgi"; |
43 |
|
|
44 |
# change this to destination directory |
# change this to destination directory |
45 |
$path = "/data/mon/"; |
$path = "/data/mon/"; |
47 |
|
|
48 |
#use lib "$gInstallRoot/../lib"; |
#use lib "$gInstallRoot/../lib"; |
49 |
use lib "$Common::global::gInstallRoot/lib"; |
use lib "$Common::global::gInstallRoot/lib"; |
50 |
|
use strict; |
51 |
|
|
52 |
use File::Basename; |
use File::Basename; |
53 |
use LWP::UserAgent; |
use LWP::UserAgent; |
61 |
use Common::Options; |
use Common::Options; |
62 |
use Common::Log; |
use Common::Log; |
63 |
|
|
64 |
|
# |
65 |
|
# Set this option to 0 if you don't want JavaScript roll-up/roll-down |
66 |
|
# of images to be created |
67 |
|
# |
68 |
|
my $dynamic_js = 1; |
69 |
|
|
70 |
Common::Options::commonOptions( 'baseURL=s' => \$gBaseURL ); |
Common::Options::commonOptions( 'baseURL=s' => \$gBaseURL ); |
71 |
initConst(); |
initConst(); |
72 |
|
|
73 |
$Common::global::gCT = new ConfigTree::Cache; |
$Common::global::gCT = new ConfigTree::Cache; |
74 |
$gCT = $Common::global::gCT; |
my $gCT = $Common::global::gCT; |
75 |
$gCT->Base($Common::global::gConfigRoot); |
$gCT->Base($Common::global::gConfigRoot); |
76 |
$gCT->Warn(\&Warn); |
$gCT->Warn(\&Warn); |
77 |
|
|
117 |
} |
} |
118 |
Info("Dumping HTML for $key to $filename."); |
Info("Dumping HTML for $key to $filename."); |
119 |
open(OUT,"> $filename") || die "can't open output html '$filename': $!"; |
open(OUT,"> $filename") || die "can't open output html '$filename': $!"; |
120 |
print OUT '<html><head><title>'.$key.'</title> |
print OUT "<html><head><title>$key</title>"; |
121 |
<meta content="no-cache" http-equiv="Pragma"> |
print OUT '<meta content="no-cache" http-equiv="Pragma"> |
122 |
<meta content="300" http-equiv="Refresh"> |
<meta content="300" http-equiv="Refresh">' if ($filename =~ m/Daily/i); |
123 |
</head><body>'; |
print OUT '</head><body>'; |
124 |
|
my $html=<<'HTMLEND'; |
125 |
|
|
126 |
|
<script language="JavaScript"> |
127 |
|
var Selected = ""; |
128 |
|
|
129 |
|
function Switch(elm) |
130 |
|
{ |
131 |
|
var cookie = Get_Cookie("##cookie_name##"); |
132 |
|
|
133 |
|
var elmref; |
134 |
|
|
135 |
|
// uncomment following lines for just 1 selected content |
136 |
|
/* |
137 |
|
if (Selected != "") |
138 |
|
{ |
139 |
|
elmref = eval("document.getElementById('" + Selected + "_h1')"); |
140 |
|
if (elmref) elmref.style.display = 'none'; |
141 |
|
elmref = eval("document.getElementById('" + Selected + "_h0')"); |
142 |
|
// roll-up color |
143 |
|
if (elmref) elmref.bgColor = '#e0e0e0'; |
144 |
|
} |
145 |
|
if (Selected != elm.name) |
146 |
|
{ |
147 |
|
Selected = elm.name; |
148 |
|
elmref = eval("document.getElementById('" + Selected + "_h1')"); |
149 |
|
if (elmref) |
150 |
|
{ |
151 |
|
if (elmref.style.display=='none') elmref.style.display=''; |
152 |
|
else elmref.style.display = 'none'; |
153 |
|
} |
154 |
|
elmref = eval("document.getElementById('" + Selected + "_h0')"); |
155 |
|
// roll-down color |
156 |
|
if (elmref) elmref.bgColor = '#ffffff'; |
157 |
|
} |
158 |
|
else |
159 |
|
Selected=""; |
160 |
|
*/ |
161 |
|
|
162 |
|
// or use this to unroll more than one line |
163 |
|
Selected = elm.name; |
164 |
|
elmref = eval("document.getElementById('" + Selected + "_h1')"); |
165 |
|
elmref0 = eval("document.getElementById('" + Selected + "_h0')"); |
166 |
|
if (elmref) |
167 |
|
{ |
168 |
|
if (elmref.style.display=='none') { |
169 |
|
elmref.style.display=''; |
170 |
|
if (elmref0) elmref0.bgColor = '#eeeeee'; |
171 |
|
} else { |
172 |
|
elmref.style.display = 'none'; |
173 |
|
if (elmref0) elmref0.bgColor = '#e0e0e0'; |
174 |
|
} |
175 |
|
cookie ^= 1 << Selected; |
176 |
|
} |
177 |
|
|
178 |
|
Set_Cookie("##cookie_name##",cookie); |
179 |
|
return false; |
180 |
|
} |
181 |
|
|
182 |
|
function SwitchThis() |
183 |
|
{ |
184 |
|
return Switch(this); |
185 |
|
} |
186 |
|
|
187 |
|
|
188 |
|
</script> |
189 |
|
|
190 |
|
<table border=0 id=DynamicTable bgColor='#e0e0e0' cellpadding=2 cellspacing=1> |
191 |
|
|
192 |
|
HTMLEND |
193 |
|
if ($dynamic_js) { |
194 |
|
my $cookie_name = $key; |
195 |
|
$cookie_name =~ s/[^a-zA-Z0-9]//g; |
196 |
|
$html =~ s/##cookie_name##/$cookie_name/g; |
197 |
|
print OUT $html; |
198 |
|
} |
199 |
|
|
200 |
print OUT $html_file{$key}; |
print OUT $html_file{$key}; |
201 |
|
$html = <<'HTMLEND'; |
202 |
|
</table> |
203 |
|
|
204 |
|
<script language=javascript> |
205 |
|
|
206 |
|
function Get_Cookie(name) { |
207 |
|
var start = document.cookie.indexOf(name+"="); |
208 |
|
var len = start+name.length+1; |
209 |
|
if ((!start) && (name != document.cookie.substring(0,name.length))) return null; |
210 |
|
if (start == -1) return null; |
211 |
|
var end = document.cookie.indexOf(";",len); |
212 |
|
if (end == -1) end = document.cookie.length; |
213 |
|
return unescape(document.cookie.substring(len,end)); |
214 |
|
} |
215 |
|
|
216 |
|
function Set_Cookie(name,value,expires,path,domain,secure) { |
217 |
|
document.cookie = name + "=" +escape(value) + |
218 |
|
( (expires) ? ";expires=" + expires.toGMTString() : "") + |
219 |
|
( (path) ? ";path=" + path : "") + |
220 |
|
( (domain) ? ";domain=" + domain : "") + |
221 |
|
( (secure) ? ";secure" : ""); |
222 |
|
} |
223 |
|
|
224 |
|
function Delete_Cookie(name,path,domain) { |
225 |
|
if (Get_Cookie(name)) document.cookie = name + "=" + |
226 |
|
( (path) ? ";path=" + path : "") + |
227 |
|
( (domain) ? ";domain=" + domain : "") + |
228 |
|
";expires=Thu, 01-Jan-70 00:00:01 GMT"; |
229 |
|
} |
230 |
|
|
231 |
|
var table = document.getElementById("DynamicTable"); |
232 |
|
var links = table.getElementsByTagName("a"); |
233 |
|
var cookie = Get_Cookie("##cookie_name##"); |
234 |
|
var new_cookie = 0; |
235 |
|
for (var i = 0; i < links.length; i++) { |
236 |
|
if (links[i].id == "DynMessLink") { |
237 |
|
links[i].onclick = SwitchThis; |
238 |
|
elmref = eval("document.getElementById('" + links[i].name + "_h1')"); |
239 |
|
elmref0 = eval("document.getElementById('" + links[i].name + "_h0')"); |
240 |
|
if (elmref && cookie) { |
241 |
|
if (cookie & 1 << links[i].name) { |
242 |
|
elmref.style.display=''; |
243 |
|
if (elmref0) elmref0.bgColor = '#eeeeee'; |
244 |
|
} else { |
245 |
|
elmref.style.display = 'none'; |
246 |
|
if (elmref0) elmref0.bgColor = '#e0e0e0'; |
247 |
|
} |
248 |
|
} else if(elmref) { |
249 |
|
// default: show all |
250 |
|
new_cookie |= 1 << links[i].name; |
251 |
|
if (elmref.style.display=='none') { |
252 |
|
elmref.style.display=''; |
253 |
|
if (elmref0) elmref0.bgColor = '#eeeeee'; |
254 |
|
} else { |
255 |
|
// hide? no... |
256 |
|
//elmref.style.display = 'none'; |
257 |
|
//if (elmref0) elmref0.bgColor = '#e0e0e0'; |
258 |
|
if (elmref0) elmref0.bgColor = '#eeeeee'; |
259 |
|
} |
260 |
|
} |
261 |
|
} |
262 |
|
} |
263 |
|
if (new_cookie) Set_Cookie("##cookie_name##",new_cookie); |
264 |
|
</script> |
265 |
|
HTMLEND |
266 |
|
|
267 |
|
if ($dynamic_js) { |
268 |
|
my $cookie_name = $key; |
269 |
|
$cookie_name =~ s/[^a-zA-Z0-9]//g; |
270 |
|
$html =~ s/##cookie_name##/$cookie_name/g; |
271 |
|
print OUT $html; |
272 |
|
} |
273 |
|
|
274 |
print OUT "</body></html>"; |
print OUT "</body></html>"; |
275 |
close(OUT); |
close(OUT); |
276 |
|
|
278 |
|
|
279 |
exit; |
exit; |
280 |
|
|
281 |
|
sub do_html { |
282 |
|
my ($desc,$url,$img) = @_; |
283 |
|
if ($dynamic_js) { |
284 |
|
my $html =<<'HTMLEND'; |
285 |
|
<tr bgcolor='#e0e0e0' id=##id##_h0> |
286 |
|
<td><a name="##id##"><a href="###id##" id=DynMessLink name=##id## >##desc##</a></td> |
287 |
|
</tr> |
288 |
|
<tr id=##id##_h1 style='' bgcolor='#ffffff' > |
289 |
|
<td><a href="##url##"><img src="##img##"</td> |
290 |
|
</tr> |
291 |
|
HTMLEND |
292 |
|
$html =~ s/##desc##/$desc/; |
293 |
|
$html =~ s/##url##/$url/; |
294 |
|
$html =~ s/##img##/$img/; |
295 |
|
$html =~ s/##id##/$dynamic_js/g; |
296 |
|
$dynamic_js++; # increment usage counter |
297 |
|
return $html; |
298 |
|
} else { |
299 |
|
return "$desc<br><a href=\"$url\"><img src=\"$img\"></a><br>\n"; |
300 |
|
} |
301 |
|
} |
302 |
|
|
303 |
sub localHandleTargetInstance { |
sub localHandleTargetInstance { |
304 |
my($Name, $target) = @_; |
my($Name, $target) = @_; |
305 |
|
|
306 |
$targetpath = $target->{'auto-target-path'}; |
my $targetpath = $target->{'auto-target-path'}; |
307 |
$targetname = $target->{'auto-target-name'}; |
my $targetname = $target->{'auto-target-name'}; |
308 |
|
|
309 |
if (! defined($target->{'skip-overview'})) |
my @skip_views = split(/[\s,]+/,$target->{'skip-view'}) if ($target->{'skip-view'}); |
310 |
{ |
print "### ",join("|",@skip_views),"\n"; |
311 |
|
|
312 |
|
if (defined($target->{'skip-overview'})) { |
313 |
|
Info("Skipping target $targetname."); |
314 |
|
} else { |
315 |
Info("Working on target $targetname."); |
Info("Working on target $targetname."); |
316 |
my($reqRanges,@ranges); |
my($reqRanges,@ranges); |
317 |
|
|
330 |
|
|
331 |
foreach $range (@ranges) |
foreach $range (@ranges) |
332 |
{ |
{ |
333 |
$rangeLabel = rangeToLabel($range); |
my $rangeLabel = rangeToLabel($range); |
334 |
|
|
335 |
my($paramtarget) = "$targetpath/$targetname"; |
my($paramtarget) = "$targetpath/$targetname"; |
336 |
|
|
347 |
|
|
348 |
# find the ds names based on the target type |
# find the ds names based on the target type |
349 |
my($ttype) = lc($target->{'target-type'}); |
my($ttype) = lc($target->{'target-type'}); |
350 |
my($ttRef) = $main::gCT->configHash($Name, 'targettype', $ttype, $target); |
my($ttRef) = $gCT->configHash($Name, 'targettype', $ttype, $target); |
351 |
|
|
352 |
# If there are views defined, then we generate graphs |
# If there are views defined, then we generate graphs |
353 |
# for each view. |
# for each view. |
354 |
|
|
355 |
my($dslist); |
my($dslist); |
356 |
|
|
357 |
if (defined($ttRef->{'view'})) |
if (defined($ttRef->{'view'})) { |
|
{ |
|
358 |
my($v); |
my($v); |
359 |
foreach $v (split(/\s*,\s*/, $ttRef->{'view'})) |
foreach $v (split(/\s*,\s*/, $ttRef->{'view'})) { |
360 |
{ |
my ($view_name,undef) = split(/\s*:\s*/,$v); |
361 |
|
if (grep(/$view_name/,@skip_views)) { |
362 |
|
Info("Skip view $v"); |
363 |
|
next; |
364 |
|
} |
365 |
# views are like this: "cpu: cpu1load cpu5load" |
# views are like this: "cpu: cpu1load cpu5load" |
366 |
my($vname, $dss) = split(/\s*:\s*/, $v, 2); |
my($vname, $dss) = split(/\s*:\s*/, $v, 2); |
367 |
|
|
369 |
$dslist =~ s/\s*$//; |
$dslist =~ s/\s*$//; |
370 |
$dslist =~ s/\s+/,/g; |
$dslist =~ s/\s+/,/g; |
371 |
|
|
372 |
$URL = "$gBaseURL?type=png&target=$paramtarget"; |
my $URL = "$gBaseURL?type=png&target=$paramtarget"; |
373 |
$URL .= "&dslist=$dslist&range=$paramrange"; |
$URL .= "&dslist=$dslist&range=$paramrange"; |
374 |
my $desc = "$paramtarget $vname"; |
my $desc = "$paramtarget $vname"; |
375 |
$desc .= " <b>".$target->{'short-desc'}."</b>" if (defined $target->{'short-desc'}); |
$desc .= " <b>".$target->{'short-desc'}."</b>" if (defined $target->{'short-desc'}); |
379 |
|
|
380 |
Info("Retrieving graph for $desc"); |
Info("Retrieving graph for $desc"); |
381 |
# getURL($URL,"$path/$name-$vname-$rangeLabel.png"); |
# getURL($URL,"$path/$name-$vname-$rangeLabel.png"); |
382 |
$tmp_URL = "$gBaseURL?target=$paramtarget&range=d:w:m:y&view=$vname"; |
my $tmp_URL = "$gBaseURL?target=$paramtarget&range=d:w:m:y&view=$vname"; |
383 |
$html{"$rangeLabel\t$paramtarget"}.="$desc<br><a href=\"$tmp_URL\"><img src=$URL></a><br>\n"; |
$html{"$rangeLabel\t$paramtarget"}.=do_html($desc,$tmp_URL,$URL); |
384 |
} |
} |
385 |
} else { |
} else { |
386 |
$dslist = $ttRef->{'ds'}; |
$dslist = $ttRef->{'ds'}; |
387 |
# squeeze out any extra spaces |
# squeeze out any extra spaces |
388 |
$dslist = join(',', split(/\s*,\s*/, $dslist)); |
$dslist = join(',', split(/\s*,\s*/, $dslist)); |
389 |
|
|
390 |
$URL = "$gBaseURL?type=png&target=$paramtarget"; |
my $URL = "$gBaseURL?type=png&target=$paramtarget"; |
391 |
$URL .= "&dslist=$dslist&range=$paramrange"; |
$URL .= "&dslist=$dslist&range=$paramrange"; |
392 |
my $desc ="$paraminst $rangeLabel"; |
my $desc ="$paraminst $rangeLabel"; |
393 |
$desc .= " <b>".$target->{'short-desc'}."</b>" if (defined $target->{'short-desc'}); |
$desc .= " <b>".$target->{'short-desc'}."</b>" if (defined $target->{'short-desc'}); |
398 |
Info("Retrieving graph for $desc"); |
Info("Retrieving graph for $desc"); |
399 |
|
|
400 |
# getURL($URL,"$path/$name-$rangeLabel.png"); |
# getURL($URL,"$path/$name-$rangeLabel.png"); |
401 |
$tmp_URL = "$gBaseURL?target=$paramtarget&range=d:w:m:y"; |
my $tmp_URL = "$gBaseURL?target=$paramtarget&range=d:w:m:y"; |
402 |
$html{"$rangeLabel\t$paramtarget"}.="$desc:<br><a href=\"$tmp_URL\"><img src=$URL><a/><br>"; |
$html{"$rangeLabel\t$paramtarget"}.=do_html($desc,$tmp_URL,$URL); |
403 |
} |
} |
404 |
} |
} |
405 |
} |
} |