Rocket Chat Integration - bcgov/PIMS GitHub Wiki

rocketchat

Table of Contents

RocketChat Integration

RocketChat Integrations

image

Below is an example of how to create a Rocketchat integration with the backup container service using an "incoming" webhook.

Creating an Integration

When creating an "incoming" integration, you need to click on the 3 dots on the top right of the left side panel:

image

Next click on the Integrations as shown below and then you will need to click the "New" button at the top right of the screen to create a new integration:

image

You will need to "enable" this integration, and enter the following fields highlighted in yellow below, (note: that you will need to have already created the channel to use in this integration). We are using the user "rocket.cat" as the generic username that this integration will post as. You will also need to add the user "rocket.cat" to your channel in order for it to be able to post to your channel.

image

You may need to create your own script, but in our case we used this script which was provided in the backup container source code

All we needed to do is copy and paste that javascript code into the "Script" field as shown below and toggle the "Script Enabled" to enable it. image

After saving this integration the Webhook URL, Token, and Curl fields will be automatically generated and populated in this integration.

You can use the curl script to do a test of the webhook from a terminal on your local machine. Just copy the curl and paste it into your terminal, hit return and you should get a notification show up in the channel that you had specified for it to post to.

Using the Webhook

In our case, we are using this integration with the backup container provided by Platform Services. The backup container developed and maintained by Wade Barnes was created with Rocket Chat integration in mind

So, the next step is to copy the Webhook URL into a key/value secret in OpenShift which the backup container uses when it creates a backup. We first created a new key/value secret in each namespace (dev, test, and prod) and copied the webhook url into the Value field as shown below:

The next step is changing the configuration of the pims-backup deployment config so that it uses this new webhook. To do that, go to Deployment Configs in Openshift and then click on the pims-backup (there should only be one). Then select the "Environment" tab and scroll down to the WEBHOOK_URL section, in our case we changed it to get the webhook url from the "rocketchat-dev-backup" secret which was created in the previous step. The backup container also provided fields for the "ENVIRONMENT_FRIENDLY_NAME" as well as the "ENVIRONMENT_NAME" which will get used in the webhook, so that the notification that appears in the channel will describe which environment the backup was created in.

image

After you save the "pims-backup" deployment config, it will create a new "pims-backup" pod, which you can then use the terminal tab in the pod to check the settings by viewing the logs tab:

image

Note that any change to the "pims-backup" deployment config will remove the "pims-"backup" pod and will create a new pod.

Now, every time a database backup "runs" it will post to the webhook in Rocketchat allowing it to create a post in the pims-db-backups channel whether the backup was successfully created or if there was an error.