#!/usr/bin/perl -I/opt/SUNWstade/lib
#<copyright>
# ----------------------------------------------------------
# Sun Proprietary/Confidential Code
# Copyright 2001, Sun Microsystems, Inc. All rights reserved.
# ----------------------------------------------------------
#</copyright>

use Util;
use LWP::UserAgent;

if ($ARGV[0] && defined($ARGV[1]) ) {
  my $URLS;
  print "Testing $ARGV[0]...\n";
  $ip = $ARGV[0];
  if($ARGV[1] ne "all"){
    $FILE = $ARGV[1];
    push(@URLS, "http://$ip/$FILE");
  }else{
    @URLS = getAllURLS($ip);
  }
    
} else {
  print "\n  Usage: testdsp <ip> [page_name|all] \n";
  print "  Example: dsp12 all \n\n";
  print "  Example: dsp12 DISKS.xml \n\n";
  exit;
}


if (!Util->testIp($ip,3)) {
  print "ERROR: Cannot ping $ip\n";
  exit;
}


foreach $url (@URLS) {
print "URL=$url \n";
$time = time;

$ua = new LWP::UserAgent;

#  $ua->agent("AgentName/0.1 " . $ua->agent);
#  $ua->proxy('http' => "http://cache-brm.Central.Sun.COM:8080");
#  $ua->credentials("http://diag210.central", "NobleGUI", "guest", "");

my $req = new HTTP::Request(GET => $url);

my $res = $ua->request($req);

  print "\n**** $url ****\n";
if ($res->is_success) {
  $s = length($res->content);
#  print "GOT " . length($res->content);
  print $res->content;
} else {
  print "$FILE FAILED!";
}

print "bytes in " . (time - $time) . "secs\n";
}

sub getAllURLS{
  my ($name, $other)=@_;
  my @URLS;
  my @FILES =
    (
      "",
      "sa_chas.xml",
      "sa_disks.xml",
      "sa_fcprt.xml",
      "sa_sys.xml",
      "sa_vols.xml",
      "chassis.xml",
      "disks.xml",
      "svsds.xml",
      "system.xml",
      "volume.xml",
      "volumes.xml"
  );
  foreach $file (@FILES){
    #push(@URLS, "http://guest\@$name/$file");
    push(@URLS, "http://$name/$file");
  }
print "URLS: @URLS\n";
  return @URLS;
}

