14
Using the CLI
$telnet = new Net::Telnet ( Timeout=>10,
Errmode=>'die',
Prompt => '/\# $/i');
if ( !cLogin($ipAddr, $username, $password) == 1 )
{
print("Error: $username user failed to log in. Exiting.\n");
$telnet->close;
exit(0);
}
For scripting support, the following command can be used to access the XML API and to disable the
paging mode that pauses for each full screen of command output.
$telnet->cmd("set cli-parameters api-embed pager disabled");
The following code segment shows how to get the entire configuration information from the CLI and print
the output. The output can easily be redirected to a file for archiving.
@sV = $telnet->cmd("show configuration");
for ($i=0; $i<scalar(@sV); $i++)
{
print ("@sV[ $i ]");
}
Because basic command-line semantics provide prompts for user input and response time is indeterminate,
scripts must use an “expect”-type mechanism to scan output for prompts. It is more efficient to use the HTTP
interface to access the XML API. The following example shows how to construct a Perl script to
communicate with the XML API via HTTP.
use LWP::UserAgent;
use Digest::MD5 qw(md5_hex);
use XML::LibXML;
# generate MD5 hash using default username/password
my $md5_data = "manage_!manage";
my $md5_hash = md5_hex( $md5_data );
print "$md5_hash\n";
# create the URL and send an http GET request
$ua = LWP::UserAgent->new;
$url = 'http://10.0.0.2/api/login/' . $md5_hash;
print ("Sending to $url\n");
$req = HTTP::Request->new(GET => $url);
$res = $ua->request($req);
# Parse the XML content using LibXML to obtain the session key
print $res->content;
my $parser = XML::LibXML->new();
my $doc = $parser->parse_string( $res->content );
my $root = $doc->getDocumentElement;
my @objects = $root->getElementsByTagName('OBJECT');
my @props = $objects[0]->getElementsByTagName('PROPERTY');
my $sessionKey;
foreach my $prop ( @props ) {
my $name = $prop->getAttribute('name');
Summary of Contents for AssuredSAN 6004
Page 11: ...Document conventions and symbols 11 TIP Provides helpful hints and shortcuts...
Page 114: ...114 Alphabetical list of commands See also set cli parameters show protocols...
Page 139: ...show controller statistics 139 See also reset all statistics reset controller statistics...
Page 162: ...162 Alphabetical list of commands See also show power supplies...