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

API & Integration


How can I search or filter SPM End Hosts connected to a specific switch?

Posts: 2
522     1

I am trying to write a Python script to dump a list from my NetMRI instance, of all the SPM End Hosts associated with a specific switch, along with their VLAN ID. I need to do this for the "End Hosts Present", "New End Hosts", and "End Hosts Not Present" categories.


I am able to login and access the API just fine. I guess I am having trouble understanding how these different "brokers" work together, or at least how to properly search them. I'm using the "InfobloxNetMRI" package from "infoblox_netmri.client", which I installed from the package on my instance's API help docs. The package installed via PIP, or on GitHub, seemed outdated so I went with the version on my NetMRI instance.


Right now, I am able to specify a switch name, and it is able to find the device in the "Device" broker.


devices_broker = client.get_broker('Device')
device = devices_broker.index(

That gives me switch's DeviceID, and most other info.


Then, I tried accesssing the "SpmEndHostsDefaultGrid" broker, but it seems I am unable to search for end hosts by device ID, or other variables. It is only able to spit out a list of hosts. Which, I might be able to work with except the API limits to 10000, and I need to pull much more than that. If I could search/filter with the API call, it would let me pull less data, just the data restricted to one switch I specify. Unfortunately, the find and search functions don't seem to be included in that broker, and if I try to filter just with the index function, it just ignores it.


I'd really like to avoid creating a local object and looping the limits/start/end points and filling it that way. It would eat up a ton of data, and be ridiculously inefficient.


Anyways, so then I tried using the "EndHostMacAddress" broker, like I saw recommended in another thread. This was getting me a bit further. I am able to use the DeviceID of the switch found from the 'Device' broker to use the find function to filter the "InfraDeviceID", which seems to give me the end hosts associated with the correct switch.


end_hosts_broker = client.get_broker('EndHostMacAddress')
    end_hosts = end_hosts_broker.find(


However, this broker has no variables related to the VLAN or VLAN ID. I'm a bit lost at this point. It seems like I amgoing to be forced to pull these huge separate data sets, to filter through offline, just to grab the two categories I need. Also, the EndHostMacAddress broker seems to spit back a ton more entries than I can see in the SPM table in the web interface, which makes me wonder if these are even the right entries so I'd like to keep it just involving the "SPM" hosts.


So am I going about this all wrong? What would be the best way to write a script to specify a switch name, and pull all the "SPM End Hosts" entries associated to that switch, outputting just the end host's MAC address, and VLAN ID? Or at least, which broker(s) should I be utilizing the most, so I can focus on those? Thanks in advance for any help! I've been pulling my hair out for days trying to figure this stuff out haha


Re: How can I search or filter SPM End Hosts connected to a specific switch?

Posts: 2
522     1

Alright, there literally has to be a better way to do this. Someone please put me out of my misery.


Right now, I have to create an empty list, request the max limit of 10000 entries, wait an absurd amount of time for it to fetch, append it to the list, and increment the start value until all the entries have been retrieved.


hosts = []
endpoints = ('spm_end_hosts_default_grids',

for endpoint in endpoints:
    total = client.api_request(endpoint + '/index', {'limit': 1})['total']
    start = 0
    limit = 10000
    while start < total:
        resp = client.api_request(endpoint + '/index', {'limit': 10000, 'start': start})
        total = resp['total']
        start += limit
        hosts += resp[endpoint]

This legit takes like 12 minutes to complete, since it needs to fetch >500000 hosts.


Then I just loop through that fairly quickly, and 'filter' by the switch I want like this


for i in range(len(hosts)):
        sw = hosts[i]['DeviceName']
        if sw in args.device_name:
            mac = hosts[i]['NeighborMAC']
            vlan = hosts[i]['VlanIndex']
            print("{},{},{}".format(sw, mac, vlan))

(args.device_name is a list of names provided when running in command line.)


It seems to be working for the most part... but it literally takes 12+ minutes to do the same thing I can do in ~3 seconds in the web GUI.


I have got to be missing something. Can anyone save me please?


Re: How can I search or filter SPM End Hosts connected to a specific switch?

Posts: 5
522     1

I am having exactly the same problem.

Any way to filter on SPM End Hosts or any other SPM Device Present ?

In the GUI, i can filter relatively quickly. Why not via API ?

Showing results for 
Search instead for 
Do you mean 

Recommended for You