Setting up a phone number to activate a pagerduty alert Version 1

Posted on Thursday, October 9, 2014





This guide will walk through setting up a Twilio phone number which when called with send an email to a pagerduty email service.  This effectively gives you an emergency call number!  I call it version 1, because I feel there are far better ways to do this, but in the meantime this works.








This guide assumes you have a Twilio and pagerduty account set up. 
If you do not, I have a few guides written up

Twilio

pagerduty



pagerduty email service


 



After you login to pagerduty Click on Services









Click + Add New Service






Give your service a name.






Select an escalation policy.




Select Integrate via email.








This will create an "Integration Email".  You can change it.  For this example mine is set to  patrick-test-alarm@10x13.pagerduty.com






Click Add Service








This service will now be activated.  Send an email to patrick-test-alarm@10x13.pagerduty.com and it will activate. 





A quick fix


If you look closely at the alert you will see this.





This means a new incident will be triggered only for emails with different subject lines in them.  I can see problems with that so I am going to change it.







Click the configure button and select Edit









Select "Open a new incident only if an open incident does not already exists"


This will allow all alerts in, but if you are currently working the issue it will not alert you again and again.







I changed these settings as well.   I un-checkbox both the Incident Ack Timeout and Incident Auto-Resolution. 

I make a point of this because I think its an odd default behavior.  I would think pagerduty's default would be to have both these unchecked.  








Click Save Changes





Test it out


Send an email to active the alert.







Here is an audio recording 




The subject of the email will be read back to you but not the body.

If you need to read the body you can open the incident in pagerduty



And click on View Message






A pop up will show the email that was received, including the body.



Twilio and Twimlets


For a quick round up:

I have service in pagerduty that triggers when I send an email to patrick-test-alarm@10x13.pagerduty.com .  Now I just need to set up a Twilio number that accepts a call and creates an email that is sent to this address.


I will do this with a Simple Menu Twimlet.





Login







 Select Simple Menu from the pull down and click Create New Twimlet







Enter a message you want Twilio to read back to your caller.

In my example I used the following


This is patrick's emergency system, if this is not an emergency please hang up, otherwise enter key code

   






Enter menu option key code.  This is really meant to be a menu, press 1 for this, press 2 for that… etc.  But I can use it for another purpose.  In this case you have to press 1234, the key code, before it will do the next thing.  If an incorrect key code is entered nothing will happen.

Click on Generate a Twimlet






From the pop up select voicemail








Click Continue







Enter the pagerduty email and a message and click OK.


Here is my message



Please leave a message describing the problem, when you are done recording your message press any key



Warning:  I have had mixed results with this, at one point Twilio would not email pagerduty for some reason, so I had to route it through another email.  But it seems to be working since then.




 Click Save URL









Give this twimlet a name and click Save.  This twimlet is associated with your twimlet account.





Click OK







Click My Twimlets in the upper right








Click Show Full URLs








Copy this URL









Click on Account






Open the Numbers Tab







Click the number you want to use as your emergency number







Enter the URL in the Request URL and click Save.


Test it!



Call the number and test it.

Here is a recording of my call.








Opening the email in pagerduty I get a link to the call Twilio recorded.

Here is the Twilio recording I got back.





Here is the actual call I got back from pagerduty.






One addition fix


For the Twilio number I have a key code the user has to enter to trigger the email.  In my mind that prevents some random person calling your number by accident or on purpose and triggering your pagerduty alert.  But, the email is still an issue in my mind.  I am trying to figure out how to use Twilio with parse cloud code to solve this problem; bypassing the email altogether and calling a pagerduty restful service.  Until I have that done there is one thing I can do to try and prevent someone from sending a random email to patrick-test-alarm@10x13.pagerduty.com (And by the time I post this the email service will be removed)


Regex filters!


Pagerduty allows you to set up regex filters on email services.  You can filter on subject, body, and from address.







Looking real quick at the email I received from Twilio it was sent by voicemail@twimlets.com.

My idea is to only let emails from this address through.







To set the regex first click on edit from the config pull down for your service.








From Email Filters select "Accept email only if it matches ALL of the rules below"







in the from address select "matches the regex"






Enter the twimlets voicemail address






Click Save Changes


If you want to do some more complex regex I found this site  http://regexpal.com/ [1] which may be a good place to test you regex.



Test it!



I tried to send an email from my gmail account to patrick-test-alarm@10x13.pagerduty.com … and no incident was triggered, also no return email, rejecting the incident (that would be a handy thing to have).


But if I call into my emergency Twilio phone number… it works just fine.




Conclusion


You now have the tools you need to create a simple emergency number.  To me, it does not feel like a long term solution … I don't like the idea of relying on email.  However I think it’s a great place to start!



Future plans



So that I can
·         Call pagerduty via its restful API
·         Call back the person who called in to tell them who has acknowledged the incident and when it has been resolved.






References

[1]        Regex pal
                        http://regexpal.com/

                Accessed 09/2014 





This post is a part of and epic, the pagerduty and twilio epic.

Epic Goal:   Set up a phone number, via twillio, that when called will set off a pagerduty event.

No comments:

Post a Comment