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 "188.8.131.52". 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 (184.108.40.206) 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.
Hi Community, I was wondering if anyone has faced this issue. The below command option is not working for me: sh ip int br | json OR sh ip int br | json-pretty. Version: IOS XE 16.12.5. Re/Saleh Re/Sal
Hello,I'm trying to setup monitoring of IOS-XE devices using Streaming Telemetry to replace SNMP. I'm able to get some data through my Telegraf-Prometheus-Grafana setup, but it looks like I'm not getting all the entries in the YANG tree. My devices are ru...
Hello Boss, Please kindly see the question below. Question is here, I can get the data with filter1 but I am not able to get anything with filter2.I'd like to know what's the scenario we use ietf-interface and what's the...
I was able to find the Cisco-IOS-XR-ping-act model to automate the Ping actions. But is there anything similar for the XE platforms? I cannot find any. And if none exists, what is a common solution to that - to automate ping action on XE...
Hi there, Is there a way to append custom text to a file in flash using an EEM script? For example, if I had a script that did the following: action 001 cli command "show version" | append flash:output.txtaction 002 cli command "show loggin...