Skip to content

Latest commit

 

History

History
82 lines (62 loc) · 4.25 KB

Tutorial.md

File metadata and controls

82 lines (62 loc) · 4.25 KB

Red Hat Insights Webhooks Tutorial

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.

Prerequisites

To complete this tutorial you'll need:

Getting Slack token

  1. Open https://<your-slack-team>.slack.com/apps/A0F7YS25R-bots

  2. Click Add Configuration

  3. Pick a username for the bot (e.g. insights-slackbot)

  4. Click Add bot integration

  5. Keep the generated Slack API Token for later

    Slack bot settings

  6. (Optional) bot user can be customized, for example its description, avatar, etc.

  7. 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

Running the bot

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:

Option A: Running insights-slackbot in Red Hat OpenShift

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:

  1. Create a new project by clicking "New Project" button in upper right corner

  2. Fill in project name and "Display Name"

    New project form

  3. Choose Import YAML / JSON tab

  4. 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.

  5. Make sure Process the template is checked and click Continue

  6. Fill in your Slack token and the name of the Slack channel you had invited the bot into

    OpenShift template form

  7. (Optional) Fill in a secret server token that will protect the webhook receiver from being called by unauthorized actors

  8. Click Application --> Routes, locate the generated URL of the webhook endpoint (Hostname column) and keep it for the next step

Option B: Running insights-slackbot locally

An alternative option is to run insights-slackbot locally and use ngrok to tunnel webhook calls from Insights to the local instance.

  1. Open https://ngrok.com/download and download ngrok for your platform
  2. Unzip the package
  3. Pull the latest docker image of insights-slackbot
    docker pull redhatinsights/insights-slackbot
    
  4. 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
    
  5. Run ngrock to tunnel webhook calls to the running container
    ./ngrok http 3006
    
  6. ngrok generates a unique URL that serves as the entry point for the tunnel. Locate the line that looks like
    Forwarding                    https://8132d156.ngrok.io -> localhost:3006
    
    Locate the URL and keep it for the next step.

Setting up Webhook in Insights

  1. Open to https://access.redhat.com/insightsbeta/config/webhooks

  2. Click ADD WEBHOOK

  3. Enter the insights-slackbot URL obtained in the previous step. Make sure the URL uses https.

  4. Click SAVE

  5. 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.

    Bot message