Welcome to part 4 of the "APIC-EM API productivity series" for network engineers getting started in API and scripting.
Earlier blogs on APIC-EM covered
/network-device – all attributes of network-devices (blog1)
/interface/network-device – all interfaces (and hosts) on a network-device e.g. a switch (blog2)
/license-info - all licencing information for a network-device (blog3)
By this stage of the blog series, I am going to assume you are familiar with swagger (API documentation tool) and the location of the github repository where I have shared the code samples.
#4 find my host
As mentioned earlier, the controller has a table of all hosts that are connected to network-devices. This information is kept updated when link up/down traps are enabled on switches and wireless Lan controllers (WLC). See the configuration guide for the commands to enable this on the network-devices.
This means that I can use the controller as an accurate source of information about hosts connected to the network and locate them. This example allows a search by host mac address or ip address.
Navigate to the "/host" URL as in blog#2. In this case you are going to use the "hostIp" parameter. From blog #2, you know there is a host with IP address of "126.96.36.199". Enter this in, along with scope.
You will get the following output, showing the network-device and the interface this host is connected to.
You can also do a lookup by MAC address. Use the "hostMac" parameter and set it to "e8:9a:8f:7a:22:99". You will get the same output as before.
The script "04_find_host.py" allows a search for a host via either MAC address or IP address. The three examples below illustrate the ways this can be done:
1) This example shows a lookup by MAC address. You can see the host IP|MAC as well as the ip address of the network-device (188.8.131.52) and the interface (GigabitEthernet1/0/47) and the vlan (200)
2) The second example is the same as the first, just a lookup by hostip. As expected it shows the same information as the previous call.
3) This example is for a wireless client. It shows the Controller the host is connected to as well (along with model and software version) as well as the AP the host is connected to.
The other concept this code shows is the use of argument parsing to allow the "—mac" and "—ip" options to be used. Argparse is a python package for argument parsing (https://pypi.python.org/pypi/argparse ).
This is a very simple tool you can use for troubleshooting. Some improvements could include:
Change the script so that it takes a single argument that is either a MAC or IP address and intelligently (based on syntax of the argument) determine if a MAC search or IP search is required.
Embed this into a python web framework like Flask to turn this into a web page. Happy to provide an example of this, if people are interested.
Provide a "refresh" option where the script will refresh the location every 5mins to track a host connectivity status.
This blog covered the forth of the useful API /host . The final blog in the series will look /flow-analysis, an API to do a path trace between hosts on the network. It also provides stats on interfaces, QoS, Perfmon and ACL trace.
In the meantime, if you would like to learn more about APIC-EM, you could visit Cisco Devnet. All of the code samples can be found in this Github repository.
I'm able to pull the topology using the API GEThttps://n.n.n.n/api/node/mo/topology/pod-1.json?query-target=children&target-subtree-class=fabricNode(after authenticating and getting a cookie, of course) But the version field is empty. I don't see...
Hello All 1. What is the best way to pull # of connections per last 24 hours?It took 3-4 hours to get everything out of "/v3/data/HistoricalClientCounts.json?.full=true&id=gt(target)&.maxResults=1000" using paged request. I can alter th...
I am trying to create and run the openconfig script which is shown as a sample in DevNet tutorial NETCONF/YANG on Nexus Part 3: Using OpenConfig YANG Models on Nexus Switches. The file as an example is add_oc_loopback.py. The file contents are :...
Hi, Any idea how to achieve the following:1. WAN QoS change2. WAN link relocation3. WAN link bandwidth upgrade or downgrade4. WAN routes advertisement or de-advertisement Using Viptela APIs:https://sdwan-docs.cisco.com/Product_Documentatio...
Ok, so Im just trying to get APIC-EM running and I keep running into this issue no matter what i do.I've attached a net diagram to clarify...Currently running APIC-EM Version 184.108.40.206024. The issue I have is that I can find one device and it won...