| Current Path : /bin/ |
| Current File : //bin/wbemcat |
#!/usr/bin/perl
use strict;
use Getopt::Long;
use LWP::UserAgent;
my $version = "1.0.0";
my $port = 5988;
my $host = "localhost";
my $protocol = "http";
my $user="";
my $password="";
my $cred_host="";
# Usage description
sub usage {
print "Usage: wbemcat [OPTION]... [FILE]\n";
print "Send FILE containing CIM-XML data to CIMOM and display returned data.\n";
print "If no input FILE specified then read the data from stdin.\n";
print "\nOptions:\n";
print " -t, --protocol=PROTOCOL\tProtocol with which to connect. Default=$protocol\n";
print " -h, --host=HOSTNAME\tName of host running the CIMOM. Default=$host\n";
print " -p, --port=PORT\tPort that the CIMOM is listening on. Default=$port\n";
print " -u, --user=USER\tUser Name for authentication\n";
print " -pwd, --password=PASSWORD\tPassword for authentication\n";
print " -?, --help\t\tDisplay this help and exit\n";
exit;
}
# Process command line options, if any
GetOptions("host|h=s" => \$host,
"port|p=i" => \$port,
"protocol|t=s" => \$protocol,
"user|u=s" => \$user,
"password|pwd=s" => \$password,
"help|?" => sub{usage}) || usage;
my $file = @ARGV[0];
# Read all the XML data from the input file
my @xml;
if ($file) {
open(XMLFILE,"<$file") || die "Cannot open $file: $!";
@xml = (<XMLFILE>);
close(XMLFILE) || warn "Cannot close $file: $!";
} else {
# If no input file specified then read XML data from stdin
@xml = (<STDIN>);
}
if ( $user && $password )
{
$cred_host=$user . ":" . $password . "@" . $host;
}
else
{
$cred_host = $host;
}
my $ua = LWP::UserAgent->new;
$ua->agent("wbemcat $version");
my $req = HTTP::Request->new(POST => "$protocol://$cred_host:$port/cimom");
$req->content_type("application/xml");
$req->header("CIMProtocolVersion" => "1.0",
"CIMOperation" => "MethodCall");
$req->content(join("", @xml));
my $res = $ua->request($req);
if($res->is_success) {
print $res->content, "\n";
} else {
print $res->status_line, "\n";
}