#!/usr/bin/perl -w

use strict;

require HTTP::Request;
require LWP::UserAgent;

if($#ARGV < 2)
{
    print "\nusage: tinder-pvfs2-status <build name> " .
          "<status> <start time> [status info]\n\n";
    exit 1;
}

my $buildname=shift @ARGV;
my $status=shift @ARGV;
my $starttime=shift @ARGV;

my $binfo = "";
if($#ARGV > -1)
{
   $binfo = "TinderboxPrint: " . join(" ", @ARGV);
}

my $admin="slang\@mcs.anl.gov";
my $datestr=time();

my $logoutput = "";
my $line;
while (defined($line = <STDIN>))
{
    $logoutput .= $line;
}

my $msg = <<"BODYEOF";

tinderbox: administrator: $admin
tinderbox: starttime: $starttime
tinderbox: buildname: $buildname
tinderbox: status: $status
tinderbox: timenow: $datestr
tinderbox: tree: PVFS2
tinderbox: errorparser: unix
tinderbox: END

$binfo

$logoutput

BODYEOF
;

my $req = HTTP::Request->new( 
    "POST" => "http://www.pvfs.org/cgi-bin/pvfs2/tinderbox2/process_build" );
$req->content( $msg );

my $ua = LWP::UserAgent->new;

my $resp = $ua->request( $req );
if( $resp->is_success )
{
	print $resp->content;
}
else
{
	die $resp->status_line;
}

