Cisco Configuration Audit: Python Regex Pattern Examples

Cisco Configuration Audit: Python Regex Pattern Example


Cisco Configuration AuditCisco configurations need an audit every so often. Rather than using a human, you can easily rely on regex patterns and the Python re library to automate it.

Interfaces are the most common Cisco configuration sections to audit. Regex patterns can save you alot of time since there can be hundreds of interfaces on each device. This article will demonstrate two examples where you can identify interfaces that either contain or are missing configuration.

Overview

Sample Cisco IOS Configuration

Contain Example

The below code snippet prints the interfaces that contain the command ending in snooping trust.

Output:

Missing Example

The below code snippet prints the interfaces missing the command ending in snooping trust.

Output:

See also:
Run Python Script from Windows Task Scheduler
Python Jinja2 Template: YAML File Cisco Example
Expect SSH Script for a Cisco Device: Tutorial
Cisco ACI Python Cobra: SDK, API, Examples