cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
25730
Views
20
Helpful
15
Replies

Webhooks in Slack or Teams...

GolfKilo
Community Member

Anyone got that working?

1 Accepted Solution

Accepted Solutions

After some quick research, it looks like the POST format of the Slack webhook API requires a specific JSON format as discussed.
This means you cannot just point Meraki to Slack, since you will need some middleware to format the data first. Zapier does this with their integration. Alternatively, you could write a micro-service to do this.

https://api.slack.com/incoming-webhooks#enable_webhooks

Expected Slack format

POST https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
Content-type: application/json
{
    "text": "Hello, world."
}

Meraki Format

{
  "alertData" : {
    "kbTotal" : 10750,
    "nodeTag" : "",
    "period" : 1200,
    "usageThreshold" : 10240
  },
  "alertId" : "643451796765320956",
  "alertType" : "Network usage alert",
  "networkId" : "L_123456789123456789",
  "networkName" : "Network - 1",
  "networkUrl" : "https://n1.meraki.com/...",
  "occurredAt" : "2018-10-25T17:17:38.623000Z",
  "organizationId" : "123456",
  "organizationName" : "Organization",
  "organizationUrl" : "https://n1.meraki.com/o/.../organization/overview",
  "sentAt" : "2018-10-25T17:17:46.608245Z",
  "sharedSecret" : "asdf1234",
  "version" : "0.1"
}

Middleware would convert JSON to look like this, where "text" could be the "alertType" and then you could parse out any other important details to format the message.

POST https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
Content-type: application/json
{
    "text":"Network usage alert /n more info.."
}

View solution in original post

15 Replies 15

Nothing for Slack/Teams Webhooks though and test in the dashboard also fails... The hook does work fine with curl though...


@GolfKilo wrote:

Nothing for Slack/Teams Webhooks though and test in the dashboard also fails... The hook does work fine with curl though...


These statements don't sound right... If the test webhook isn't received then your receiver isn't listening, or something is blocking the Post from coming through. I would start there.

I also didn't realize you could make curl listen for an HTTP Post from an external source. Can you share the switches you're using to do that? I'm interested in knowing how to do that.

GolfKilo
Community Member

curl -X POST -H 'Content-type: application/json' --data '{"Hello":"World"}' https://hooks.slack.com/services/{{whatever}}


The hook works, it seems like Slack (&MS Teams) don't like the json Meraki provides... As most probably use Slack or Teams. It's a bit useless Meraki feature at the moment.

Ahh! OK I misunderstood. I thought you were saying you were using curl to receive the post from Meraki. Now I understand.

I'm not sure I have much to offer here. I've been playing with webhooks a bit, but not with Slakc or Teams. I just made a little LED rig and attached it to a Raspberry Pi so that I get little flashing lights when an alert goes off. But I have that working at least. Not sure why it's not working for you...

One thing that did hang me up for a bit was that you have to add the server on the alerts page, AND then you have to add the server to each specific alert you want to (or add it to the default recipient). Maybe that's where you're going wrong?

GolfKilo
Community Member

Nope, it's the only recipient, and if I add an email admin, the email gets thru...

And the "send test webhook" in the dashboard fails also... Can only be that Slack doesn't like the json...

I believe you're correct - in the above links, they are using Zapier to do the translation from Meraki webhook payload, to webex teams friendly payload.

Zapier is rather straightforward, and though I've not played with it in a year or two, I believe they have a free tier.

Your other option is to host an app yourself, and do that message translation. To that end, for testing webhooks on your laptop, look at ngrok- it creates an http(s) tunnel to your laptop, giving you a public URL. Also lets you replay webhook payloads, amazing for testing!

After some quick research, it looks like the POST format of the Slack webhook API requires a specific JSON format as discussed.
This means you cannot just point Meraki to Slack, since you will need some middleware to format the data first. Zapier does this with their integration. Alternatively, you could write a micro-service to do this.

https://api.slack.com/incoming-webhooks#enable_webhooks

Expected Slack format

POST https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
Content-type: application/json
{
    "text": "Hello, world."
}

Meraki Format

{
  "alertData" : {
    "kbTotal" : 10750,
    "nodeTag" : "",
    "period" : 1200,
    "usageThreshold" : 10240
  },
  "alertId" : "643451796765320956",
  "alertType" : "Network usage alert",
  "networkId" : "L_123456789123456789",
  "networkName" : "Network - 1",
  "networkUrl" : "https://n1.meraki.com/...",
  "occurredAt" : "2018-10-25T17:17:38.623000Z",
  "organizationId" : "123456",
  "organizationName" : "Organization",
  "organizationUrl" : "https://n1.meraki.com/o/.../organization/overview",
  "sentAt" : "2018-10-25T17:17:46.608245Z",
  "sharedSecret" : "asdf1234",
  "version" : "0.1"
}

Middleware would convert JSON to look like this, where "text" could be the "alertType" and then you could parse out any other important details to format the message.

POST https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
Content-type: application/json
{
    "text":"Network usage alert /n more info.."
}

Not really a workable solution for us, but might work for someone else.

Here is how the Zapier settings for my Meraki <--> Zapier<--> Slack integration look like... in case it helps.

ps: Keep up the great work Tony Carmichael!

image.png

I made some mistakes

UPDATE

- with Webhook Payload Templates (beta) you can now send alerts DIRECTLY to Slack or Teams without middleware.

More info here

JQ2
Community Member

I have spent a few hours trying to configured webhook to work with slack. I agree, it seems like a a useless feature. All tech support does is pointing you to un-relevant documents.

CIDR32
Frequent Visitor
Frequent Visitor

I needed this ability, so I wrote a nodejs app to be the middleware. To try and make it easy to use I turned that into a docker container (because isn't everything in a docker container now??). Added support for Slack, MS Teams, and Telegram. Would be easy to add services like Discord, or any other services that has an API you can POST to.

Meraki Alerts Container

Also posted the code on Github

Nice work! This will be a great benefit to all.

.. I had to make a small change to the app.js file line 29

the original line was causing errors running.
res.render('error');
by using this method, it doesn't require a default view to be setup and works great.
res.json({ error: err });
Error I was receiving
> node ./bin/www

POST / 400 24.616 ms - 1314
Error: No default engine was specified and no extension was provided.
at new View (/Users/u/dev/merakialerts/node_modules/express/lib/view.js:61:11)