[Day #80 Pyats Series] Cloud-managed network checks (Meraki Dashboard API) using pyATS for Cisco [Python for Network Engineer]

[Day #80 Pyats Series] Cloud-managed network checks (Meraki Dashboard API) using pyATS for Cisco [Python for Network Engineer]

Introduction on the Key Points

In the era of cloud-managed networks, Cisco Meraki has changed the way we deploy, monitor, and troubleshoot enterprise infrastructure. Gone are the days of telnetting or SSH-ing into each device individually — with the Meraki Dashboard API, you can programmatically retrieve performance metrics, device statuses, and configuration details from the cloud in seconds.

But here’s the real question — how do we integrate Meraki API with our existing network testing framework like pyATS?

This article will walk you through automating Meraki cloud-managed network health checks using pyATS and the Meraki Dashboard API. You’ll see how to:

  • Connect to Meraki cloud via API keys securely.
  • Pull device and network health status from the dashboard.
  • Integrate cloud-based checks with pyATS jobs.
  • Produce actionable pass/fail results for monitoring dashboards.

If you are a Python for Network Engineer learner, this use case is golden — because cloud-managed APIs are becoming a standard in modern IT automation, and the demand for engineers who can work across on-prem + cloud networking is skyrocketing.


Topology Overview

While this is a cloud-based lab, here’s the conceptual topology:


Topology & Communications

  • pyATS Host → Runs Python scripts using meraki Python library.
  • Meraki Dashboard API → HTTPS endpoint for retrieving device and network data.
  • Authentication → API key (stored securely in environment variables).
  • Data Flow:
    1. pyATS script authenticates to Meraki Dashboard via API key.
    2. Pulls organization and network IDs.
    3. Retrieves device health status (online/offline).
    4. Generates compliance or health reports.

Workflow Script

Here’s the pyATS + Meraki API integration script:

import os
from genie.testbed import load
import meraki

# Load testbed (if needed for hybrid environments)
testbed = load('testbed.yml')

# Load API key from environment variable
MERAKI_API_KEY = os.getenv("MERAKI_API_KEY")
if not MERAKI_API_KEY:
    raise ValueError("Meraki API Key not found in environment variables.")

# Create dashboard API session
dashboard = meraki.DashboardAPI(api_key=MERAKI_API_KEY, suppress_logging=True)

# Step 1: Get organizations
orgs = dashboard.organizations.getOrganizations()
org_id = orgs[0]['id']
print(f"Using Organization ID: {org_id}")

# Step 2: Get networks in organization
networks = dashboard.organizations.getOrganizationNetworks(org_id)
print(f"Found {len(networks)} networks.")

# Step 3: For each network, get devices and status
for net in networks:
    net_id = net['id']
    net_name = net['name']
    print(f"\nChecking devices in network: {net_name}")

    devices = dashboard.networks.getNetworkDevices(net_id)
    statuses = dashboard.networks.getNetworkDevicesStatuses(net_id)

    for device in statuses:
        name = device.get('name', device.get('serial'))
        status = device['status']
        if status.lower() != 'online':
            print(f"ALERT: {name} is {status}")
        else:
            print(f"OK: {name} is {status}")

Explanation by Line

  1. import meraki → Uses Meraki’s official Python SDK for API calls.
  2. os.getenv("MERAKI_API_KEY") → API key stored securely, never hardcoded.
  3. dashboard.organizations.getOrganizations() → Lists all Meraki organizations your account can access.
  4. dashboard.organizations.getOrganizationNetworks(org_id) → Fetches all networks under the chosen organization.
  5. dashboard.networks.getNetworkDevicesStatuses(net_id) → Retrieves real-time device statuses (online/offline/dormant).
  6. Conditional check → Marks offline devices as ALERT.
  7. Looping over networks → Ensures every network in your organization gets checked automatically.

testbed.yml Example

Even though Meraki API is cloud-based, we include testbed.yml to keep our scripts compatible with hybrid cloud + on-prem checks.

testbed:
  name: MerakiCloudChecks
  credentials:
    default:
      username: admin
      password: cisco123

devices:
  pyATS_Host:
    os: linux
    type: host
    connections:
      cli:
        protocol: ssh
        ip: 192.168.1.100

Post-validation CLI (Real expected output)

Sample Output — All Devices Online:

Using Organization ID: 123456
Found 2 networks.

Checking devices in network: HQ-Network
OK: MX84-Security is online
OK: MS225-Switch is online
OK: MR33-AP is online

Sample Output — Some Devices Offline:

Using Organization ID: 123456
Found 2 networks.

Checking devices in network: Branch-1
OK: MX64 is online
ALERT: MR20-AP is offline

FAQs

1. What is the Meraki Dashboard API and why is it useful for network checks?
The Meraki Dashboard API is a RESTful API that allows programmatic access to your Meraki cloud-managed network data. Instead of manually logging into the dashboard, you can automate tasks like device health checks, client tracking, configuration audits, and security policy validations.


2. What types of network checks can I perform with the Meraki API?
You can automate:

  • Device status & connectivity (online/offline alerts)
  • WAN/LAN health (latency, packet loss, throughput)
  • Client activity reports (bandwidth, application usage)
  • Configuration compliance (SSID settings, VLANs, firewall rules)
  • Firmware compliance (upgrades pending or outdated firmware)

3. How do I authenticate and access the API?
Meraki APIs require an API key, which is generated from your dashboard account under Organization → Settings → API Key. You must include it in every request as an HTTP header:

X-Cisco-Meraki-API-Key: <your_api_key>

Always store API keys securely (environment variables or secrets managers).


4. Can I use the Meraki API for multi-organization monitoring?
Yes. If your account has access to multiple organizations, the API can query each one in sequence. You can loop through GET /organizations and perform checks across all networks under each organization.


5. How often should I run automated checks?
It depends on the criticality of your environment:

  • Device uptime checks: every 1–5 minutes
  • Configuration compliance: daily or after change windows
  • Firmware checks: weekly
    Meraki enforces rate limits (5 requests/sec per organization), so schedule checks accordingly.

6. Can I get alerts automatically without polling the API?
Yes. Meraki supports webhooks that push real-time alerts (e.g., device offline, rogue AP detected) to your automation platform, eliminating the need for frequent polling.


7. Is it possible to integrate Meraki API checks into pyATS or other automation tools?
Absolutely. The Meraki API returns JSON, which can be easily consumed in pyATS scripts or integrated into CI/CD tools like Jenkins or GitLab CI for continuous network health validation.


8. What’s a common automation workflow for Meraki health checks?
A typical workflow:

  1. Authenticate with API key
  2. Pull organization & network IDs
  3. Retrieve device list & statuses
  4. Compare settings with golden config (stored in JSON/YAML)
  5. Generate compliance/health report
  6. Send results via email, Slack, or ticketing system

YouTube Link

Watch the Complete Python for Network Engineer: Cloud-managed network checks (Meraki Dashboard API) using pyATS for Cisco [Python for Network Engineer] Lab Demo & Explanation on our channel:

Master Python Network Automation, Ansible, REST API & Cisco DevNet
Master Python Network Automation, Ansible, REST API & Cisco DevNet
Master Python Network Automation, Ansible, REST API & Cisco DevNet
Why Robot Framework for Network Automation?

Join Our Training

If you want to master Python for Network Engineer use cases — from Cisco CLI automation to cloud-managed APIs like Meraki — join Trainer Sagar Dhawan’s 3-Month Instructor-Led Training.

You’ll learn:

  • Python automation for on-prem + cloud networking.
  • pyATS for network validation and compliance.
  • API integration with Cisco, Meraki, Arista, Palo Alto, and more.
  • Real-world automation project workflows.

Course Outline: Click Here

Take the next step in your career — learn Python for Network Engineer automation that works both in the data center and in the cloud.


Enroll Now & Future‑Proof Your Career
Emailinfo@networkjourney.com
WhatsApp / Call: +91 97395 21088