How do I send notifications to a Slack channel?

Is it possible to send alert notifications to a Slack channel?

Q: I need to post a message to a Slack channel every time alert is executed. How can I do that?

A: Please follow the below guide:

1. Create Slack API Webhook Integration

Create Incoming Webhook integration for your team as described on corresponding Slack API page. There is a link on that page (underlined below) that redirects you to the integration page for your team, assuming you are logged in and can manage the team:

Slack notifications - create Webhook integration

Click that link and on a page that opens select a channel to post your messages to:

Slack notifications - select channel

Click the green button to get the webhook URL and a brief guide on sending messages.

2. Create Send HTTP(S) request action

Now open IPHost GUI client and create new “Send HTTP(S) request” action (click “Alerting > Alerts”, select “Simple Actions” tab):

Slack notifications - create HTTP(S) request action

In this action, use the webhook URL given to you by Slack, and define JSON payload using the template variables:

Slack notifications - HTTP(S) request action definition

(enter the whole URL; on the above screenshot channel-specific part is greyed)

For your convenience, “POST Data” contents are given below:

{
  "username": "IPHost $NewState alert",
  "icon_url": "https://cdn.iphostmonitor.com/images/icons/40x40/$NewState.png",
  "text": "<$MonitorReportUrl|$MonitorName> on <$HostReportUrl|$HostName> - $EventShortDescription $Duration"
}

Now add newly created Simple Action to an existing alert, for example to “E-mail to Administrator + Popup” alert used by the Default Alerting Rule. Click “Alerts”, select “E-mail to Administrator + Popup” (or any other alert of your choice) and click “Edit”. Use “Add” drop-down in a newly opened alert editor to add “Post to Slack” simple action:

Slack notifications - add action to alert

Please don’t forget to click “OK” to save changes.

3. Test Slack notifications

Now that “Post to Slack” action has been added to alerts, try putting a monitor to Down state and back (by altering its “State conditions” and polling the monitor), or use “Alerting > Testing” tab to simulate alert execution.

If Slack integration has been done correctly, you will see something like below in your Slack channel. Please note that alerts are grouped by state and identified by IPHost state icons:

Slack notifications - sample channel posts

Monitor and host names are linked to corresponding daily reports. You can further customize the messages posted to Slack channel using other template variables in “text” property of the “POST Data” contents (see step 2. above).

Related topics