Code Monkey home page Code Monkey logo

nautobot-plugin-chatops-meraki's Introduction

The code in this repository has been migrated to the Nautobot ChatOps Repository as an integration - read more about it in the ChatOps Docs! As of July 2023 this repository has been FROZEN - all development / issues / discussions for this integration are in the Nautobot ChatOps Repository going forward.

Cisco Meraki ChatOps

Using the Nautobot ChatOps base framework, this Nautobot app (plugin) adds the ability to gather data as well as make basic changes communicating directly with the Meraki portal using Slack, Webex Teams, MS Teams, and Mattermost changing the way IT organizations support their Meraki infrastructure.

Usage

Command Setup

Add a slash command to Slack called /meraki. See the nautobot-chatops installation guide for instructions on adding a slash command to your Slack channel.

You may need to adjust your Access Grants in Nautobot depending on your security requirements.

The following commands are available:

  • /meraki get-organizations: Gather all the Meraki Organizations.
  • /meraki get-admins [org-name]: Based on an Organization Name Return the Admins.
  • /meraki get-devices [org-name] [device-type]: Gathers devices from Meraki.
  • /meraki get-networks [org-name]: Gathers networks from Meraki.
  • /meraki get-switchports [org-name] [device-name]: Gathers switch ports from a MS switch device.
  • /meraki get-switchports-status [org-name] [device-name]: Gathers switch ports status from a MS switch device.
  • /meraki get-firewall-performance [org-name] [device-name]: Query Meraki with a firewall to device performance.
  • /meraki get-network-ssids [org-name] [net-name]: Query Meraki for all SSIDs for a given Network.
  • /meraki get-camera-recent [org-name] [device-name]: Query Meraki Recent Camera Analytics.
  • /meraki get-clients [org-name] [device-name]: Query Meraki for List of Clients.
  • /meraki get-lldp-cdp [org-name] [device-name]: Query Meraki for List of LLDP or CDP Neighbors.
  • /meraki configure-basic-access-port [org-name] [device-name] [port-number] [enabled] [vlan] [port-desc]: Configure an access port with description, VLAN and state.
  • /meraki cycle-port [org-name] [device-name] [port-number]: Cycles a port on a given switch.

Screenshots

Running /meraki get-organizations. Example output for get-organizations

Running /meraki get-networks. Example output for get-networks

Running /meraki get-switchports-status. Example output for get-networks

Since the output was cut off the output example is below:

Port   Enabled      Status         Errors       Warnings   Speed    Duplex    Usage (Kb)    Client Count    Traffic In
                                                                                                              (Kbps)
========================================================================================================================
1      True      Connected                                 1 Gbps   full     total: 46687   1              total: 4.3
                                                                             sent: 27405                   sent: 2.5
                                                                             recv: 19282                   recv: 1.8
2      True      Connected                                 1 Gbps   full     total: 10086   1              total: 1.0
                                                                             sent: 9481                    sent: 0.9
                                                                             recv: 605                     recv: 0.1
3      True      Disconnected   Port                                         total: 0       0              total: 0
                                disconnected                                 sent: 0                       sent: 0
                                                                             recv: 0                       recv: 0
4      True      Disconnected   Port                                         total: 0       0              total: 0
                                disconnected                                 sent: 0                       sent: 0
                                                                             recv: 0                       recv: 0

To demonstrate a example of configuration updates. There is a simple configuration ability for access ports. /meraki configure-basic-access-port

Specify Org, Switch, and Port ID. Example output for config-port0

Fill out the Port Specific Configuration. Example output for config-port1

Result of the configuration. Example output for config-port2

Installation

This plugin requires installation of the Nautobot ChatOps plugin. Follow this link to the installation instructions for that plugin.

The plugin is available as a Python package in PYPI and can be installed with pip

pip install git+https://github.com/networktocode-llc/nautobot-plugin-chatops-meraki.git

The plugin is compatible with Nautobot 1.0.1 and higher

To ensure Nautobot Plugin Chatops Meraki is automatically re-installed during future upgrades, create a file named local_requirements.txt (if not already existing) in the Nautobot root directory (alongside requirements.txt) and list the nautobot-plugin-chatops-meraki package:

# echo nautobot-plugin-chatops-meraki >> local_requirements.txt

Once installed, the plugin needs to be enabled in your nautobot_config.py

# In your configuration.py
PLUGINS = ["nautobot_chatops", "nautobot_plugin_chatops_meraki"]

PLUGINS_CONFIG = {
  "nautobot_chatops": {
    # ADD SLACK/MS-TEAMS/WEBEX-TEAMS/MATTERMOST SETTINGS HERE
  }
}

To connect to the Meraki Dashboard API, you need to define Meraki Dashboard API key. See Meraki Dashboard API Documentation.

There are two options to define the API key.

The first option is to define the API key in the nautobot_config.py:

PLUGINS_CONFIG = {
    "nautobot_plugin_chatops_meraki": {
        "meraki_dashboard_api_key": <API KEY>
    },

Note: You would probably want to read the API key from the env variable like this: os.environ.get("MERAKI_API_KEY")

The alternative option is to set the environmental variable:

  • MERAKI_DASHBOARD_API_KEY: Is set to the dashboard API key.

For the local development and testing add this variable and its value in the creds.env file. If both options are used, the plugin will read the key from the settings.

Contributing

Pull requests are welcomed and automatically built and tested against multiple version of Python and multiple version of Nautobot through TravisCI.

The project is packaged with a light development environment based on docker-compose to help with the local development of the project and to run the tests within TravisCI.

The project is following Network to Code software development guideline and is leveraging:

  • Black, Pylint, Bandit and pydocstyle for Python linting and formatting.
  • Django unit test to ensure the plugin is working properly.

Development Environment

The development environment can be used in 2 ways. First, with a local poetry environment if you wish to develop outside of Docker. Second, inside of a docker container.

Invoke tasks

The PyInvoke library is used to provide some helper commands based on the environment. There are a few configuration parameters which can be passed to PyInvoke to override the default configuration:

  • nautobot_ver: the version of Nautobot to use as a base for any built docker containers (default: latest)
  • project_name: the default docker compose project name (default: nautobot-plugin-chatops-meraki)
  • python_ver: the version of Python to use as a base for any built docker containers (default: 3.6)
  • local: a boolean flag indicating if invoke tasks should be run on the host or inside the docker containers (default: False, commands will be run in docker containers)
  • compose_dir: the full path to a directory containing the project compose files
  • compose_files: a list of compose files applied in order (see Multiple Compose files for more information)

Using PyInvoke these configuration options can be overridden using several methods. Perhaps the simplest is simply setting an environment variable INVOKE_NAUTOBOT-PLUGIN-CHATOPS-MERAKI_VARIABLE_NAME where VARIABLE_NAME is the variable you are trying to override. The only exception is compose_files, because it is a list it must be overridden in a yaml file. There is an example invoke.yml in this directory which can be used as a starting point.

Local Poetry Development Environment

  1. Copy development/creds.env.example to development/creds.env (This file will be ignored by git and docker)
  2. Uncomment the POSTGRES_HOST, REDIS_HOST, and NAUTOBOT_ROOT variables in development/creds.env
  3. Create an invoke.yml with the following contents at the root of the repo:
---
nautobot_plugin_chatops_meraki:
  local: true
  compose_files:
    - "docker-compose.requirements.yml"
  1. Run the following commands:
poetry shell
poetry install
export $(cat development/dev.env | xargs)
export $(cat development/creds.env | xargs)
  1. You can now run nautobot-server commands as you would from the Nautobot documentation for example to start the development server:
nautobot-server runserver 0.0.0.0:8080 --insecure

Nautobot server can now be accessed at http://localhost:8080.

Docker Development Environment

This project is managed by Python Poetry and has a few requirements to setup your development environment:

  1. Install Poetry, see the Poetry Documentation for your operating system.
  2. Install Docker, see the Docker documentation for your operating system.

Once you have Poetry and Docker installed you can run the following commands to install all other development dependencies in an isolated python virtual environment:

poetry shell
poetry install
invoke start

Nautobot server can now be accessed at http://localhost:8080.

CLI Helper Commands

The project is coming with a CLI helper based on invoke to help setup the development environment. The commands are listed below in 3 categories dev environment, utility and testing.

Each command can be executed with invoke <command>. Environment variables INVOKE_NAUTOBOT-PLUGIN-CHATOPS-MERAKI_PYTHON_VER and INVOKE_NAUTOBOT-PLUGIN-CHATOPS-MERAKI_NAUTOBOT_VER may be specified to override the default versions. Each command also has its own help invoke <command> --help

Docker dev environment

  build            Build all docker images.
  debug            Start Nautobot and its dependencies in debug mode.
  destroy          Destroy all containers and volumes.
  restart          Restart Nautobot and its dependencies.
  start            Start Nautobot and its dependencies in detached mode.
  stop             Stop Nautobot and its dependencies.

Utility

  cli              Launch a bash shell inside the running Nautobot container.
  create-user      Create a new user in django (default: admin), will prompt for password.
  makemigrations   Run Make Migration in Django.
  nbshell          Launch a nbshell session.

Testing

  bandit           Run bandit to validate basic static code security analysis.
  black            Run black to check that Python files adhere to its style standards.
  flake8           This will run flake8 for the specified name and Python version.
  pydocstyle       Run pydocstyle to validate docstring formatting adheres to NTC defined standards.
  pylint           Run pylint code analysis.
  tests            Run all tests for this plugin.
  unittest         Run Django unit tests for the plugin.

Questions

For any questions or comments, please check the FAQ first and feel free to swing by the Network to Code slack channel (channel #networktocode). Sign up here

nautobot-plugin-chatops-meraki's People

Contributors

jedelman8 avatar jeffkala avatar qduk avatar tim-fiola avatar ubajze avatar whitej6 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

whitej6

nautobot-plugin-chatops-meraki's Issues

The traceback is returned if the API key is not defined in Nautobot settings

Environment

  • Python version: any
  • Nautobot version: any
  • Nautobot Chatops Plugin version: any
  • nautobot-plugin-chatops-meraki version: 1.2.0

Expected Behavior

The plugin should read the key either from settings or from an environmental variable as per documentation.

Observed Behavior

If the key is not defined in the settings you get the following traceback:

nautobot_1  | Internal Server Error: /api/plugins/chatops/slack/slash_command/
nautobot_1  | Traceback (most recent call last):
nautobot_1  |   File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
nautobot_1  |     response = get_response(request)
nautobot_1  |   File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
nautobot_1  |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
nautobot_1  |   File "/usr/local/lib/python3.9/site-packages/django/views/generic/base.py", line 70, in view
nautobot_1  |     return self.dispatch(request, *args, **kwargs)
nautobot_1  |   File "/usr/local/lib/python3.9/site-packages/django/utils/decorators.py", line 43, in _wrapper
nautobot_1  |     return bound_method(*args, **kwargs)
nautobot_1  |   File "/usr/local/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
nautobot_1  |     return view_func(*args, **kwargs)
nautobot_1  |   File "/usr/local/lib/python3.9/site-packages/django/views/generic/base.py", line 98, in dispatch
nautobot_1  |     return handler(request, *args, **kwargs)
nautobot_1  |   File "/usr/local/lib/python3.9/site-packages/nautobot_chatops/api/views/slack.py", line 104, in post
nautobot_1  |     registry = get_commands_registry()
nautobot_1  |   File "/usr/local/lib/python3.9/site-packages/nautobot_chatops/workers/__init__.py", line 70, in get_commands_registry
nautobot_1  |     command_func = worker.load()
nautobot_1  |   File "/usr/local/lib/python3.9/site-packages/pkg_resources/__init__.py", line 2450, in load
nautobot_1  |     return self.resolve()
nautobot_1  |   File "/usr/local/lib/python3.9/site-packages/pkg_resources/__init__.py", line 2456, in resolve
nautobot_1  |     module = __import__(self.module_name, fromlist=['__name__'], level=0)
nautobot_1  |   File "/usr/local/lib/python3.9/site-packages/nautobot_plugin_chatops_meraki/worker.py", line 26, in <module>
nautobot_1  |     MERAKI_DASHBOARD_API_KEY = settings.PLUGINS_CONFIG["nautobot_plugin_chatops_meraki"]["meraki_dashboard_api_key"]
nautobot_1  | KeyError: 'meraki_dashboard_api_key'

Steps to Reproduce

  1. Install the plugin version 1.2.0
  2. Start Nautobot without the nautobot-plugin-chatops-meraki plugin settings in the configuration file.
  3. Execute the /meraki command.

Docs review

A couple of links to the ChatOps plugin are not working in the README.md file in the section In https://github.com/networktocode-llc/nautobot-plugin-chatops-meraki/blob/develop/README.md#command-setup

  1. The hyperlink in Add a slash command to Slack called /meraki. See the nautobot-chatops installation guide for instructions on adding a slash command to your Slack channel. for the nautobot-chatops installation guide is https://github.com/nautobot/nautobot-plugin-chatops/blob/develop/docs/chat_setup.md. This URL is not found. I think the file name changed.

  2. Same thing as above with linked URL in same section in the sentence You may need to adjust your Access Grants in Nautobot depending on your security requirements.. The hyperlink for Access Grants in Nautobot is https://github.com/nautobot/nautobot-plugin-chatops/blob/develop/docs/chat_setup.md#grant-access-to-the-chatbot, which leads nowhere.

  3. In the README.md file, I recommend describing how to add that environment variable.

The plugin requires the use of a environment variable. See below.

MERAKI_DASHBOARD_API_KEY: Is set to the dashboard API key

Allow API Key to be specified in config or read from file

When deploying this plugin in our environment I store the API key in hashicorp vault. I can query vault in the Nautobot config file very easily. I can also use the vault agent to inject the secret as a file but injecting it as an environment variable is much harder with vault and arguably less secure. I would suggest allowing this variable to be set in the config file where I can configure any way I might want.

Inconsistent handling of "no matches found" cases

Expected Behavior

Consistent behavior across chat commands for the case where no matches are found corresponding to a given request.

Observed Behavior

Some commands (get_organizations, get_admins, get_networks, get_firewall_performance, get_camera_recent) return STATUS_FAILED when no matches are found, while other commands (get_devices, get_neighbors) send a message to the user but return STATUS_SUCCESS. Others (get_switchports, get_switchports_status, get_wlan_ssids, get_clients) have no special handling of this case at all.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.