Learn How We Can Help You Keep Teleworkers Protected During the COVID-19 Crisis

API & Integration

Reply
Highlighted
Accepted Solution

NetMRI REST API Query

Techie
Posts: 5
9005     0

I'm trying to query our NetMRI device for a list of devices who have a particular VLAN configured. For example, if I take a VLAN name or index I would like to get all devices with that VLAN. I've been using the below query but can't get it to return a specific device; it only will return all devices. I've tried search and show to filter this out, but haven't had any success with either. Any assistance that can be provided would much appreciated. Thanks in advance!

 

http://<netmri>/api/v2.20/device_by_vlanname_or_vlanindex_grids/index?VlanName=<nameofvlan>

Highlighted

Re: NetMRI REST API Query

Adviser
Posts: 353
9006     0
You could try using the "search" instead of "index" (index will only filter on things that are actually indexed in the database, search will filter on everything but that of course can be slower).

That said, I don't think most of the _grids APIs, which are made for the UI grids, are published as external APIs and so they may change at any time. Unless that one appears in the API docs, you can't rely on it not changing from version to version (typically it would just add columns, but you never know).

I would use the VlanMember API for that, though it also will have limited searching. If you use VlanMember, you can use the "include" parameter to avoid multiple queries to fetch the device details.


John
Highlighted

Re: NetMRI REST API Query

Techie
Posts: 5
9006     0

John:

 

Thanks for the quick reply! I tried using search instead of index on that class but wasn't able to get it to return any objects for me.

 

I did find this in the documentation on the appliance, but wasn't aware they weren't typically externally facing APIs. Are they typically just used as an integration point for the Grid?

 

Would the VlanMember API give me the ability to search based on VLAN rather than a device? In my use case I can expect to have a network and a VLAN but no other identifying information on which to base a query, hence the need to search by VLAN.

 

Thanks again for the assistance!

 

Joseph

Highlighted

Re: NetMRI REST API Query

Adviser
Posts: 353
9006     0
Ok, yes, I see that is in the docs, so it should be safe to use. However I also see that it does not allow any filtering other than by DeviceGroupID, from what I can see.

If you first query the VLAN API:

https://netmri/api/3/vlans/search?VlanName=foo

The result will contain VlanID (our internal ID, as opposed to VlanIndex which is the switch VLAN ID). Then:

https://netmri/api/3/vlan_members/search?VlanID=2&include=device,interface

If you are only searching for actual switches participating in the VLAN (as opposed to things attached to access ports that are in the VLAN), then you can use VlanName directly in the VlanMember "search". Note though that that will use whatever VLAN name is configured on that particular switch, whereas the Vlan API will search by the name of the VLAN on the root bridge. VlanMember essentially represents the configuration of a particular VLAN on a particular switch (for BridgeMemberInd = 1).

John
Highlighted

Re: NetMRI REST API Query

Techie
Posts: 5
9006     0

John:

 

That makes sense. I tried to search by VLAN ID after using the VLAN object and searching for the appropriate VLAN. However, when I tried to use the second search (for VLAN members) it failed to return a device object.

 

What was interesting is that the output mirrored the input options listed in the API documentation, but were much more verbose than what the documentation indicated would be an expected output. I'm not sure if you've seen this behavior before or not.

 

Thanks again for the help and let me know if there's anything else I can provide for you regarding this. 

 

- Joseph

Highlighted

Re: NetMRI REST API Query

Techie
Posts: 5
9006     0

John:

 

Nevermind; I figured it out. The device information is after the VLAN information. Clearly yesterday was a Monday Smiley Happy. Sorry about the confusion and thanks for all of the help. I think I'm good now. Very much appreciate the quick assistance with this - will definitely reach out in the future with any questions I have.

Highlighted

Re: NetMRI REST API Query

Adviser
Posts: 353
9006     0
Yes, when you use "include" it gathers all the relevant objects and lists them in their own array, so you still have to do some stitching via the IDs, but it prevents an extra query.
Highlighted

Re: NetMRI REST API Query

Techie
Posts: 5
9006     0

John:

 

Yep I figured that part out but thank you for the confirmation. I think based on what you've provided plus what I ran across in the documentation I should be good to go. Thanks again for all of your help; I'll definitely reach out if I have any questions in the future.

 

Joseph

Showing results for 
Search instead for 
Do you mean 

Recommended for You