NetDevOps & Infrastructure Automation

Enterprise Closed-Loop Network Automation & Compliance Engine

A production-grade, closed-loop network compliance and automated remediation framework. Continuously reconciles multi-vendor network devices against NetBox as Single Source of Truth (SSoT), detects configuration drift, enforces declarative Jinja2 policies with dry-run safety gates, executes automated post-remediation data plane validation, and streams real-time JSON audit events to Splunk HEC.

Status: 12 Protocols Verified Live Python 3.12 NetBox v4.7 SSoT Multi-Transport: Netmiko | NETCONF | RESTCONF 116 Offline Pytest Suite (100% Pass) Splunk HEC Real-Time Telemetry Declarative Jinja2 Remediation Two-Phase Drift Purge
12 Verified Protocols
116 Offline Pytests (100% Pass)
~10.6s Full Pytest Suite Runtime
3 Transports (CLI, NETCONF, RESTCONF)

Architecture & Closed-Loop Reconciliation Lifecycle

A deterministic 7-stage engine lifecycle ensuring physical data plane compliance without operator intervention or human configuration error.

Enterprise Network Automation Architecture Diagram

Figure 1: Full closed-loop automation lifecycle: NetBox SSoT ingestion → multi-transport state collection → compliance diff evaluation → pre-flight dry-run gate → Jinja2 remediation → empirical post-validation → Splunk telemetry dispatch.

The Closed-Loop Automation Cycle

[ NetBox (Source of Truth) ]             [ Live Network Infrastructure ]
  • IPAM / VLANs / Prefixes                • Cisco IOS-XE Switches / Routers
  • Device Interfaces & Custom Fields      • Operational Data (Show Commands)
  • Local Config Contexts                  • Running Configurations
             │                                         │
             ▼ (REST API Ingestion)                    ▼ (Netmiko / NETCONF / RESTCONF)
     [ Desired State ]                         [ Observed State ]
             │                                         │
             └───────────────────┬─────────────────────┘
                                 ▼
                    [ Compliance Diff Engine ]
                      ├── Rule Validation Gates
                      ├── Set & Attribute Diffing
                      └── Drift Identification
                                 │
                ┌────────────────┴────────────────┐
                ▼                                 ▼
        [ State Compliant ]              [ Drift Detected ]
                │                                 │
                │                                 ▼
                │                    [ Pre-Flight DRY_RUN Gate ]
                │                    ├── True: Log preview & skip push
                │                    └── False: Execute Remediation
                │                                 │
                │                                 ▼
                │                    [ Jinja2 Remediation Push ]
                │                    ├── Interface Defaulting / Purge
                │                    └── Netmiko atomic send_config_set
                │                                 │
                │                                 ▼
                │                    [ Closed-Loop Post-Validation ]
                │                    ├── Re-collect operational state
                │                    └── Assert 100% compliance
                │                                 │
                └────────────────┬────────────────┘
                                 ▼
                [ Auditing & Telemetry Dispatcher ]
                  ├── Splunk HEC Streamer (Real-time JSON events)
                  ├── JSON Report (`final_compliance_report.json`)
                  └── Technical Report (`network_compliance_report.txt`)
Core Engineering Principle Technical Implementation Production Operational Value
Declarative SSoT (NetBox) NetBox REST API models IPAM, VLANs, interface modes, should_be_up flags, and Config Contexts Eliminates CLI as configuration origin; establishes unambiguous desired state
Multi-Transport Extraction Netmiko + Genie parsers for CLI; ncclient for NETCONF/YANG; HTTP requests for RESTCONF/YANG Extracts structured Python dictionaries across legacy and modern model-driven devices
Hierarchical AST Parsing CiscoConfParse analyzes parent-child config hierarchies for subcommands omitted by show tables Enables precise edge-guard auditing (STP PortFast, BPDU Guard, Loop Guard)
Two-Phase Active Purge Negation-then-enforcement templates (no snmp-server..., default interface...) Prevents orphaned configurations, stale trunk bindings, and rogue monitoring servers
Safe Change Gates (`DRY_RUN`) Pre-flight dry-run gate renders templates in-memory and outputs planned diffs to JSON for CAB review Zero data-plane modifications during change validation audits
Closed-Loop Post-Validation Re-queries operational data plane post-push, running secondary diffs to assert 100% compliance Catches silent CLI rejections or syntax errors before reporting device state
Observability (Splunk HEC) Direct JSON event streaming over HTTP Event Collector with standardized Cisco Severities (3/4/6) Provides real-time auditability and security compliance visibility in SIEM dashboards

12-Module Master Implementation Matrix

Comprehensive protocol coverage spanning Layer 2 switching, Layer 3 dynamic routing, first-hop redundancy, and infrastructure services with deep-dive walkthroughs.

Switching • Netmiko / Genie

VLAN Compliance Engine

  • Authoritative NetBox IPAM VLAN database synchronization across access and distribution switches
  • Case-insensitive name diffing preventing cosmetic naming discrepancies from masking intent
  • Dynamic broadcast domain provisioning with atomic creation of missing VLAN IDs
  • Verified zero-touch remediation restoring corrupted VLAN databases to 100% compliance
View Case Study & CLI Proof →
Switching • Netmiko / Genie

Access Switchports

  • Untagged VLAN validation ensuring endpoints are bound strictly to designated subnets
  • Strict trunk exclusion: detects and strips accidental trunk encapsulation on access ports
  • Interface defaulting remediation: executes default interface before re-applying access mode
  • Eliminates stale QoS, channel-group, or dot1q encapsulation traps in one atomic operation
View Case Study & CLI Proof →
Switching • Netmiko / Genie

802.1Q Trunk Ports

  • Allowed VLAN whitelist enforcement preventing unauthorized VLAN propagation across trunks
  • Cisco trunk encapsulation trap resolution: enforces switchport trunk encapsulation dot1q
  • Trunk hijack recovery: identifies ports erroneously forced into access mode and restores trunking
  • Closed-loop verification confirming trunk status and allowed lists in live switch forwarding tables
View Case Study & CLI Proof →
Switching • Netmiko / Genie

Interface Baseline & Health

  • NetBox should_be_up custom field reconciliation matching administrative intent
  • Compound L1/L2 health analysis parsing physical link status and line protocol state
  • Unmanaged active port isolation: automatically places rogue active links into disabled quarantine
  • Phantom port detection alerting on hardware interfaces absent from NetBox inventory
View Case Study & CLI Proof →
Switching • Netmiko / CiscoConfParse

Spanning Tree Protocol (STP)

  • Two-tier compliance audit: Global root bridge priorities + granular interface edge guard rails
  • Root priority enforcement via NetBox Config Contexts ensuring deterministic STP root placement
  • Hierarchical AST parsing detecting PortFast, BPDU Guard, and Loop Guard per edge port
  • Remediates disabled BPDU Guard on user access ports to prevent network loop injection
View Case Study & CLI Proof →
Routing • RESTCONF / YANG

Router-on-a-Stick (ROAS)

  • NetBox roas tagged interface filtering modeling inter-VLAN routing subinterfaces
  • Model-driven subinterface extraction using Cisco-IOS-XE-native:interface/GigabitEthernet YANG
  • Validates 802.1Q encapsulation tags, IP host addresses, and CIDR subnet masks
  • Automated RESTCONF PATCH payload generation executing zero-touch subinterface remediation
View Case Study & CLI Proof →
Routing • RESTCONF / YANG

OSPF Dynamic Routing

  • Process ID and Router ID validation via Cisco-IOS-XE-native:router/ospf YANG model
  • Automated subnet-to-wildcard mask calculation generating compliant network advertisement statements
  • Rogue process HTTP DELETE purging unauthorized secondary OSPF processes
  • Area 0 backbone route advertisement reconciliation ensuring deterministic interior routing
View Case Study & CLI Proof →
Routing • NETCONF / YANG

First Hop Redundancy (HSRP)

  • Two-tier audit: rogue standby group identification + granular standby attribute diffing
  • Standby Version 2 standardization across all routed interfaces and VIP instances
  • Priority elevation and preemption enforcement guaranteeing deterministic active router election
  • NETCONF edit-config RPC deployment with YANG-validated XML payloads
View Case Study & CLI Proof →
Routing • NETCONF / YANG

Static Routing Architecture

  • Multi-type route validation: recursive (next-hop IP), directly connected, and fully specified
  • Administrative Distance (metric) diffing ensuring primary vs floating backup route hierarchy
  • Rogue route purging via targeted NETCONF nc:operation="remove" XML directives
  • Reconciles static default routes (0.0.0.0/0) against NetBox WAN gateway intent
View Case Study & CLI Proof →
Routing • NETCONF / YANG

NAT & PAT Architecture

  • Four-pillar compliance audit: PAT overload pools, dynamic NAT ranges, 1:1 static NAT, and inside/outside roles
  • Translates complex Cisco NAT tables into normalized YANG data structures
  • Active deprovisioning and rebuild handling dependent ACLs and IP pool allocations
  • Pre-flight verification asserting inside/outside interface roles before applying translation rules
View Case Study & CLI Proof →
Services • Netmiko / CiscoConfParse

Centralized Syslog Infrastructure

  • Multi-collector validation auditing UDP/TCP collector IP addresses and ports against NetBox
  • Source interface binding enforcing logging source-interface Loopback0
  • High-precision timestamp standardization enforcing service timestamps log datetime msec
  • Two-phase active purge deleting rogue logging hosts before applying authorized collectors
View Case Study & CLI Proof →
Services • Netmiko / CiscoConfParse

SNMP Security & Traps

  • Read-Only (RO) and Read-Write (RW) community string audit and cryptographic ACL restriction
  • Rogue SNMP host purging executing no snmp-server host ... to prevent data exfiltration
  • SNMP trap receiver verification ensuring SIEM alerting for link-down and authentication failures
  • System contact and location metadata synchronization against NetBox site facilities
View Case Study & CLI Proof →

Declarative Jinja2 Remediation Patterns

Remediation configurations are generated through three battle-tested templating patterns designed to eliminate configuration drift without causing network instability.

Pattern 1: Two-Phase Active Purge (Syslog & SNMP)

For services where lingering configurations introduce security and data exfiltration vulnerabilities, templates execute negation-then-enforcement:

{# templates/syslog_netmiko.j2 #}

{# Phase 1: Negate observed drift #}
{% if act_syslog %}
{% if act_syslog.get("hosts") %}
{% for h in act_syslog.get("hosts") %}
no logging host {{ h.get("host") }}
{% endfor %}
{% endif %}
{% endif %}

{# Phase 2: Enforce NetBox baseline #}
{% if syslog_data.get("hosts") %}
{% for h in syslog_data.get("hosts") %}
logging host {{ h.get("host") }} transport {{ h.get("transport") }} port {{ h.get("port") }}
{% endfor %}
{% endif %}

Production Impact: Without the negation phase, an unauthorized host like logging host 8.8.8.8 would silently persist alongside legitimate collectors, exfiltrating network telemetry.

Pattern 2: Atomic Interface Defaulting (Access Switchports)

For switchports that drifted into trunk encapsulation or accumulated conflicting port-security commands, the engine wipes residual interface state in one atomic pass:

{# templates/access_port.j2 #}
{% for a in access_data %}
default interface {{ a.access_interface }}
interface {{ a.access_interface }}
 switchport mode access
 switchport access vlan {{ a.access_vlan }}
{% endfor %}

Production Impact: Applying switchport mode access to an interface with residual trunk encapsulation fails on Cisco IOS-XE. default interface guarantees an idempotent clean slate.

Automated Testing & CI/CD Validation

116 unit tests executed in 100% offline environments using pytest, unittest.mock, and pre-captured Genie/NETCONF fixtures. Every build completes in ~10.6 seconds.

Pytest Unit Test Suite Execution Results

Figure 2: Pytest execution showing 100% test pass rate across data builders, compliance state machines, and multi-transport parametrization.

Protocol Domain Data Builder Tests Compliance State Tests Total Tests Execution Time
VLAN Database 5 8 13 1.56s
Access Switchports 6 7 13 1.32s
802.1Q Trunk Ports 6 7 13 1.40s
Interface Baseline 6 7 13 1.53s
Spanning Tree (STP) 9 14 23 1.99s
Centralized Syslog 6 14 20 1.45s
SNMP Infrastructure 7 14 21 1.40s
Total Test Suite 45 71 116 ~10.65s

Multi-Transport Parametrization (`@pytest.mark.parametrize`)

For protocols supporting both CLI (Netmiko) and API (NETCONF) engines, tests execute against both transport drivers seamlessly:

@pytest.mark.parametrize("transport", ["NETCONF", "NETMIKO"])
def test_compliance_snmp_already_compliant(
    transport, mock_sesh, mock_context, mock_device_result, mock_log
):
    mock_sesh.transport = transport
    transport_patch = patch_transports(transport)

    with patch(transport_patch["build_snmp"]) as mock_build_snmp,          patch(transport_patch["check_snmp"]) as mock_check_snmp:
        mock_build_snmp.return_value = {}
        mock_check_snmp.return_value = (True, [])

        result = compliance_snmp(
            mock_sesh, mock_sesh.device_ip, mock_context, {},
            mock_device_result, mock_log, transport
        )

        mock_log.info.assert_called_once()
        assert result["initial_issues"] == []

Enterprise Observability & Splunk HEC Telemetry

Every compliance evaluation, drift identification, and remediation command streams real-time structured JSON events directly to Splunk HTTP Event Collector (HEC).

Splunk HEC Real-Time Audit Telemetry Events

Figure 3: Real-time Splunk search query showing compliance events, drift warnings (Severity 4), remediation success (Severity 6), and post-validation confirmation.

Cisco Severity Level Compliance State Trigger Standardized Payload Action
Severity 6 (INFO) Baseline compliant, remediation applied, post-validation passed Streamed on successful verification with 0 remaining failures
Severity 4 (WARNING) Configuration drift detected (e.g., wrong VLAN, rogue SNMP community, STP priority mismatch) Identifies exact attribute diffs and triggers the Jinja2 remediation pipeline
Severity 3 (ERROR) Remediation push rejected by CLI/RPC, or post-validation failure detected Alerts on-call engineers via SIEM; generates critical issue ticket metadata

Standardized Audit Event Schema

{
  "asctime": "2026-11-26 03:39:34,637",
  "cisco_appname": "SRC",
  "cisco_msgname": "INFO",
  "cisco_sev": 6,
  "compliant": true,
  "component": "main_process",
  "detail": "SNMP Configuration Already Compliant",
  "dev": "10.10.10.20",
  "device_ip": "10.10.10.20",
  "event_type": "snmp_compliance",
  "failures": [],
  "failures_count": 0,
  "hostname": "mx",
  "level": "INFO",
  "message": "snmp_compliant",
  "protocol": "snmp",
  "seqnum": 59,
  "status": "SUCCESS",
  "transport": "NETMIKO"
}