Forum Discussion
Derek_21893
Nimbostratus
Feb 16, 2010Perl script to dump API response->result
I'm sure I'm not the only one who has fun trying to figure out the sometimes massive data structures returned by an iControl API response. I've written a simple Perl program to dump the response for you using Data::Dumper.
You'll need iControlTypeCast.pm in the same directory as this script.
Other module requirements:
SOAP::Lite
GetOpt::Long
Data::Dumper
MIME::Base64
You can edit the variables at the beginning of the script to match your installation, such that you do not have to specify a bunch of cmd line args every time. I just point them at my lab F5 device.
Hope this helps someone, Joe, maybe this could be included in the sample Perl scripts in a future API release?
Thanks,
-Derek
!/usr/bin/perl -w
icontrol-dump
using Data::Dumper, dump the contents of an API response->result
written by Derek Andree derek.andree@gmail.com
use strict;
use Data::Dumper;
use Getopt::Long;
use SOAP::Lite;
use MIME::Base64;
require iControlTypeCast;
options, set for default behavior for your network if you like
this will let you not have to use command line args
my $ip = 0; management ip of an F5
my $proto = "https"; protocol, either http or https
my $port = 443; port to connect to
my $user = ""; username to connect as
my $pass = ""; password
my $urn = ""; iControl URN
my $method = ""; method to use
my $help = 0;
my $opts = GetOptions (
"ip=s" => \$ip,
"proto=s" => \$proto,
"port=i" => \$port,
"user=s" => \$user,
"pass=s" => \$pass,
"urn=s" => \$urn,
"method=s" => \$method,
"h" => \$help,
"help" => \$help
);
if ($help) {
&usage;
}
unless ($ip) {
print "Must specify an IP address!\n";
&usage;
}
unless ($proto) {
print "Must specify a protocol, either http or https!\n";
&usage;
}
unless ($port) {
print "Must specify a port number!\n";
&usage;
}
unless ($user) {
print "Need a username to connect with, try --user blah\n";
&usage;
}
unless ($pass) {
print "No password given, try --pass somepAssWord\n";
&usage;
}
unless ($urn) {
print "Must have an iControl URN\n";
&usage;
}
unless ($method) {
print "No method specified, don't know what I'm doing.\n";
&usage;
}
my $obj = SOAP::Lite->uri("urn:iControl:$urn")
->proxy("$proto://$ip:$port/iControl/iControlPortal.cgi");
$obj->transport->http_request->header
(
'Authorization' =>
'Basic ' . MIME::Base64::encode("$user:$pass", ''),
);
my $response = $obj->$method;
&check_response($response);
print Dumper($response->result);
sub usage {
print "usage: icontrol-dump [--urn Urn/Name] [--ip ip_address]\n";
print " [--proto http|https] [--port port]\n";
print " [--user username] [--pass password]\n";
print " [--method method_name]\n";
print "example:\n";
print "./icontrol-dump --ip 10.10.10.10 --user fred --pass 123 \\\n";
print " --urn System/SystemInfo --method get_cpu_metrics\n";
exit;
}
sub check_response {
my $response = shift;
if ($response->fault) {
my $msg = $response->faultcode . " : " . $response->faultstring;
die $msg;
}
}
- JRahm
Admin
This is great, Derek! Mind if I add this to the wiki? - Derek_21893
Nimbostratus
By all means, feel free to add it to the wiki!
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects