This repository is deprecated; please follow the main search page or use the ‘Related code repos’ widget on the right side of the current page.

Network Device Interface Health Check

A Python script to quickly check the interface status and statistics of Cisco IOS and IOS XE network devices using Ansible (watch demo).

Overview

High Level Workflow

Device/Interface Health: To get a high-level and quick overview of whether network devices are up and running, the output of the CLI commands "show ip interface brief" and "show interface {{ interface }} | i errors" can provide some insights.

Ansible: Ansible is an open-source tool enabling infrastructure as code and is used in this script to automate running CLI commands on the network devices.

Python and the ansible_runner module: The script is written in Python and makes use of the ansible_runner module to execute playbooks and to retrieve the output for further processing in Python.

Output: The results of the CLI commands are stored in simple .txt files: Sample Output

Contacts

Solution Components

  • Ansible
  • Python, incl. ansible_runner module

Prerequisites

  • Ansible control node requirements: The script must be run from a machine that fulfils the Ansible control node requirements.
  • Ansible Variables and Hosts: The ansible_runner module makes use of a specific directory hierarchy to be able to retrieve the correct variables, host files, and playbooks. The structure of the directory is already integrated in this repository (see the env, inventory, and project folders) and it only requires adding some variables and the target host devices.
    • In the env folder, update the extravars file. The values you need to fill in are:
      • ansible_user, which is the username to log into the target host devices
      • ansible_password, which is the password linked to the username and that is required to log into the target devices
      • ansible_become_pass, which is the password to access enable mode on the target devices
      • interfaces remains empty
    • In the inventory folder, update the hosts file by adding the IP addresses of the target devices. For each target device IP, use a new line.
    • Note that the playbooks are stored in the project folder. No customization is required here.

Installation

  1. Clone this repository with git clone <this repo> and navigate to the directory with cd path/to/repo.

  2. (Optional) Create a Python virtual environment for the project and activate it (find instructions here).

  3. In the terminal, navigate to the root directory of the repository, and install the requirements with pip install -r requirements.txt.

  4. From the root directory, run the Python script with python main.py

License

Provided under Cisco Sample Code License, for details see LICENSE.

Code of Conduct

Our code of conduct is available here.

Contributing

See our contributing guidelines here.

View code on GitHub
  • Owner

  • Contributors

    +2Github contributors
  • Categories

  • Products

    IOS XE
  • Programming Languages

    Python
  • License

    Other

Code Exchange Community

Get help, share code, and collaborate with other developers in the Code Exchange community.View Community
Disclaimer:
Cisco provides Code Exchange for convenience and informational purposes only, with no support of any kind. This page contains information and links from third-party websites that are governed by their own separate terms. Reference to a project or contributor on this page does not imply any affiliation with or endorsement by Cisco.