Meraki Webhooks with json-server
Quickly launch a JSON server to receive, store and process Meraki webhook Alerts.
Overview
Meraki Webhooks are a powerful and lightweight new way to subscribe to alerts sent from the Meraki Cloud when something happens. They include a JSON formatted message and are sent to a unique URL where they can be processed, stored or used to trigger powerful automations. This solution provides you with a rapid way to setup a hosted service capable of receiving and storing any webhook alert data.
Prerequisites
- NodeJS
- Meraki Dashboard
- Postman (optional)
- Ngrok (optional)
Install json-server
Begin by installing json-server globally on your system. This is a light-weight web server which uses a simple JSON file to store and retrieve data like a database. It then exposes default routes to save the data and provide a simple HTML front-end.
$ npm install -g json-server
Run
$ json-server merakialerts.json
The server will start with a few default routes and store the data into our merakialerts.json file.
All of the Meraki Alerts will be sent to the default http://localhost:3000/posts endpoint.
{^_^}/ hi!
Oops, merakialerts.json doesn't seem to exist
Creating merakialerts.json with some default data
Loading merakialerts.json
Done
Resources
http://localhost:3000/posts
http://localhost:3000/comments
http://localhost:3000/profile
Home
http://localhost:3000
Test with Postman
You can use Postman to quickly test any of the Meraki Alerts by sending mock data to your json-server.
Install Collection
Push the “Run in Postman” button to add this collection to your instance. You will be prompted to install Postman if it is not already available.
Once the collection is added, update the {{ webhook - url }} environment variable with your json-server address:
Send Test Alert
The folders on the left will contain Meraki Alerts based on their respective categories. Select any one of the POST endpoints and then press the blue “Send” button to trigger the event.
View Alert Data with Postman
The Postman collection includes a few test endpoints for listing the data received by our json-server. When you run these endpoints, you will receive a JSON response matching the query.
View Alert Data with json-server
You can also use the built-in web page with json-server to view the data. Simply open your web browser to:
Public Internet Access
In order for the Meraki cloud to send the alerts to the local address, you must make it publicly available. You can do this by either adjusting your network firewall rules or quickly spin up a local proxy to your local instance using ngrok.
$ ngrok http 3000
ngrok by @inconshreveable (Ctrl+C to quit)
Session Status online
Session Expires 7 hours, 59 minutes
Version 2.2.8
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://6d78ac34.ngrok.io -> localhost:3000
Forwarding https://6d78ac34.ngrok.io -> localhost:3000
Connections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00
Your new secure public address is:
https://6d78ac34.ngrok.io
Alternative Hosting Method
Use the json-server-heroku project to launch json-server with more options and easily deploy to a variety of free hosting services.
Meraki Alerts
Configure the Meraki Dashboard to send all Alerts by adding an HTTP server with the public URL of your server. In this example, we would use https://6d78ac34.ngrok.io for the URL.
-
Add HTTP servers by defining their unique URL and shared
secret
[ network-wide > alerts ]
-
Configured HTTP servers can now be selected as a recipient for any
alert within the dashboard
[ network-wide > alerts ]