Infoblox Community
Reply
Highlighted
Accepted Solution

NetMRI WebAPI to find device_id and other fields give device name?

[ Edited ]
Authority
Posts: 28
Registered: ‎05-08-2015
Authority
Posts: 28

Hi Al,

 

I'm trying to find out the device_id of a device (and other fields) given a device name via webAPI.

Though I have a functional script using Perl API.

I'm not sure how do I use val_c_DeviceName and op_DeviceName in the weAPI link together?

 

I tried using below which failed terribly.

http://xvy/api/3/devices/find?op_DeviceName='=',val_c_DeviceName='aaabbbcccc'&select=DeviceID

 

Ironically when I'm running this I'm getting a list of all the availabvle devices discovred by NetMRI.(I'm expecting 1 result not ALL)

http://xyz/api/3/devices/find?val_c_DeviceName='aaaabbbbbcccc'

 

Can someone explain?

 

 

 

 

Re: NetMRI WebAPI to find device_id and other fields give device name?

Adviser
Posts: 300
Registered: ‎10-26-2007
Adviser
Posts: 300
There are four different ways to search any given object in the NetMRI API:

show - requires the ID

index - you can filter on specific, indexed fields with equality. The specific fields are listed in the API docs for the index method for that particular type of object. For example, for Device, the DeviceName is one of those fields, so you can just do: /api/3/devices?DeviceName=my.device.name

search - like index, except you can search on ANY fields with equality. Note though that if you use a field other than the ones listed in ”index”, you will be doing a complete scan of the table, which is not efficient.

find - this is a more complex beast but allows you to do partial matches and other operations than ”equality”.

Your first example of ”find” would work if you used & not , between the first two parameters, and didn’t put any quotes:

http://xvy/api/3/devices/find?op_DeviceName==&val_c_DeviceName=aaabbbcccc&select=DeviceID

John

Re: NetMRI WebAPI to find device_id and other fields give device name?

Authority
Posts: 28
Registered: ‎05-08-2015
Authority
Posts: 28

Thanks John!!!

 

For the detailed and prompt reply!!

 

Still have some question about search and index but 'find' did work for me.

 

thanks again!

 

Nidhi 

Re: NetMRI WebAPI to find device_id and other fields give device name?

Techie
Posts: 6
Registered: ‎10-19-2016
petrusarcov
Techie
Posts: 6

if you use python, i made this function for this kind of need. i let it here, maybe it will help:

#device_name ->>string        
def find_DeviceID(device_name):
    if device_name.lower() in d.lower():
            json_device_name=c.api_request('devices/find', {
            'limit':'5000','select': 'DeviceID,DeviceName,DeviceIPDotted',
            'op_DeviceName':'rlike','val_c_DeviceName':device_name})
            device_json=str(json_device_name)
            DeviceID_right=device_json.split("DeviceID':",1)[1]
            DeviceID_field = DeviceID_right.partition("}")[0]
            DeviceID=re.sub('[^0-9]','', DeviceID_field)
    else:
            print("WARNING: device: "+device_name+" does NOT exist in NETMRI")
            DeviceID="null"
    return DeviceID