This tutorial demonstrates how Red Hat Insights can be integrated with other services using webhooks. More specifically, we will be deploying a simple service that listens to webhooks from Red Hat Insights and turns them into messages posted to a Slack channel.
To complete this tutorial you'll need:
- a Slack team account
- either
- a Red Hat OpenShift account, or
- development environment with Docker
-
Open
https://<your-slack-team>.slack.com/apps/A0F7YS25R-bots
-
Click Add Configuration
-
Pick a username for the bot (e.g. insights-slackbot)
-
Click Add bot integration
-
Keep the generated Slack API Token for later
-
(Optional) bot user can be customized, for example its description, avatar, etc.
-
Back in your Slack team default view choose a channel you want the bot to post updates to and invite the bot to join this channel
insights-slackbot is a thin layer that translates events received from Red Hat Insights over webhooks and translates them into messages posted into a Slack channel.
It needs to be run and reachable from the Internet over HTTPS for the integration to work. There are multiple ways to achieve this:
Red Hat OpenShift is a container platform by Red Hat that provides environment for deploying and managing containers based on Docker. If you do not have an account yet a Started Plan can be used for free.
In your OpenShift Web Console:
-
Create a new project by clicking "New Project" button in upper right corner
-
Fill in project name and "Display Name"
-
Choose Import YAML / JSON tab
-
Use this template. The template will create a new deployment and set up a route for it to be available from the Internet. Proceed further by clicking the Create button.
-
Make sure Process the template is checked and click Continue
-
Fill in your Slack token and the name of the Slack channel you had invited the bot into
-
(Optional) Fill in a secret server token that will protect the webhook receiver from being called by unauthorized actors
-
Click Application --> Routes, locate the generated URL of the webhook endpoint (Hostname column) and keep it for the next step
An alternative option is to run insights-slackbot locally and use ngrok to tunnel webhook calls from Insights to the local instance.
- Open https://ngrok.com/download and download ngrok for your platform
- Unzip the package
- Pull the latest docker image of insights-slackbot
docker pull redhatinsights/insights-slackbot
- Run insights-slackbot
docker run --name insights-slackbot -p 3006:3006 -e SLACK_TOKEN=<your slack bot api token> -e SLACK_CHANNEL=<slack channel you had invited the bot into> redhatinsights/insights-slackbot:latest
- Run ngrock to tunnel webhook calls to the running container
./ngrok http 3006
- ngrok generates a unique URL that serves as the entry point for the tunnel. Locate the line that looks like
Locate the URL and keep it for the next step.
Forwarding https://8132d156.ngrok.io -> localhost:3006
-
Open to https://access.redhat.com/insightsbeta/config/webhooks
-
Click ADD WEBHOOK
-
Enter the insights-slackbot URL obtained in the previous step. Make sure the URL uses
https
. -
Click SAVE
-
Press the TEST EVENT button. A test message should appear in the slack channel you specified. Updates to your systems monitored by Red Hat Insights (e.g. new system registered, new issue identified, ...) will be posted to the Slack channel from now on.