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 "184.108.40.206". 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 (220.127.116.11) 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 am having trouble configuring the command "soft-reconfiguration inbound always"under the vrf neighbor:
router bgp 100address-family ipv4 unicast!address-family vpnv4 unicast!neighbor-group GROUP_A!neighbor-group BGP_NEIGHBOR_GROUP!!vrf ...
I have a Catalyst 4500 L3 Switch running IOS XE version 03.11.02.E. According to Cisco it should support netconf.Configuring netconf-yang by running "netconf-yang" in the terminal in config mode seems to have no effect. The command however, run...
Hello all.I've been using Python for a couple of repetitive tasks but I'm still stuck on how to get into Web GUI only devices for e.g. Cisco SG200 line. I've been looking at using some web scraping utilities in order to do it all in Python but I'm not a f...
I am configuring CAT9K switches for Model-Driven Telemetry and want to use secure gRPC with TLS as the telemetry protocol. Below is the IOS-XE config for my gRPC collector ("ip receiver") which requires a profile name (ie: "security_profile"). H...
I'm trying to get the IP and MAC address of a device that is connected to interface 0/0/7 on my ASR920 with Netconf.I can see both the IP and the MAC address from the CLI, however the tags that are supposed to show these, are not present in the model.&nbs...