2002-11-20 22:31:44 +03:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
#
|
|
|
|
# Graph tree-open status, via tbox graph server.
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
use Sys::Hostname; # for ::hostname()
|
|
|
|
|
2002-11-21 04:45:04 +03:00
|
|
|
# Location of this file. Make sure that hand-runs and crontab-runs
|
|
|
|
# of this script read/write the same data.
|
|
|
|
my $script_dir = "/builds/tinderbox/mozilla/tools/tinderbox";
|
|
|
|
|
|
|
|
my $sheriff_string;
|
2002-11-20 22:31:44 +03:00
|
|
|
|
|
|
|
# Send data to graph server.
|
|
|
|
sub send_results_to_server {
|
|
|
|
my ($value, $data, $testname, $tbox) = @_;
|
|
|
|
|
|
|
|
my $tmpurl = "http://tegu.mozilla.org/graph/collect.cgi";
|
|
|
|
$tmpurl .= "?value=$value&data=$data&testname=$testname&tbox=$tbox";
|
|
|
|
|
|
|
|
print "send_results_to_server(): \n";
|
|
|
|
print "tmpurl = $tmpurl\n";
|
|
|
|
|
|
|
|
# libwww-perl has process control problems on windows,
|
|
|
|
# spawn wget instead.
|
|
|
|
if ($Settings::OS =~ /^WIN/) {
|
|
|
|
system ("wget", "-o", "/dev/null", $tmpurl);
|
|
|
|
print "send_results_to_server() succeeded.\n";
|
|
|
|
} else {
|
|
|
|
my $res = eval q{
|
|
|
|
use LWP::UserAgent;
|
|
|
|
use HTTP::Request;
|
|
|
|
my $ua = LWP::UserAgent->new;
|
|
|
|
$ua->timeout(10); # seconds
|
|
|
|
my $req = HTTP::Request->new(GET => $tmpurl);
|
|
|
|
my $res = $ua->request($req);
|
|
|
|
return $res;
|
|
|
|
};
|
|
|
|
if ($@) {
|
|
|
|
warn "Failed to submit startup results: $@";
|
|
|
|
print "send_results_to_server() failed.\n";
|
|
|
|
} else {
|
|
|
|
print "Results submitted to server: \n",
|
|
|
|
$res->status_line, "\n", $res->content, "\n";
|
|
|
|
print "send_results_to_server() succeeded.\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub is_tree_open {
|
|
|
|
my $tbox_url = "http://tinderbox.mozilla.org/showbuilds.cgi?tree=SeaMonkey";
|
|
|
|
|
|
|
|
# Dump tbox page source into a file.
|
|
|
|
print "HTTP...";
|
2002-11-21 04:45:04 +03:00
|
|
|
system ("wget", "-q", "-O", "$script_dir/tbox.source", $tbox_url);
|
2002-11-20 22:31:44 +03:00
|
|
|
print "done\n";
|
|
|
|
|
|
|
|
my $rv = 0;
|
|
|
|
|
2002-11-21 04:45:04 +03:00
|
|
|
$sheriff_string = "";
|
|
|
|
|
2002-11-20 22:31:44 +03:00
|
|
|
# Scan file, looking for line that starts with <a NAME="open">
|
2002-11-21 04:45:04 +03:00
|
|
|
open TBOX_FILE, "$script_dir/tbox.source";
|
2002-11-20 22:31:44 +03:00
|
|
|
while (<TBOX_FILE>) {
|
2002-11-21 04:45:04 +03:00
|
|
|
# Scan for open string
|
2002-11-20 22:31:44 +03:00
|
|
|
if(/^<a NAME="open">/) {
|
|
|
|
# look for "open" string
|
|
|
|
if (/open<\/font>$/) {
|
|
|
|
print "open\n";
|
|
|
|
$rv = 1;
|
|
|
|
} else {
|
|
|
|
print "closed\n";
|
|
|
|
$rv = 0;
|
|
|
|
}
|
|
|
|
}
|
2002-11-21 04:45:04 +03:00
|
|
|
|
|
|
|
# Scan for sheriff string & save it off for HTTP submit later.
|
|
|
|
if(/^<br><a NAME="sheriff"><\/a>/) {
|
2002-11-21 09:23:39 +03:00
|
|
|
chomp;
|
2002-11-21 04:45:04 +03:00
|
|
|
$sheriff_string = $_;
|
|
|
|
|
|
|
|
# Strip out content to save space.
|
|
|
|
|
|
|
|
# Strip out permanent content.
|
|
|
|
$sheriff_string =~ s/^<br><a NAME="sheriff"><\/a>//;
|
|
|
|
|
|
|
|
# Crude attempt at reducing the random html that shows up here.
|
|
|
|
# Order is important, pick off easy tags, then make it legal cgi,
|
|
|
|
# then shorten it up.
|
|
|
|
$sheriff_string =~ s/<[pP]>//g;
|
2002-11-21 09:23:39 +03:00
|
|
|
$sheriff_string =~ s/\015//g; # ^M
|
2002-11-21 04:45:04 +03:00
|
|
|
$sheriff_string =~ s/<br>//g;
|
2002-11-21 05:34:44 +03:00
|
|
|
$sheriff_string =~ s/<\/a>//g;
|
2002-11-21 04:45:04 +03:00
|
|
|
$sheriff_string =~ s/<//g;
|
|
|
|
$sheriff_string =~ s/>//g;
|
|
|
|
$sheriff_string =~ s/"/ /g;
|
|
|
|
$sheriff_string =~ s/\///g;
|
|
|
|
$sheriff_string =~ s/\\//g;
|
|
|
|
$sheriff_string =~ s/#/[lb]/g;
|
|
|
|
$sheriff_string =~ s/mailto://g;
|
2002-11-23 02:19:20 +03:00
|
|
|
$sheriff_string =~ s/[aA][iI][mM]://g;
|
2002-11-22 10:06:10 +03:00
|
|
|
$sheriff_string =~ s/[iI][rR][cC]://g;
|
2002-11-21 04:45:04 +03:00
|
|
|
$sheriff_string =~ s/a href//g;
|
|
|
|
$sheriff_string =~ s/[sS]heriff//g;
|
2002-11-22 09:05:39 +03:00
|
|
|
$sheriff_string =~ s/[mM]onday//g;
|
|
|
|
$sheriff_string =~ s/[tT]uesday//g;
|
|
|
|
$sheriff_string =~ s/[wW]ednesday//g;
|
|
|
|
$sheriff_string =~ s/[tT]hursday//g;
|
|
|
|
$sheriff_string =~ s/[fF]riday//g;
|
|
|
|
$sheriff_string =~ s/[wW]eekend//g;
|
2002-11-21 04:45:04 +03:00
|
|
|
$sheriff_string =~ s/^[tT]he //g;
|
|
|
|
$sheriff_string =~ s/\/a//g;
|
|
|
|
$sheriff_string =~ s/netscape.com/nscp/g;
|
|
|
|
$sheriff_string =~ s/mozilla.org/moz/g;
|
|
|
|
$sheriff_string =~ s/ is / /g;
|
|
|
|
$sheriff_string =~ s/ for / /g;
|
|
|
|
$sheriff_string =~ s/ on / /g;
|
2002-11-22 09:05:39 +03:00
|
|
|
$sheriff_string =~ s/ in / /g;
|
2002-11-21 04:45:04 +03:00
|
|
|
$sheriff_string =~ s/ = / /g;
|
|
|
|
$sheriff_string =~ s/ - / /g;
|
|
|
|
|
|
|
|
$sheriff_string = substr($sheriff_string,0,60);
|
|
|
|
print "sheriff string = $sheriff_string\n";
|
|
|
|
}
|
2002-11-20 22:31:44 +03:00
|
|
|
}
|
|
|
|
close TBOX_FILE;
|
|
|
|
|
|
|
|
# Clean up.
|
2002-11-21 04:45:04 +03:00
|
|
|
unlink("$script_dir/tbox.source");
|
2002-11-20 22:31:44 +03:00
|
|
|
|
|
|
|
return $rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# main
|
|
|
|
{
|
|
|
|
my $time_since_open = 0;
|
|
|
|
|
|
|
|
# Get tree status.
|
|
|
|
if(is_tree_open()) {
|
|
|
|
|
|
|
|
# Record tree open time if not set.
|
2002-11-21 04:45:04 +03:00
|
|
|
if (not (-e "$script_dir/timefile")) {
|
|
|
|
open TIMEFILE, ">$script_dir/timefile";
|
2002-11-20 22:31:44 +03:00
|
|
|
print TIMEFILE time();
|
|
|
|
close TIMEFILE;
|
|
|
|
} else {
|
|
|
|
# Timefile found, compute difference and report that number.
|
|
|
|
print "found timefile!\n";
|
|
|
|
|
|
|
|
my $time_tree_opened = 0;
|
|
|
|
my $now = 0;
|
|
|
|
|
2002-11-21 04:45:04 +03:00
|
|
|
open TIMEFILE, "$script_dir/timefile";
|
2002-11-20 22:31:44 +03:00
|
|
|
while (<TIMEFILE>) {
|
|
|
|
chomp;
|
|
|
|
$time_tree_opened = $_;
|
|
|
|
}
|
|
|
|
close TIMEFILE;
|
|
|
|
print "time_tree_opened = $time_tree_opened\n";
|
|
|
|
|
|
|
|
$now = time();
|
|
|
|
print "now = $now\n";
|
|
|
|
|
2002-11-21 04:45:04 +03:00
|
|
|
# Report time in hours.
|
|
|
|
$time_since_open = ($now - $time_tree_opened)/3600;
|
|
|
|
print "time_since_open (hours) = $time_since_open\n";
|
2002-11-26 04:02:59 +03:00
|
|
|
|
2002-11-26 11:20:40 +03:00
|
|
|
# Clamp time to 20 hours so we don't get huge spikes for
|
2002-11-26 04:02:59 +03:00
|
|
|
# extended open times (weekends)
|
2002-11-26 11:20:40 +03:00
|
|
|
if($time_since_open > 20.0) {
|
|
|
|
$time_since_open = 20.0;
|
2002-11-26 04:02:59 +03:00
|
|
|
}
|
|
|
|
|
2002-11-20 22:31:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
# tree is closed, leave tree_open_time at zero.
|
|
|
|
|
|
|
|
# Delete timefile if there is one.
|
2002-11-21 04:45:04 +03:00
|
|
|
if (-e "$script_dir/timefile") {
|
|
|
|
unlink("$script_dir/timefile");
|
2002-11-20 22:31:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-21 04:45:04 +03:00
|
|
|
send_results_to_server("$time_since_open", "$sheriff_string", "treeopen", ::hostname());
|
2002-11-20 22:31:44 +03:00
|
|
|
}
|