Slack (www.slack.com) is a popular chat/communications platform used by thousands of organizations around the world.
Slack provides an API to allow third-party apps such as Omnilert to post messages to Slack channels. Here's how to set up such a connection to post Omnilert alerts to Slack using Webhooks.
(Please Note: You will need administrator access to Omnilert and your organization's Slack account to complete this setup.)
Step 1: Create a Slack application and enable Slack's "Webhooks" feature.
You will need to create a Slack "app" to receive the alerts sent by Omnilert. This app will need to have its "Webhook" feature enabled on Slack. (Your local Slack admin may need to assist you in this step as Slack will require "approval" for new apps.)
See https://api.slack.com/apps for detailed instructions from Slack on how to create an app and enable webhooks for that app.
Create a Slack App
- Go to https://api.slack.com/apps
- Click “Create an App” Button.
- There are several popups. (You can use the default values for this Slack app to function.)
The end result of that setup will be a URL provided by Slack. Copy that URL. You will need it for Step 3.
Activate Incoming Webhooks in Slack App
- Click Incoming Webhooks
- Click toggle to activate Incoming Webhooks.
Add webhook to workspace
- Click “Add new webhook to workspace”
- There will be a popup shown where you can choose the Slack channel from your existing channels. This determines which channel the webhook will post alerts to.
- Copy your new Slack webhook URL using the Copy button. (Save this URL. You will use this URL in the JSON script in Step 3 below.)
Step 2: Create a new Webhook Endpoint in Omnilert
In Omnilert, you will need to set up a new "Webhook" endpoint to send messages to your Slack app.
Go to Endpoints > Add Endpoint to create a new Webhook endpoint in Omnilert's admin portal. See: Adding a new Endpoint for instructions. (Tip: Be sure to set your new endpoint as "Active")
Step 3: Configure Omnilert Webhook to send to Slack
Next, we need to edit the new webhook endpoint and insert a JSON script to instruct Omnilert on where to send its hook and how to format the hook for Slack to read it.
- Go to Endpoints > Active (or Inactive if you hadn't activated your new endpoint yet!)
- Click on the new webhooks endpoint in the list
- Go to the "Configure" tab for your new webhook endpoint.
- Paste your customized JSON script (see below for code!)
- Check "Bypass Service Status Checks". (Slack's API will not accept "OPTION" requests, so this feature must be disabled for the webhook to work properly.)
- Click Update configuration to save your changes.
The Omnilert configuration JSON script for sending to Slack is quite simple. You'll only need to set 4 parameters in your JSON:
- url = This will be your Slack app's webhook URL from Step 1.
- postData = The payload to send to Slack. Slack will want it to be a parameter called "text" with the text content to display. In the example below, we'll insert the Omnilert content using variables {{webhook_subject}} and {{webhook_body}}
- method = POST (We want to post the data!)
- headers = Where we sent the content type for the posts. This will always be the same thing; "application/json" for Slack.
Example Configuration JSON for sending to Slack:
You will need to customize the code below to meet your needs. At a minimum, you must replace "YOUR_SLACK_WEBHOOK_URL" with the Slack webhook URL created in Step 1 of this guide.
{
"url": "YOUR_SLACK_WEBHOOK_URL",
"postData": {
"text": "*Subject:* {{webhook_subject}} \n *Message:* {{webhook_body}} \n\n `This message sent via OMNILERT`"
},
"method": "POST",
"headers": {
"Content-type": "application/json"
}
}
In this example, we've configured the Slack message to include both the "Subject" {{webhook_subject}} and "Message body" {{webhook_body}} of the Omnilert alert.
Naturally, you can edit the formatting and layout to your own liking. Simply edit the "postData" section of the JSON script accordingly.
(For more info on formatting content in Slack messages, see https://api.slack.com/messaging/webhooks )
Sending Omnilert messages to Slack
After your configuration is complete, you'll be able to send Omnilert messages to your Slack channel right away.
Simply select your new webhook endpoint as your would any other endpoint in Omnilert!
The message will then be posted to Slack via the app created in Step 1.
Comments
0 comments
Please sign in to leave a comment.