Certera.io notification via Slack webhook on Rocketchat

Certera is a software that allows you, as sysadmin, to centralize the production and the distribution of SSL certificates for your websites and applications.

If you landed here it’s because you probably need to go deeper on some topic as notifications from Certera when something is going wrong or, more often, when a certificate is about to expire.

An easy and effective way to get notifications from Certera is on your Slack chat with a webhook, but what happen if you or your company are using Rocket Chat as instant messaging system?

I personally opened a ticket (feature request) to Certera developers (that are very reactive) in which I asked for a RocketChat integration for Certera.io.

I’m sure they will solve it soon, but meanwhile I will give you some hint to make the things done with the Slack Webhook, in order to translate the request from Slack to RocketChat.

Let’s begin then.

Step1 – Create a Rocketchat webhook

  • Go to Admin panel -> Integration
  • Create an Incoming Webhook dedicated to certera
  • Configure it
  • Activate the script and put there the following code (gotten in Rocket Chat Integrations page)
/* exported Script */
/* globals console, _, s */

/** Global Helpers
 *
 * console - A normal console instance
 * _       - An underscore instance
 * s       - An underscore string instance
 */

class Script {
  /**
   * @params {object} request
   */
  process_incoming_request({ request }) {
    // request.url.hash
    // request.url.search
    // request.url.query
    // request.url.pathname
    // request.url.path
    // request.url_raw
    // request.url_params
    // request.headers
    // request.user._id
    // request.user.name
    // request.user.username
    // request.content_raw
    // request.content

    // console is a global helper to improve debug
    console.log(request);

    return {
      content:{
        text: request.content.blocks[0].text.text + "\n" +  request.content.blocks[1].text.text
        // "attachments": [{
        //   "color": "#FF0000",
        //   "author_name": "Rocket.Cat",
        //   "author_link": "https://open.rocket.chat/direct/rocket.cat",
        //   "author_icon": "https://open.rocket.chat/avatar/rocket.cat.jpg",
        //   "title": "Rocket.Chat",
        //   "title_link": "https://rocket.chat",
        //   "text": "Rocket.Chat, the best open source chat",
        //   "fields": [{
        //     "title": "Priority",
        //     "value": "High",
        //     "short": false
        //   }],
        //   "image_url": "https://rocket.chat/images/mockup.png",
        //   "thumb_url": "https://rocket.chat/images/mockup.png"
        // }]
       }
    };

    // return {
    //   error: {
    //     success: false,
    //     message: 'Error example'
    //   }
    // };
  }
}

Configure and activate everything.

Step2 – Put the webhook url to Certera.io admin web panel

In Certera.io notification page you will find the Slack webhook URL, put what you have produced on Rocketchat side and activate the notification.

Done!

Explaination

You have certainly noticed that the most of the source code is commented (//), infact the most important part of the code is:

        text: request.content.blocks[0].text.text + "\n" +  request.content.blocks[1].text.text

This code translates the payload of the POST request gotten via webhook by Rocket Chat.

The “translation” is done according to the template I found in Certera.io source code.