REQUEST A demo
REQUEST A DEMO

API integration with Ansible and Zabbix

By
Milan Zapletal
March 20, 2020
Est. Reading: 3 minutes

The IP Fabric platform provides a standard Application Programming Interface (API), and this interface allows to integrate IP Fabric platform with any 3rd party software or build any custom scripts. See the official documentation for details on how to use our API.

Thanks to a unique discovery algorithm, IP Fabric is capable of collecting data about all active network devices automatically. It collects more than 1000 parameters from each individual device and provides the data in a standardized form. Those data can be viewed in GUI or accessed via API. Hence all available data serves as a perfect baseline for any automation or API integration efforts.

The goal of this article

This article demonstrates how to add devices to Zabbix monitoring software. Zabbix uses the SNMP protocol for monitoring; therefore, we have to check if a device has SNMP configured and if no, then we will configure it automatically using the Ansible tool.

Where to get API information in IP Fabric

The IP Fabric is a very flexible tool when it comes to getting information. The same applies to well-documented API fetch points. In every technology table, including the main device inventory, there's table description, that appears on request.

API Integration: URL for device inventory

The full device inventory can be accessed with a POST request to https://ipfabric.domain.com/api/v1/tables/inventory/devices. The response can be filtered by any column.

So let's say that we want to get all Cisco IOS, IOS-XE devices, the following code snippet will accomplish just that:

curl -k -s https://ipfabric.domain.com/api/v1/tables/inventory/devices \
   -u 'username:password' \
   -H 'Content-Type: application/json' \
   --data-binary '{"columns":["sn","hostname","loginIp","loginType"],"filters":{"or":[{"family":["eq", "ios"]},{"vendor":["eq","ios-xe"]}]},"snapshot":"$last"}'

Access the SNMP data from the IP Fabric

All data related to SNMP configuration for all discovered devices is presented in a different technology table related to SNMP. If in doubt, there's always the search box that will help with finding a specific target. Let's say we are looking for SNMP information, let's just type 'SNMP' and see results. The platform will provide us with information about tables, including SNMP information. We will navigate to SNMP Summary, where we again collect API link.

In the same way, we collected full device inventory, filtering IOS and IOS-XE, we can collect all devices with that has no SNMP community configured.

curl -k -s  https://ipfabric.domain.com/api/v1/tables/management/snmp/summary \
     -u 'username:password' \
     -H 'Content-Type: application/json' \
     --data-binary '{"columns":["id"],"filters":{"communitiesCount":["eq",0],"sn":["eq","'"$sn"'"]},"snapshot":"$last"}'

By comparing Inventory with IOS or IOS-XE devices and SNMP summary table information, where we can find devices with no configured SNMP community, we will get the full list of devices that need to be added to Zabbix and configured with Ansible.

The entire bash script can be seen in our public repository.

Ansible automation

Ansible is an open-source configuration management and application-deployment tool. It helps to automate configuration updates with templates called the 'playbooks' with various network vendors, including servers.

We used the Ansible version 2.5.1. Our simple Ansible playbook will add a new SNMP community and trap the host server as well.

Please note, that you may want to modify the YAML file to fit your environment, we only used 'dummy' SNMP server IP, which may be the Zabbix IP address and SNMP community as an example. The following snippet may need an update per case.

     - name: Add SNMP config
      ios_config:
        lines:
        - snmp-server community newCommunity ro
        - snmp-server host 10.10.10.10 version 2c snmpCommunity
      notify:
      - Save Configuration 

The entire Yaml file can be seen in our public repository.

Zabbix automation

The Zabbix configuration is updated with the help of powerful Zabbix-CLI, which was originally developed by members of the Department for IT Infrastructure at the Center for Information Technology at the University of Oslo, Norway. It's a very user-friendly and powerful solution for connecting to Zabbix's API.

The connector needs to be preinstalled and configured accordingly. For the full installation process, please, follow the documentation.

Thank you for reading!

If you have found this article helpful, please follow our company’s LinkedIn or Blog, where there will be more content emerging. Furthermore, if you would like to test our platform to evaluate how it can assist you in managing your network more effectively, please let us know through www.ipfabric.io.

Request a Demo
Request a demo with our professional to evaluate usability of the product in your network

Where you can find us

Prague
IP Fabric s.r.o.
Kateřinská 466/40
Praha 2 - Nové Město, 120 00
Czech Republic

Phone :
+420 720 022 997

Email : sales@ipfabric.io
New York
IP Fabric, Inc.
200 Business Park Drive
Armonk, NY 10504
United States

Phone : +1 (914) 752-2991
Email : info@ipfabric.io
IP Fabric, Inc. © 2021 All Rights Reserved