bloxHub

www.infoblox.com/community
5 posts / 0 new
finding devices using curl NetMRI REST URL

Hi Team,

I have seen Tools->Network->API Documentation and Help->Additional Documentation->API Developers guide. And i have noticed availability of http/https REST API i.e., NetMRI Core API, a language-independent, HTTP/HTTPS-based, RESTful interface built into the NetMRI product.

In the API Developers guide it is mentioned /api/base_uri to find the BASE URL but i couldn't find by trying it on my server.

I would like to get for e.g., device groups in network by hitting http url like below (ofcourse with login credentials in command line):

curl http://mynetmri.server.com/device_groups/index

Could you tell me if i could leverage RESTful interface of NetMRI using CURL or perl LWP http client instead of using NetMRI::API module.

Thanks !!

+1
0
-1
Tags
NetMRI,Network analysis,API
Re: finding devices using curl NetMRI REST URL

Hey meischandra,

Great question - give me a few to work with some folks internally to identify an appropriate response.

Best,

Eric

+1
0
-1
Re: finding devices using curl NetMRI REST URL

Hi meischandra,

The /api/base_uri call is used to determine the URI for a specific version of the API; you need to pass in the desired API version. This is is a best practice in the event that the API gets relocated, and also to allow a script to be sure it is getting the correct API version.

The API version supported by your NetMRI is found on the Tools->Network->API Documentation page, but it is buried deep in there. You can also see it in the file name of the Perl CPAN distribution file under the Perl Distribution link from that same page. You can also find this version by clicking on the documentation of any specific API under API List or API Index; it will be in the browser URL. Granted, this is too obscure, and we will be fixing it.

That said, currently shipping NetMRI 6.4 has API version 2.5; the NetMRI 6.3 version is running API version 2.4.

If you are using CURL on the command line:

% curl --basic --user <user>:<password> http://mynetmri.server.com/api/2.5/device_groups

or equivalently

% curl --basic --user <user>:<password> http://mynetmri.server.com/api/2.5/device_groups/index

to get the devices in a particular device group, say device group 1:

% curl --basic --user <user>:<password> http://mynetmri.server.com/api/2.5/devices?DeviceGroupID=1

Note that this will return JSON by default; to get XML, append .xml to the URL:

% curl --basic --user <user>:<password> http://mynetmri.server.com/api/2.5/devices.xml?DeviceGroupID=1

Also, I would highly recommend you use curl's cookies/cookie jar handling rather than using basic authentication each time. If you use local authentication, it doesn't matter much, but if you use a remote authentication mechanism then it will have to validate your credentials which each basic auth request.

PS. You can use the URLs in the browser directly of course. You'll get XML back by default, because the browser sends an Accepts header that includes XML.

+1
0
-1
Re: finding devices using curl NetMRI REST URL

Hey John,

Yeah -c cookies is nice option instead of wide open --user.

Also i could get CSV format by simply hitting for e.g., NetMRI v2.5

curl --user userid:password "http://mynetmri.server.com/api/2.5/devices.csv"

Even you can select specific columns in output say DeviceName, Device IP and Device ID by following thing.

curl --user userid:password "http://mynetmri.server.com/api/2.5/devices?select%5B%5D=DeviceID&select%...

cheers,
chandra

+1
0
-1
Re: finding devices using curl NetMRI REST URL

That's correct. .csv will work for the index methods.

You can use the select[]= syntax although for the select parameter, which will never contain commas in a value, you can also use the simpler comma-delimited format: select=col1,col2,col3.

Enjoy!

John

 

+1
0
-1