Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Pagerduty ack assigned #1280

Closed
wants to merge 3 commits into from

4 participants

@ChrisLundquist

This makes it so hubot pager ack only acks incidents assigned to your user. This minimizes the chances of acking something you didn't intend.

The real change in this PR is 328be7b

The other commits are whitespace noise and cleanup.

/cc @github/ops-tools @github/ops

@jnewland
Owner

Lookin good

@technicalpickles technicalpickles deleted the pager-duty-ack-assigned branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 40 additions and 31 deletions.
  1. +40 −31 src/scripts/pagerduty.coffee
View
71 src/scripts/pagerduty.coffee
@@ -14,7 +14,7 @@
# hubot pager me problems - return all open incidents
# hubot pager me ack <incident> - ack incident #<incident>
# hubot pager me resolve <incident1> <incident2> ... <incidentN> - ack all specified incidents
-# hubot pager me ack - ack all triggered incidents
+# hubot pager me ack - ack all triggered incidents
# hubot pager me resolve <incident> - resolve incident #<incident>
# hubot pager me resolve <incident1> <incident2> ... <incidentN>- resolve all specified incidents
# hubot pager me resolve - resolve all acknowledged incidents
@@ -22,12 +22,12 @@
# Dependencies:
# "moment": "1.6.2"
#
-# Notes:
-# To setup the webhooks and get the alerts in your chatrooms, you need to add the endpoint you define here (e.g /hooks) in
-# the service settings of your Pagerduty accounts. You also need to define the room in which you want them to appear.
-# (Unless you want to spam all the rooms with alerts, but we don't believe that should be the default behavior :)
+# Notes:
+# To setup the webhooks and get the alerts in your chatrooms, you need to add the endpoint you define here (e.g /hooks) in
+# the service settings of your Pagerduty accounts. You also need to define the room in which you want them to appear.
+# (Unless you want to spam all the rooms with alerts, but we don't believe that should be the default behavior :)
#
-# URLS:
+# URLS:
# http://developer.pagerduty.com/documentation/rest/webhooks
# http://support.pagerduty.com/entries/21774694-Webhooks-
#
@@ -40,7 +40,7 @@
# HUBOT_PAGERDUTY_ROOM - Room in which you want the pagerduty webhook notifications to appear
# HUBOT_PAGERDUTY_ENDPOINT - Pagerduty Webhook listener e.g /hook
#
-# Authors:
+# Authors:
# Jesse Newland, Josh Nicols, Jacob Bednarz, Chris Lundquist, Chris Streeter, Joseph Pierri, Greg Hoin
#
@@ -54,7 +54,7 @@ pagerDutyBaseUrl = "https://#{pagerDutySubdomain}.pagerduty.com/api/v1"
pagerDutyServiceApiKey = process.env.HUBOT_PAGERDUTY_SERVICE_API_KEY
pagerDutyScheduleId = process.env.HUBOT_PAGERDUTY_SCHEDULE_ID
pagerRoom = process.env.HUBOT_PAGERDUTY_ROOM
-# Webhook listener endpoint. Set it to whatever URL you want, and make sure it matches your pagerduty service settings
+# Webhook listener endpoint. Set it to whatever URL you want, and make sure it matches your pagerduty service settings
pagerEndpoint = process.env.HUBOT_PAGERDUTY_ENDPOINT || "/hook"
module.exports = (robot) ->
@@ -143,6 +143,9 @@ module.exports = (robot) ->
robot.respond /(pager|major)( me)? ack(nowledge)?$/i, (msg) ->
pagerDutyIncidents msg, 'triggered,acknwowledged', (incidents) ->
+ email = msg.message.user.pagerdutyEmail || msg.message.user.email_address
+ incidents = incidentsForEmail(incidents, email)
+
incidentNumbers = (incident.incident_number for incident in incidents)
if incidentNumbers.length < 1
msg.send "Nothing to acknowledge"
@@ -164,7 +167,7 @@ module.exports = (robot) ->
msg.send "Nothing to resolve"
return
- # only resolve things that are acknowledged
+ # only resolve things that are acknowledged
updateIncidents(msg, incidentNumbers, 'acknowledged', 'resolved')
robot.respond /(pager|major)( me)? notes (.+)$/i, (msg) ->
@@ -220,7 +223,6 @@ module.exports = (robot) ->
withPagerDutyUser = (msg, cb) ->
-
email = msg.message.user.pagerdutyEmail || msg.message.user.email_address
unless email
msg.send "Sorry, I can't figure out your email address :( Can you tell me with `#{robot.name} pager me as you@yourdomain.com`?"
@@ -335,7 +337,7 @@ module.exports = (robot) ->
# SERVICEDESC: 'snapshot_repositories',
# SERVICESTATE: 'CRITICAL',
# HOSTSTATE: 'UP' },
-
+
summary = if inc.trigger_summary_data
# email services
if inc.trigger_summary_data.subject
@@ -354,7 +356,7 @@ module.exports = (robot) ->
"- assigned to #{inc.assigned_to_user.name}"
else
""
-
+
"#{inc.incident_number}: #{inc.created_on} #{summary} #{assigned_to}\n"
@@ -409,7 +411,7 @@ module.exports = (robot) ->
console.log res.statusCode
console.log body
-
+
# Pagerduty Webhook Integration (For a payload example, see http://developer.pagerduty.com/documentation/rest/webhooks)
parseWebhook = (req, res) ->
hook = req.body
@@ -429,49 +431,56 @@ module.exports = (robot) ->
else
'(???)'
+ incidentsForEmail = (incidents, user_email) ->
+ incidents.filter (incident) ->
+ getUserForIncident(incident) == user_email
+
generateIncidentString = (incident, hookType) ->
console.log "hookType is " + hookType
+ assigned_user = getUserForIncident(incident)
+ incident_number = incident.incident_number
+
if hookType == "incident.trigger"
"""
- Incident # #{incident.incident_number} :
- #{incident.status} and assigned to #{getUserForIncident(incident)}
+ Incident # #{incident_number} :
+ #{incident.status} and assigned to #{assigned_user}
#{incident.html_url}
- To acknowledge: @#{robot.name} pager me ack #{incident.incident_number}
- To resolve: @#{robot.name} pager me resolve #{incident.incident_number}
+ To acknowledge: @#{robot.name} pager me ack #{incident_number}
+ To resolve: @#{robot.name} pager me resolve #{}
"""
else if hookType == "incident.acknowledge"
"""
- Incident # #{incident.incident_number} :
- #{incident.status} and assigned to #{getUserForIncident(incident)}
+ Incident # #{incident_number} :
+ #{incident.status} and assigned to #{assigned_user}
#{incident.html_url}
- To resolve: @#{robot.name} pager me resolve #{incident.incident_number}
+ To resolve: @#{robot.name} pager me resolve #{incident_number}
"""
else if hookType == "incident.resolve"
"""
- Incident # #{incident.incident_number} has been resolved by #{getUserForIncident(incident)}
+ Incident # #{incident_number} has been resolved by #{assigned_user}
#{incident.html_url}
"""
else if hookType == "incident.unacknowledge"
"""
- #{incident.status} , unacknowledged and assigned to #{getUserForIncident(incident)}
+ #{incident.status} , unacknowledged and assigned to #{assigned_user}
#{incident.html_url}
- To acknowledge: @#{robot.name} pager me ack #{incident.incident_number}
- To resolve: @#{robot.name} pager me resolve #{incident.incident_number}
+ To acknowledge: @#{robot.name} pager me ack #{incident_number}
+ To resolve: @#{robot.name} pager me resolve #{incident_number}
"""
else if hookType == "incident.assign"
"""
- Incident # #{incident.incident_number} :
- #{incident.status} , reassigned to #{getUserForIncident(incident)}
+ Incident # #{incident_number} :
+ #{incident.status} , reassigned to #{assigned_user}
#{incident.html_url}
- To resolve: @#{robot.name} pager me resolve #{incident.incident_number}
+ To resolve: @#{robot.name} pager me resolve #{incident_number}
"""
else if hookType == "incident.escalate"
"""
- Incident # #{incident.incident_number} :
- #{incident.status} , was escalated and assigned to #{getUserForIncident(incident)}
+ Incident # #{incident_number} :
+ #{incident.status} , was escalated and assigned to #{assigned_user}
#{incident.html_url}
- To acknowledge: @#{robot.name} pager me ack #{incident.incident_number}
- To resolve: @#{robot.name} pager me resolve #{incident.incident_number}
+ To acknowledge: @#{robot.name} pager me ack #{incident_number}
+ To resolve: @#{robot.name} pager me resolve #{incident_number}
"""
parseIncidents = (messages) ->
Something went wrong with that request. Please try again.