In this tutorial I will show you how to use the Webhook function of Meraki, and integrate with raspberry pi.
Webhook?
We can call Webhook as “Web Callback” or “Http push API”. It is a system to let the server send some message to any client when some event is happening.
It is more Efficient than sending the request between Application A and Application B to monitor the status of each side.
(For example, register the webhook in github and send the notification to slack while the Responsibility is updated)
Reference Link
http://soup01.com/en/category/cisco/
Configure in Meraki Side
Go to MerakiのDash Board>Network-wide>CONFIGURE>Alerts.
Here is the configuration screen of webhook.
Test Server
We will prepare a Test server.
Cop the “Your Unique URLのLINK”.
Go back to the Meraki Dashboard, Click Add an HTTP server.
Name:Server name
URL:The Test server URL.
Finally Press the Send test webhook button to try the feature.
The status is changed to Enqueued.
And you can see the Meraki Webhook notification is received!
And Also you can view the content of Webhook.
The status is changed to Delivered.
Setup Raspberry
We will start-up a Local Server in the raspberry and then public it to the cloud by using the Ngrok services.
Then In the Meraki Dashboard we will configure the Webhook link to this Ngrok link to get the notification.
Ngrok Setup
Please reference this link to configure a Ngrok server.
Meraki Side
Paste the Ngrok server link to the Webhook URL setting.
Local Server Code
Here is the sample code to configure a Python http server with return status 200, then print out the message that received from Meraki Webhook.
import http.server import socketserver import json class MyHandler(http.server.BaseHTTPRequestHandler): def do_POST(self): self.send_response(200) self.end_headers() print(self.path) content_length = int(self.headers[‘Content-Length’]) post_data = self.rfile.read(content_length) print(post_data) def do_GET(self): self.send_response(200,”GET is received.”) print(“GET is received”) self.end_headers() with socketserver.TCPServer((“”, 8001), MyHandler) as httpd: httpd.serve_forever() |
Result
We can see the server can receive the message from Meraki Webhook.
In the Ngrok terminal, we can also see the post request is received.