Skip to content

tmunzer/mist_library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mist_library

Examples of Python scripts using the Mist APIs These scripts are using the mistapi Python package to simplify the authentication process.

Menu

MIT LICENSE

Copyright (c) 2023 Thomas Munzer

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Description

Usage

These scripts are using the mistapi Python package to manage the authentication process with the Mist Cloud. This package can use API Token authentication or Login/Password:

  • saved in a .mist_env file located in your home folder (see below for the env file description)
  • saved in a file and passed with the -e or --env parameter to the script (see below for the env file description)
  • if no env file is found, the script will ask for the Login/Passws

Environment File

The environment file can be used to store all the information requested by the scripts. It can be used to easily store and used different environments and automate the excecution of the scripts without having to save credential information in the script itself.

Variable Name Type Default Comment
MIST_HOST string None The Mist Cloud to use. It must be the "api" one (e.g. api.mist.com, api.eu.mist.com, ...)
MIST_APITOKEN string None The API Token to use.
MIST_USER string None The login to use if no API Token is provided (apitoken use is prefered)
MIST_PASSWORD string None The password to use if no API Token is provided (apitoken use is prefered)
CONSOLE_LOG_LEVEL int 20 The minimum log level to display on the console, using logging schema (0 = Disabled, 10 = Debug, 20 = Info, 30 = Warning, 40 = Error, 50 = Critical)
LOGGING_LOG_LEVEL int 10 The minimum log level to log on the file, using logging schema (0 = Disabled, 10 = Debug, 20 = Info, 30 = Warning, 40 = Error, 50 = Critical). This is only used when the script calling mistapi is using Python logging package and is configured to log to a file

An example of the environment file content is:

MIST_HOST = api.mist.com
MIST_APITOKEN = xxxxxx

Scripts

The scripts are located in the scripts folder. They can be used as-is, or customized if needed. There is a short desccription at the beginning of each script explaining the purpose of the script, the available options, and how to use it. They are also accepting the -h option which will display the script help.

Clients

Devices

  • Common:
    • rename_devices.py: Python script to rename devices (AP, Switch, Router) from a CSV file. The script will automatically locate the site where the device is assigned, and update its name.
  • APs
  • Switches
    • update_port_config.pyPython script to reconfigure switch interfaces based on a CSV file. The script will create or replace device override at the switch level to reconfigure the interfaces.
    • toggle_poe.py: Python script to enable/disable/toggle PoE for a specified Port Profile in a Switch Template.

Exports

  • export_inventory.py: Python script to export the inventory from an organization. The export will include all the information available from the org inventory, including the claim codes.
  • export_search.py: Python script to export historical data from Mist API and save the result in CSV of JSON format.

NAC

  • import_client_macs.py: Python script import import a list of MAC Address into "Client List" Mist NAC Labels from a CSV File.

Orgs

  • clone_template.py: Python script to clone a specific template from an organization to another (or the same) organization.
  • fix_sites_geocoding.py: Python script check if all the sites have geo information configured (lat/lng, country_code, timezone), and update the site information when missing.
  • import_admins.py: Python script to invite/add adminsitrators from a CSV file.
  • import_floorplans.py: Python script to import multiple Ekahau/iBwave project into Mist Organisation.
  • import_sites.py: Python script automate the sites creation in a Mist Org from a CSV file.
  • inventory_assign.py: Python script to assign devices to sites from a CSV file. The devices MUST already have been claimed on the org.
  • inventory_claim.py: Python script to claim devices to an org from a CSV file.
  • org_clone.py: Python script to clone a whole organization to another one. The destination org can be an existing org, or it can be created during the process.
  • org_migration.py: Python script to migrate a whole organization and the devices to another one. The destination org can be an existing org, or it can be created during the process.
  • org_complete_backup.py: Python script to backup a whole organization configuration and devices.
  • org_complete_backup_encrypted.py: Python script to backup a whole organization configuration and devices in AES encrypted file.
  • org_conf_backup.py: Python script to backup a whole organization.
  • org_conf_backup_encrypted.py: Python script to backup a whole organization in AES encrypted file.
  • org_conf_deploy.py: Python script to deploy organization backup/template file.
  • org_conf_zeroize.py: Python script to zeroise an organization. This scrip will remove all the configuration, all the sites and all the objects from the organization.
  • org_inventory_backup.py: Python script to backup all the devices from an organization. It will backup the devices claim codes (if any), configuration (including position on the maps) and pictures.
  • org_inventory_backup_encrypted.py: Python script to backup all the devices from an organization in AES encrypted file. It will backup the devices claim codes (if any), configuration (including position on the maps) and pictures.
  • org_inventory_deploy.py: Python script to deploy organization inventory backup file. By default, this script can run in "Dry Run" mode to validate the destination org configuration and raise warning if any object from the source org is missing in the destination org.
  • org_inventory_restore_pictures.py: Python script to restore device images from an inventory backup file.
  • validate_site_variables.py: Python script to validate that all the variables used in the templates used by each site are configured at the site level. The result is displayed on the console and saved in a CSV file.

Sites

Reports

  • report_app_usage.py: Python script to generate a report of the application usage on a specific site
  • report_bssids.py: Python script to list all Access Points from orgs/sites and their associated BSSIDs.
  • report_rogues.py: Python script to gerenate a Rogue AP report.
  • report_switch_snapshot.py: Python script to gerenates a list of all the switches for a specified org/site
  • report_wlans.py: Python script to list all WLANs from orgs/sites and their parameters, and save it to a CSV file.

Utils

  • encryption.py: Python script to manage backup encryption. This file can be used to generate RSA Private and Public keys for encryption, to encrypt file (AES encryption, AES key is RSA Protected) or to decrypt encryted files.