Infoblox Exchange Cybersecurity Roadshow 2020 – Join us!
North America | Europe | Middle East/Africa | Asia-Pacific

Network Change & Configuration Management

Reply
Accepted Solution

WebAPI to find the number of licensed device managed by Net MRI?

[ Edited ]
Authority
Posts: 41
5855     0

I'm writing a Python webAPI to retrieve the number of licensed devices managed my NetMRI appliance, can someone please advise which API I should be looking ?

I'm able to get the maximum number of devices (device_limit) with below webapi call

http://xvy/api/3/basic_services/license_info?device_limit

 

Any help is much appreciated.

thanks

Nidhi

Re: WebAPI to find the number of licensed device managed by Net MRI?

Adviser
Posts: 353
5856     0
You can get this from:

https://netmri/api/3/device_settings/search?DeviceLicensedInd=true

The "total" will be the count of licensed devices.

John

Re: WebAPI to find the number of licensed device managed by Net MRI?

[ Edited ]
Authority
Posts: 41
5856     0

John,

 

Thanks for replying. I did get the response back of what I was looking. 

Can I have the specific fields for exp (DeviceID and DeviceLicensedInd) rather than all the attributes?

 

For example something related to _return_fields in Infoblox api?

I tried below but still got the same result.

"https://netmri/api/3/device_settings/search?DeviceLicensedInd=true&_return_fields=DeviceID"

 

I have a working script  using PerlAPI for this but I wanted to have a webAPI for the same?

for exp select => [qw( DeviceID DeviceLicensedInd )

 

Thanks

Nidhi

Re: WebAPI to find the number of licensed device managed by Net MRI?

[ Edited ]
Authority
Posts: 41
5856     0

John

 

I'm also having a KeyError while calculating 'total'. I have Python version Python 2.6.6..Can you please help?

 

Code:

response = requests.get( url + search_query, auth=authtok )
if response.status_code >= 200:
data = json.loads(response.content)
devices = []
for x in range(data['total']):
devices.append(data['DeviceLicensedInd'][x]['DeviceID'])

 

Error:

Traceback (most recent call last):
File "xyz.py", line 23, in <module>
for x in range(data['total']):
KeyError: 'total'

 

Thanks

Nidhi

Re: WebAPI to find the number of licensed device managed by Net MRI?

[ Edited ]
Authority
Posts: 32
5856     0

 

With the NetMRI API, you can use "select" to specify which fields to include in the results.

 

For example, 

 

//netmri/api/3/devices/index?select=DeviceIPDotted,DeviceName,DeviceModel

 

For your specific query, you could do

 

//netmri/api/3/device_settings/search?DeviceLicensedInd=true&select=DeviceID

 

Best Regards,

 

-Marc-

 

Re: WebAPI to find the number of licensed device managed by Net MRI?

Adviser
Posts: 353
5856     0
Try printing out data and seeing what it looks like. I would expect data['total'] to work, but data['DeviceLicensedInd'] wouldn't - it would be:


data['device_settings'][x]['DeviceID']


If you use the browser to go to the URL, you'll see the XML version of the response. If you use "search.json" instead of just "search", you'll see the JSON version. This is because the browser includes XML in an Accepts header in the request - the default is actually JSON.

Re: WebAPI to find the number of licensed device managed by Net MRI?

Adviser
Posts: 353
5856     0

As a side note, if you are using Python, you may find this lightweight NetMRI API module to be useful:

 

 

https://github.com/infobloxopen/infoblox-netmri

 

 

John

 

Re: WebAPI to find the number of licensed device managed by Net MRI?

[ Edited ]
Authority
Posts: 41
5856     0

John

 

Thanks for your reply.

I edited my script as below still didn't work. Not sure I'm doing it correct.

Please advise.

 

Thanks

Nidhi


get_license='device_settings/search.jason?DeviceLicensedInd=true'

response = requests.get( url + get_license, auth=authtok )
if response.status_code >= 200:

data = json.loads(response.content)

for x in range(data['total']):
print data['device_settings']['DeviceID']
else:
print "There was an error: Status code", response.status_code
print response.content

 

Error is

for x in range(data['total']):
KeyError: 'total'

Re: WebAPI to find the number of licensed device managed by Net MRI?

Adviser
Posts: 353
5856     0

Sorry, I didn't mean to imply you had to change the script. Since the default is JSON what you had before was OK. What I was saying is that if you go to the URL in a browser, you will see XML - I didn't want you to think that meant that your script was getting XML back. It is getting JSON back because that is the default - it's just that the browser behaves a bit differently.

 

I think you need to print out the response.content and/or data dict to see why it's not working the way we expect. Response code >= 200 will also say everything was fine even if there was a 400 or 500 error. You really want >= 200 and < 300.

 

I suggest though the library I mentioned in the other post, it simplifies things a bit for you.

Re: WebAPI to find the number of licensed device managed by Net MRI?

Authority
Posts: 41
5856     0

Marc,

 

Thank you so much for your response.

I got exactly what I was looking, just little parsing is requierd.

thanks a bunch!

 

-Nidhi

Showing results for 
Search instead for 
Do you mean 

Recommended for You