CLI Guide

Table Of Contents
# Generate the login hash used to authenticate the user. The username
# and password are hard coded here to illustrate the requirements for the string.
# The user name and password must be joined with an underscore.
my $auth_data = "username_password";
my $sha256_hash = sha256_hex( $auth_data );
# Create a user agent for sending https requests and generate a request object.
$user_agent = LWP::UserAgent->new( );
$url = 'https://IP-address/api/login/' . $sha256_hash;
$request = HTTP::Request->new( GET => $url );
# Send the request object to the system. The response will be returned.
$response = $user_agent->request($request);
# 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 );
Using the CLI
13