CLI Guide

# Once the script has logged in, the response returns back a session key.
# This code shows how to retrieve that session key.
my $parser = XML::LibXML->new();
my $document = $parser->parse_string( $response->content );
my $root = $document->getDocumentElement;
my @objects = $root->getElementsByTagName( 'OBJECT' );
my @properties = $objects[0]->getElementsByTagName( 'PROPERTY' );
my $sessionKey;
foreach my $property ( @properties ) {
my $name = $property->getAttribute( 'name' );
if( $name eq 'response' ) {
$sessionKey = $property->textContent;
}
}
The following example shows how to construct a Python script to communicate with the JSON API using HTTPS:
import sys
import requests
import json
import hashlib
# NOTE: This is to suppress the insecure connection warning for certificate
# verification.
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
url = "https://IP-address"
auth_string = hashlib.sha256('username_password').hexdigest()
# Login and obtain the session key.
headers = {'datatype':'json'}
r = requests.get(url + '/api/login/' + auth_string, headers=headers, verify=False )
response = json.loads(r.content)
sessionKey = response['status'][0]['response']
# Obtain the health of the system
headers = {'sessionKey': sessionKey, 'datatype':'json'}
r = requests.get(url+'/api/show/system', headers=headers, verify=False)
print r.content
response = json.loads(r.content)
print "Health = " + response['system'][0]['health']
The following code segment shows how to get the entire configuration information from the CLI and print the output using the ipa
option for XML output:
NOTE: The output can be redirected to a file for archiving.
$url = 'https://IP-address/api/show/configuration';
$request = HTTP::Request->new(GET => $url );
$request->header('sessionKey' => $sessionKey );
$request->header('dataType' => 'ipa' );
$response = $user_agent->request( $request );
print $response->content;
Alternatively, the dataType in the request header can be set to json for JSON output, or to console for standard CLI text output. Do
not use the console output should for parsing. However, the console output can be useful for tabular reports that are obtained directly
from the CLI commands.
Using XML API output
The Management Controller provides access for monitoring and management using the SSH and Telnet protocols for command-line
interface semantics, or using the HTTP and HTTPS protocols for XML API request/response semantics.
You can use an XML parser, such as XML::Parser in Perl, to process the XML output and store this information as objects.
Using the CLI
13