Access REST API via Perl (Perl2Rest NetMRI)

Posts: 15
1062     0

This is a sekelton Perl script for access the NetMRI REST API.  This allows you to pull back data and use the strength of Perl to manipulate the data as you see fit.



use Data:Smiley Very Happyumper;
use LWP;
use URI;
use JSON;


my $browser=LWP::UserAgent->new();

#Open up a cookie jar in a local file which only exists for the length of runtime
$browser->cookie_jar({ file => ".$$.cookies.txt" });

#Turn off SSL verification (Either method works)
$browser->ssl_opts(verify_hostname => 0);

#Build our authentication request
$url = URI->new("https://$SERVER/api/$VERSION/authenticate.json");
    username => "$USER",
    password => "$PASS"
#Authenticate, place cookies in the cookie jar automatically
my $response=$browser->get($url);

#BEGIN our scripting here

#In this example we will get all of the devices and then print out their IPs

#Build the WAPI URL by passing options to query_form
$url = URI->new("https://$SERVER/api/$VERSION/devices/index");
    sort => 'DeviceIPDotted'

#Execute the request
my $response=$browser->get($url);

#Create a Perl data object reference from JSON

print "Total Devices: ",$ref->{'total'},"\n";

foreach $device (@$devarray){
  print "($i) ",$device->{'DeviceIPDotted'},",",$device->{'DeviceMAC'},"\n";

#print Dumper($ref),"\n\n";


You can use this sort of

Posts: 353
1062     0

You can use this sort of script if you want to access the API via Perl but do not want to install the full Perl API package. The API package includes a complete framework binding the JSON object to Perl classes, however, and therefore is usually much more convenient.



Re: Access REST API via Perl (Perl2Rest NetMRI)

Posts: 25
1062     0
How to update EA to the using rest in Perl ?

Re: Access REST API via Perl (Perl2Rest NetMRI)

Posts: 463
1062     0

Can you please start a new thread instead of replying to a very old one.


You can add a link to it Smiley Happy

Follow me on LinkedIn:
Showing results for 
Search instead for 
Did you mean: 

Recommended for You