Vinod Subramaniam

Getting started with the HCS 8.0 REST API for HTNM

Discussion created by Vinod Subramaniam Employee on Apr 29, 2014
Latest reply on Aug 4, 2014 by Vinod Subramaniam

Example uses perl and the perl library REST::Client.

api_key is the HTNM username and api_pass is the corresponding password.

 

 

#!/usr/bin/perl

use MIME::Base64;

use REST::Client;

use Encode qw( decode );

use Text::CSV;

 

# Define HTNM Username and Password

my $api_key = "******";

my $api_pass = "********";

my $client = REST::Client->new();

 

#Set the HTNM URL and encode the userid and password using BASE64 encoding

$client->setHost("http://172.17.237.129:22015/TuningManager/");

$client->addHeader("Authorization", "Basic " .

                   encode_base64("$api_key:$api_pass", ""));

 

# Define the REST HTTP GET URL with the metrics that you desire. The metric names are in the User Guide.

my $response = $client->GET("/v1/objects/RAID_PI_LDA?agentInstanceName=VSP_53086&hostName=RHEL64-2&startTime=2014-04-08T00:00Z&endTime=2014-04-09T23:55Z&fields=RECORD_TIME%1FREAD_IO_RATE%1FWRITE_IO_RATE%1FREAD_XFER_RATE%1FWRITE_XFER_RATE");

 

Check the HTTP response code.

print $client->responseCode();

 

#Write the REST API return values to a temp file

open (TEMPFILE, '>/tmp/rest.out');

print TEMPFILE $client->responseContent();

close (TEMPFILE);

 

# Parse the temp file from above

my $csv = Text::CSV->new();

open(my $data, '<', "/tmp/rest.out");

while (my $fields = $csv->getline( $data )) {

  printf "%6.2f, %6.2f, %6.2f, %6.2f\n", "$fields->[1]", "$fields->[2]", "$fields->[3]", "$fields->[4]";

}

Outcomes