Meraki Automation Scripts

repository·master·Indexed 19 days ago

https://github.com/meraki/automation-scripts

A collection of Python 3 automation and migration scripts for the Meraki Dashboard API. Includes the ASA Cryptomap Converter for importing site-to-site VPN tunnels from ASA 9.8(4)20 configurations, mxfirewallcontrol.py for managing MX Layer 3 firewall rulesets via CLI, and nodejs_sdk_builder.py for generating a custom Node.js SDK based on live API data.

Tokens
8.6K
Snippets
28
Records
50
Agent score
65%

What's inside meraki-automation-scripts

  1. Overview of Meraki Dashboard API automation scripts

    master

    This repository contains Python 3 automation and migration scripts for the Meraki Dashboard API. These scripts are designed to help automate common tasks within the Meraki ecosystem.

    Important Considerations:

    • Python Version: These scripts require Python 3. They will not run in Python 2. You can verify your version using python --version (Windows) or python3 --version (Linux/Mac).
    • API Versions: Some older scripts may use the Meraki Dashboard API v0, which is end-of-life and unsupported. If you encounter a v0 script, consider requesting a conversion to v1.
    • API Updates: Meraki APIs are constantly expanding. Always check the Meraki What's New page for the most current information.
  2. Understand the Remote Access Logs Analyzer output format

    master

    The script processes Meraki Secure Connect logs into a table containing the following columns:

    • Timestamp
    • Connect Timestamp
    • Connection Event
    • OS Version
    • AnyConnect Version
    • Internal IP
    • External IP

    Visual Indicators

    To improve readability, the terminal output uses color-coding:

    • Connection Event: connected is displayed in green; disconnected is displayed in red.
    • OS Version: Windows versions are displayed in yellow; all other OS versions are displayed in blue.

    Generated Statistics

    The script automatically calculates statistics for these specific columns:

    • OS Version
    • AnyConnect Version
    • Connection Event
    • Internal IP
  3. How to use wildcard name filters

    master

    When using the name:<name> filter, you can use the asterisk * as a wildcard at the beginning or end of the string to match patterns.

    ExpressionDescription
    name:*securityMatches names ending with security
    name:security*Matches names starting with security
    name:*security*Matches names containing security
    name:adv*,name:*securityMatches elements starting with adv AND ending with security
  4. Format firewall rulesets for input

    master

    Rulesets can be provided as JSON formatted strings or as input files.

    Input Files

    Input files are text files where each line contains exactly one rule in JSON format.

    • Requirement: You must insert a new line character after the last rule definition in the file.
    • Data Types: Most fields are strings (enclosed in double quotes). The syslogEnabled field is a boolean and must be written in lowercase without quotes (e.g., false).
    • Keywords: The keyword any is case-insensitive.

    JSON String Format

    When passing rules via the command line, ensure the entire command is a single line. In Windows environments, double quotes within the JSON string may need to be escaped (e.g., "").

    {"protocol":"any", "srcPort":"Any", "srcCidr":"10.1.1.1", "destPort":"Any", "destCidr":"any", "policy":"deny", "syslogEnabled":false, "comment":"Line 1"}
    {"protocol":"any", "srcPort":"Any", "srcCidr":"10.2.2.2", "destPort":"Any", "destCidr":"any", "policy":"deny", "syslogEnabled":false, "comment":"Line 2"}
  5. Use the Meraki Secure Connect Private Applications Import Script

    master

    This script automates the creation of Meraki Secure Connect private applications by importing data from a CSV file.

    Workflow:

    1. Prepare a CSV file following the required schema.
    2. Run the script using python3 meraki_private_app_import.py.
    3. When prompted, provide your Meraki API key and organization ID.
    4. The script validates the CSV and imports the applications into your Meraki Dashboard. If required fields are missing, the script will abort with an error message.
    python3 meraki_private_app_import.py
  6. Automate customer account and organization creation

    master

    The deploycustomer.py script automates the creation of customer accounts/organizations for service providers.

    Requirements:

    • A source organization used as a "customer template".
    • A network configuration template within that source organization.

    Optional Features:

    • If a Google Maps API key is provided, the script can optionally set street addresses for devices, network administration tags, and network timezones.
  7. Migrate networks and devices between organizations

    master

    The repository provides several scripts for moving assets between Meraki organizations:

    • migrate_networks: Copies networks from one organization to another (refer to script comments for supported features).
    • migrate_devices: Moves devices from one organization to another.
    • movedevices.py: Moves all devices from one organization to another. Note that devices must be part of a network, and the destination organization must already contain the corresponding networks (use copynetworks.py to create them if necessary).
    • copynetworks.py: Copies networks and their base attributes. It does not move devices or individual device configurations. Combined networks are copied as "wireless switch appliance".
  8. Run the RadiusCertSurvey script

    master

    The RadiusCertSurvey script performs a survey of devices within a specific Meraki network to identify those using the radius.meraki.com certificate. It flags devices with out-of-date certificates based on a date provided by the user during execution.

    Mandatory Arguments:

    • -k <API KEY>: Your Meraki Dashboard API Key.
    • -n <networkID>: Your Meraki network ID.

    Optional Arguments:

    • -v: Enables verbose mode for detailed output.
    python RadiusCertSurveyResults.py -k <API_KEY> -n <NETWORK_ID>
  9. Generate reports on per-user group network usage

    master

    The usagestats.py script produces reports on network usage categorized by user groups (identified by subnet, VLAN ID, or VLAN name). It combines the Meraki Dashboard API with a SQLite3 database and sends the results via HTML-formatted emails.

    Reference Files:

    • usagestats_initconfig.txt: Example initial configuration file.
    • usagestats_manual.pdf: User manual.
  10. Run mxfirewallcontrol.py

    master

    The script is executed via the command line. The basic syntax requires an organization name (or /all to process all accessible organizations) using the -o flag.

    Syntax:

    • Windows: python mxfirewallcontrol.py -o <org> [-k <api_key>] [-f <filter>] [-c <command>] [-m <mode>]
    • Linux/Mac: python3 mxfirewallcontrol.py -o <org> [-k <api_key>] [-f <filter>] [-c <command>] [-m <mode>]

    Example: To create a backup for the organization "Meraki Inc" using API key 1234:

    python mxfirewallcontrol.py -k 1234 -o "Meraki Inc" -c create-backup
  11. Install and set up offline_logging.py

    master

    The offline_logging.py script allows you to periodically log Meraki dashboard data into an external MongoDB database. This is useful for meeting data residency requirements, extending storage duration beyond what the Meraki cloud provides, or creating timestamped snapshots of specific data.

    Prerequisites

    • A Meraki organization with API access enabled and a Dashboard API key.
    • Python 3.
    • MongoDB (Community Server edition recommended).
    • A database viewer like MongoDB Compass.

    Installation Steps

    1. Install Python 3: On Windows, ensure you select the "Add to PATH" option.
    2. Install Python dependencies:
      • Windows:
        pip install requests
        pip install pyyaml
        pip install pymongo
      • Linux/Mac:
        pip3 install requests
        pip3 install pyyaml
        pip3 install pymongo
    3. Install MongoDB and MongoDB Compass.
    4. Prepare files: Copy offline_logging.py and config.yaml into a folder on your server.
    # Example installation for Linux/Mac
    pip3 install requests pyyaml pymongo