1. The Workflow
  2. The Implementation

Meraki dashboards are convenient, but if an admin accidentally modifies a critical firewall rule, rolling back is a nightmare. This Python script uses the Meraki Dashboard API to serialize your network configurations into a secure JSON format.

1. The Workflow

The script performs the following steps:

  • Authentication: Initializes the Meraki SDK using a read-only API key.
  • Iteration: Loops through the Organization to find all active Networks.
  • Extraction: Pulls VLAN subnets, SSID configurations, and MX L3 Firewall rules.
  • Serialization: Dumps the state into a structured JSON file.

2. The Implementation

import meraki
import json
from datetime import datetime

API_KEY = 'YOUR_MERAKI_API_KEY'
ORG_ID = 'YOUR_ORG_ID'
dashboard = meraki.DashboardAPI(API_KEY, suppress_logging=True)

def backup_network_config():
    networks = dashboard.organizations.getOrganizationNetworks(ORG_ID)
    backup_data = {}
    for net in networks:
        net_id = net['id']
        net_name = net['name']
        backup_data[net_name] = {'vlans': dashboard.appliance.getNetworkApplianceVlans(net_id)}
    
    filename = f"meraki_backup_{datetime.now().strftime('%Y%m%d')}.json"
    with open(filename, 'w') as f:
        json.dump(backup_data, f, indent=4)