Notify your Pagerduty oncall by mentioning @oncall in Slack channel with help of Hubot

Read Time: 3 mins

In this article, I will explain how you can Notify a Pagerduty oncall by mentioning @oncall in Slack channel with help of Hubot. If you are a DevOps, Developer or any engineer who works on infrastructure which demands high availability and stability, you must be familiar with Pagerduty. Pagerduty takes care of oncall management and notify the Oncall person via Phone call, SMS, Mail …etc.  And an Oncall is someone who acts on alerts which is received via Pagerduty notification methods. I think I don’t have to explain much more about Oncall person because nowadays every company has oncall culture.

 

Assume you are a developer, and you are seeing app owned by you is not behaving as usual. Now you want to talk to the DevOps Oncall to check for any system level issues. You know the Slack channel for DevOps, and you messaged there about this abnormality. If we don’t know the DevOps Oncall name, generally people mention @here or @channel to notify everybody in the slack channel. Why are we disturbing others, if someone can help you notify the DevOps Oncall alone when you mention @oncall in your message. Yes, we can setup Hubot to do this.

This funny Pic clearly explains what we are going to do here 😛

Note: Here Jarvis is name of the Hubot chatbot.

Step 1: Integrate Hubot with Slack

Before we start, you need to have Hubot setup and integrated with Slack. If you don’t, go through this easy tutorial from easyaslinux >>.

Step 2: Write a JavaScript to do the work

Once you have integrated Hubot with Slack, go to the scripts directory, create a JavaScript file at_oncall.js  and add below content.

Note: I developed this script assuming that same username is used to authenticate both Pagerduty and Slack.

You need to give values for two variables pagerduty_api_key  and escalation_policy_name  to get the script working.

What the JavaScript does:
  1. Hubot hear for @oncall  mention in the slack.
  2. Once someone mention @oncall , script finds escalation policy ID by making an API call to Pagerduty RestAPI with Escalation policy name as input.
  3. Then gets Oncall person’s login Email ID from Pagerduty RestAPI by making another API call.
  4. Then split the email ID with ”@” and first part is sent back to slack(After prefix ‘@’ added).
  5. And Jarvis put the message in the channel.

Step 3: Install required NPM packages

Fortunately, we need to install only one node.js package for the script which is request  package. Go to the directory where bot installed and run below command.

Now we have everything ready. Let’s restart Hubot service to detect the newly added script.

Step 4: Let’s test it

Now go to slack channel where Hubot chatbot is present, ask Oncall to check something and see what happens.

See Hubot has tagged the Oncall person for you. You don’t have to go around and ask “who is oncall?”. This will be useful for managers also. You can customise the JavaScript to tag Dev/DevOps oncall, tag oncall based on the channel …etc. Do explore!

 

Thanks for the time taken to read my blog. Subscribe to this blog so that you don’t miss out anything useful (Checkout Right Sidebar for the Subscription Form) . Please also put your thoughts on this article as   comments .

A Site Reliability Engineer and an automation enthusiast.
Posts created 32

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top
x