Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

Open source @github's Hubot PagerDuty integration #858

Merged
merged 17 commits into from
Apr 12, 2013

Conversation

jnewland
Copy link
Contributor

Usage

hubot pager help

  /who's on call              # return the username of who's on call

  /pager me page <msg>        # create a new incident

  /pager me 60                # take the pager for 60 minutes

  /pager me incidents         # return the current incidents
  /pager me problems          # return all open inicidents

  /pager me ack 24            # ack incident #24
  /pager me resolve 24        # resolve incident #24

Config

Some environment variables are required:

HUBOT_PAGERDUTY_USERNAME
HUBOT_PAGERDUTY_PASSWORD
HUBOT_PAGERDUTY_SUBDOMAIN
HUBOT_PAGERDUTY_APIKEY
HUBOT_PAGERDUTY_SCHEDULE_ID

Caveats

/pager me 60 assumes your Campfire and PagerDuty usernames are identical.

Easter Eggs

major can be substituted for pager in most places. Thank Siri for this one.

@technicalpickles
Copy link
Contributor

I'm working on some style updates (ie documentation format) and generalizing... So, plz hold off merging quite yet :)

On Mar 29, 2013, at 2:28 PM, Jesse Newland [email protected] wrote:

Usage

hubot pager help

/who's on call # return the username of who's on call

/pager me page # create a new incident

/pager me 60 # take the pager for 60 minutes

/pager me incidents # return the current incidents
/pager me problems # return all open inicidents

/pager me ack 24 # ack incident #24
/pager me resolve 24 # resolve incident #24
Config

Some environment variables are required:

HUBOT_PAGERDUTY_USERNAME
HUBOT_PAGERDUTY_PASSWORD
HUBOT_PAGERDUTY_SUBDOMAIN
HUBOT_PAGERDUTY_APIKEY
HUBOT_PAGERDUTY_SCHEDULE_ID
Caveats

/pager me 60 assumes your Campfire and PagerDuty usernames are identical.

Easter Eggs

major can be substituted for pager in most places. Thank Siri for this one.

You can merge this Pull Request by running

git pull https://github.com/jnewland/hubot-scripts pagerduty
Or view, comment on, or merge it at:

#858

Commit Summary

open source @github's hubot pagerduty script
File Changes

A src/scripts/pagerduty.coffee (235)
Patch Links:

https://github.com/github/hubot-scripts/pull/858.patch
https://github.com/github/hubot-scripts/pull/858.diff

@jnewland
Copy link
Contributor Author

Thanks @technicalpickles 👍

@technicalpickles
Copy link
Contributor

So far, I was able to:

  • document the commands and environment variables
  • add error checking for environment variables missing
  • cleanup formatting of incidents (ie underline 'acknowledged' and 'triggered', since it confused me the first time when there were triggered or acknowledged, but not both)

The last thing I'd like to see in this is getting rid of the caveat that pagerduty & chat user name has to match. Thereotically, a msg has a user object, but the metadata of that will depend on the adapter. campfire (might) have an email, which could be looked up against the pagerduty API, but that changes the assumption to the pagerduty & campfire email are the same. The Shell does not have that though, but maybe could be fixed to.

Another thought is to have a pager me command to tell the bot your pagerduty id. that'd help a little, but it'd make it more manual for new team members.

@martinisoft
Copy link

@technicalpickles I'm in favor of introducing yourself to hubot for the pagerduty id. It's similar to telling hubot your github name for the Play integration.

@technicalpickles
Copy link
Contributor

@martinisoft yeah, I think that'll be needed. I would still like to see if we can correctly guess based on a user's name/email what their pagerduty thing is

@tombell
Copy link
Contributor

tombell commented Apr 4, 2013

What's the status on this, good to merge?

@technicalpickles
Copy link
Contributor

Not yet, still needs those changes I was talking about to either tell hubot your pagerduty user info, or correctly guess it based on campfire's user.

Sent from my iPhone

On Apr 4, 2013, at 4:48 PM, Tom Bell [email protected] wrote:

What's the status on this, good to merge?


Reply to this email directly or view it on GitHub.

@tombell
Copy link
Contributor

tombell commented Apr 5, 2013

I modified hubot to allow adapters to pass more details along with the message, so if that isn't there it should be easy to add without breaking all the things.

@joemiller
Copy link

Would love to use this with an irc-based hubot so I'm waiting to see what comes of the "register yourself to hubot so he knows your PD email". Anxiously awaiting final commits. Also available to help if needed.

@tombell
Copy link
Contributor

tombell commented Apr 6, 2013

I think the best way is attempt to identity you by campfire email else fallback to some manual identification. This means it won't be entirely tied to the campfire adapter.

@joemiller
Copy link

For irc (or other systems without a good 1:1 email mapping) I was thinking something like registering your PD email and then save it in the redis brain. I suppose it wouldn't be too hard to include email upon invocation too, something like: "/msg hubot me [email protected] 60" .. ?

@technicalpickles
Copy link
Contributor

@jnewland was doing more work on this, and got an error like:

TypeError: Object Wed Apr 10 2013 19:07:24 GMT-0400 (EDT) has no method 'addHours'
  at withCurrentOncall (/Users/technicalpickles/src/hubot/hubot-scripts/src/scripts/pagerduty.coffee:225:19)

Code is:

  oneHour = now.addHours(1).toISOString()

Googling points at datejs. Does that sound right? Need to get that documented. I'm also considering using momentjs instead.

@jnewland
Copy link
Contributor Author

Yeah, likely. Would like to avoid any external deps if possible. I'll see what I can do here.

On Apr 10, 2013, at 7:12 PM, Josh Nichols [email protected] wrote:

@jnewland was doing more work on this, and got an error like:

TypeError: Object Wed Apr 10 2013 19:07:24 GMT-0400 (EDT) has no method 'addHours'
at withCurrentOncall (/Users/technicalpickles/src/hubot/hubot-scripts/src/scripts/pagerduty.coffee:225:19)
Code is:

oneHour = now.addHours(1).toISOString()
Googling points at datejs. Does that sound right? Need to get that documented. I'm also considering using momentjs instead.


Reply to this email directly or view it on GitHub.

@technicalpickles
Copy link
Contributor

I think I like the idea of moment, rather than datejs, because it doesn't modify the Date prototype. Actually have a version working with moment already.

On Apr 10, 2013, at 7:37 PM, Jesse Newland [email protected] wrote:

Yeah, likely. Would like to avoid any external deps if possible. I'll see what I can do here.

On Apr 10, 2013, at 7:12 PM, Josh Nichols [email protected] wrote:

@jnewland was doing more work on this, and got an error like:

TypeError: Object Wed Apr 10 2013 19:07:24 GMT-0400 (EDT) has no method 'addHours'
at withCurrentOncall (/Users/technicalpickles/src/hubot/hubot-scripts/src/scripts/pagerduty.coffee:225:19)
Code is:

oneHour = now.addHours(1).toISOString()
Googling points at datejs. Does that sound right? Need to get that documented. I'm also considering using momentjs instead.


Reply to this email directly or view it on GitHub.

Reply to this email directly or view it on GitHub.

@jnewland
Copy link
Contributor Author

Sounds legit.

On Apr 10, 2013, at 7:44 PM, Josh Nichols [email protected] wrote:

I think I like the idea of moment, rather than datejs, because it doesn't modify the Date prototype. Actually have a version working with moment already.

On Apr 10, 2013, at 7:37 PM, Jesse Newland [email protected] wrote:

Yeah, likely. Would like to avoid any external deps if possible. I'll see what I can do here.

On Apr 10, 2013, at 7:12 PM, Josh Nichols [email protected] wrote:

@jnewland was doing more work on this, and got an error like:

TypeError: Object Wed Apr 10 2013 19:07:24 GMT-0400 (EDT) has no method 'addHours'
at withCurrentOncall (/Users/technicalpickles/src/hubot/hubot-scripts/src/scripts/pagerduty.coffee:225:19)
Code is:

oneHour = now.addHours(1).toISOString()
Googling points at datejs. Does that sound right? Need to get that documented. I'm also considering using momentjs instead.


Reply to this email directly or view it on GitHub.

Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub.

@technicalpickles
Copy link
Contributor

Yep yep.

Right now, working on going from a message to the pagerduty user, without assuming that usernames are identical. Emails is probably a safer assumption. For campfire, there's like msg.message.user.email_address, so we can use that. It's not always going to be the same, especially with 37signal logins, so will still want the ability to override.

To be continue?

On Apr 10, 2013, at 7:45 PM, Jesse Newland [email protected] wrote:

Sounds legit.

On Apr 10, 2013, at 7:44 PM, Josh Nichols [email protected] wrote:

I think I like the idea of moment, rather than datejs, because it doesn't modify the Date prototype. Actually have a version working with moment already.

On Apr 10, 2013, at 7:37 PM, Jesse Newland [email protected] wrote:

Yeah, likely. Would like to avoid any external deps if possible. I'll see what I can do here.

On Apr 10, 2013, at 7:12 PM, Josh Nichols [email protected] wrote:

@jnewland was doing more work on this, and got an error like:

TypeError: Object Wed Apr 10 2013 19:07:24 GMT-0400 (EDT) has no method 'addHours'
at withCurrentOncall (/Users/technicalpickles/src/hubot/hubot-scripts/src/scripts/pagerduty.coffee:225:19)
Code is:

oneHour = now.addHours(1).toISOString()
Googling points at datejs. Does that sound right? Need to get that documented. I'm also considering using momentjs instead.


Reply to this email directly or view it on GitHub.

Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub.

Reply to this email directly or view it on GitHub.

@technicalpickles
Copy link
Contributor

@martinisoft I just looked over play.coffee, and don't see anywhere where you introduce yourself to play, or at least it's not using the brain.

Checking for other scripts that do something similar.

@martinisoft
Copy link

@technicalpickles its part of the setup, if you look in this area of play.coffee you'll see the reference to githubLogin. Which comes from github-credentials.coffee

@technicalpickles
Copy link
Contributor

@martinisoft actually found github-credentials with some clever grepping. Should have something soon...

* use moment instead of datejs for time manipulation (ie adding
  hours/minutes)
* for `pager me N`, try to use the person who's said it email, instead
  of their name to find a PagerDuty user
* add command to remember your PagerDuty email address
* use moment's .calendar() to display nicer time when coverage is
* `pager me` will also say what it thinks your PagerDuty email address
  is
@technicalpickles
Copy link
Contributor

Changes pushed, for anyone wanting to try them!

Only things I can think of to consider fixing/updating:

  • moment('something').calendar() doesn't include timezones, which can be confusing for a distributed team
  • process.env.HUBOT_PAGERDUTY_SCHEDULE_ID needs to be checked if it's defined, because API calls will fail without it

@technicalpickles
Copy link
Contributor

I renamed pager me page to pager me trigger because I thought it was a little less confusing, and also matches the PagerDuty language. And I fixed the error checking of HUBOT_PAGERDUTY_SCHEDULE_ID.

The only question is that moment('something').calendar(). It returns like:

Rejoice, Blackhole! Josh Nichols has the pager from Today at 11:41 PM until Today at 11:42 PM

No timezones. I'm guessing it's the TZ of where hubot is running.

@tombell
Copy link
Contributor

tombell commented Apr 11, 2013

Welcome to dates in JS :P, you can UTC it like moment(blah).utc().calendar().

@technicalpickles
Copy link
Contributor

It's more a display problem. The timezone we get back is in the right timezone, but calendar() doesn't show it.

On Apr 11, 2013, at 3:58 AM, Tom Bell [email protected] wrote:

Welcome to dates in JS :P, you can UTC it like moment(blah).utc().calendar().


Reply to this email directly or view it on GitHub.

@tombell
Copy link
Contributor

tombell commented Apr 11, 2013

Use .format() instead of .calendar()

@technicalpickles
Copy link
Contributor

I had contacted pagerduty about adding support for creating notes at some point, and they recently added it, so added support for that here: hubot pager note 123345 wow this is such a note.

I also changed the hubot pager me 1 to use format instead of calendar. Moment used to have support for nice conversions to like EST and whanot, but it's been deprecated moment/moment#162 . For simplicity, leaving it with the default format.

At this point, I think it's 'ready', but like to have some other folks test it on in their hubots first. Particularly @jnewland, so he can use this script directly via hubot-scripts when it's merged.

This let's us use request_id in places, so when you look at PagerDuty,
it reports which user ack/resolved, instead of the logged in user.

As part of this, needed to rename HUBOT_PAGERDUTY_APIKEY to
HUBOT_PAGERDUTY_SERVICE_API_KEY.
@technicalpickles
Copy link
Contributor

Annnnd, one last change hopefully. I switched to using token authentication. This let's us use requester_id in some places, which means that when you look at incidents on the website, it shows ack/resolve/notes as being from the person who said it in chat, rather than the API user.

@jnewland
Copy link
Contributor Author

I'll test that out today.

@ches
Copy link

ches commented Apr 12, 2013

Man this is badass.

@jnewland
Copy link
Contributor Author

This has been out for a few hours and gotten good use in the GitHub Ops room. 👍 from me. Thanks for the cleanup @technicalpickles!

@tombell
Copy link
Contributor

tombell commented Apr 12, 2013

:squirrel:

technicalpickles added a commit that referenced this pull request Apr 12, 2013
Open source @github's Hubot PagerDuty integration
@technicalpickles technicalpickles merged commit 387413c into github:master Apr 12, 2013
@technicalpickles
Copy link
Contributor

🚨 👑 💥 ✨

@technicalpickles
Copy link
Contributor

Released hubot-scripts 2.4.3 with this included.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants