911 Email Alert

We are trying to setup a system where our freepbx system will notify us via email if somebody dials 911. I found an article where somebody said they got it working.

I added the following line to our extensions_custom.conf file

exten => 911,1,System(echo “911 call from ${CALLERID(NUM)} - ${CALLERID(NAME)} at ${STRFTIME(%C%m%d%y%H%M)}” | mail -s “911 Alert at ${CALLERID(NUM)}” [email protected])

We had the lines below already in the system.

exten => 911,1,Set(CHIAMANTE=${CALLERID(num)})
exten => 911,n,Set(ROCK=${CALLERID(name)})
exten => 911,n,Set(KNOCK=${CDR(start)})
exten => 911,n,DeadAGI(blah.php)
exten => 911,n,Dial(SIP/99922${EXTEN}@cisco-iad2)
exten => 911,n,Hangup

I am not very familiar with the extensions_custom.conf file so I am not sure if this will do the trick.

Thank You

Did this work? I would like to have the same functionality.

1 Like

Contexts are little programs that run in the case an event occurs (hence the name). You can only do thing that are within the context of what you are doing, Also, your context is “step” oriented. The context processes the steps in order starting with ‘1’. The next step can be ‘2’ or ‘n’ (for next). So, if you want to add your custom line to the context, you need to make sure that you put it somewhere it will get executed. Once you’ve established a ‘step 1’ for a context and extension, you can’t have another one. We use this trick to our advantage in the “freepbx-override-extensions.conf” since it gets read first.

So, to add this functionality, you have to either add a new context “[mail-on-911]” and make sure it gets included in the beginning of your current context: “include => mail-on-911” or modify the existing “911” code to add your program line into the existing context.

Be warned that some of the files (like extensions.conf) are managed by FreePBX and will be overwritten when you apply changes.

I thought the whole point of extensions_custom.conf was to be able to add your own stuff. extensions and extensions_additional will be overwritten but not custom.

@bksales Yes. Some people that are new to FreePBX aren’t immediately aware of that. Also, there are lots of instructions on the Internet that tell people to edit the extensions.conf file and make changes, then find out that FreePBX has deleted their custom contexts.

I now need this functionality but don’t understand custom contexts. can someone explain a little more about what each line is doing and why its there?

this seems like something that could help a lot of people if it was explained a bit better so it could be modified to fit the needs of different people. I keep seeing this question asked and the answers are scenario specific.

basically, I am in the same boat. I need an email sent when someone dials 911.

I would also like to page people and let them listen to the 911 call as a safety measure so the front desk knows exactly what’s going on.

check with your provider - we use multiple providers and all allow us to set up email alerts when a 911 call is made.

One solution that WFM is to add

tail -F  /var/log/asterisk/full|while read i;do if [[ $i =~ /.*/911$ ]];then echo $i|mail -s WARNING [email protected] ;fi;done &

to your /etc/rc.local script it will fire off the email at the moment that call is attempted, and as E911 services try and “hold the line open” it should work even on a DAHDI call or waiting for the call to complete if relying on your VSP or the call to end.


PagePro provides you the feature to page a group of phones when a call is made out any route that you setup to be notified so your emergency route could be set to page a group of phones and let them listen and join the call and take it over.

(Updated to use system time so it will follow DST if used in your time zone)

we have put together our own context that seems to do the trick well. Thought I would share as it took a lot of testing. originally we used mail but there were some limitations. this works and the emails and texts are crazy fast.

in extensions_custom.conf add

include => emergency-notify to the end of the Includes section

then at the bottom add

exten => 911,1,Macro(user-callerid)
exten => 911,2,System(echo -e “Subject:911 Alert! \n\n 911 call from Extension ${CALLERID(NUM)} - ${CALLERID(NAME)} on $(date +”%a %b %d at %r")\n" | sendmail -r [email protected] -F “911” [email protected],[email protected] )

subject will be 911 Alert!
sender address will be [email protected]
sender name will be 911

you can add one of many addresses by separating them with commas. do not include any spaces and the whole context is 2 lines, make sure your editor doesn’t add returns.

If you want text messages just look up your carrier’s SMS gateway. example [email protected] sends a text message to number 555-123-1234.

depending on who you your trunk provider is, you may find they have an option to do this for you. the advantage of them doing it is that you know for certain the 911 call hit their switch. but of course your script offers probably more flexibility in the customizing the body of the message

We Use Vitelity and they do offer a notification service which we use as a backup but in this case the client is a large foundry with several large warehouses and lots of dangerous machines and 1700 degree metal flying around. when Vitelity sends an alert they only specify the server it came from and associated account(wich is great for us as a provider). what we needed is the location. so this script sends the extension and name of the extension to the reception desk and texts all managers so when the ambulance shows up at the reception desk they can point them to the location of the accident.

this would be a nice feature in freepbx. perhaps you should submit it as a feature request?

Has anyone done this recently, something I’d really like to be able to do but having trouble in the extensions_custom.conf.

This dial plan code works.
Just paste it into extensions_custom.conf and replace the email addresse(s) in there with yours.

    exten => s,1,ExecIf($["${OUTNUM}"="911"]?System(echo "Ext ${AMPUSER} - ${AMPUSERCIDNAME} just placed a 911 emergency call on ${STRFTIME(%C%m%d%y%H%M)}" | mailx -r "[email protected]" -s "911 Alert from ext ${AMPUSER} - ${AMPUSERCIDNAME}" [email protected]))
    exten => s,n,MacroExit()

That works great!

Now, how about if I wanted to sort it based on someones emergency caller-ID?


What do you mean by sort?
Different email recepient depending on the CallerID of the calling party?
Then something like below code, depending on what you want.
There are also plenty of threads here discussing this.

exten => s,1,GotoIf($["${AMPUSER}" = "1000" | "${AMPUSER}" = "1001"]?2:4) 
exten => s,2,ExecIf($["${OUTNUM}"="911"]?System(echo "Ext ${AMPUSER} - ${AMPUSERCIDNAME} just placed a 911 emergency call on ${STRFTIME(%C%m%d%y%H%M)}" | mailx -r "[email protected]" -s "911 Alert from ext ${AMPUSER} - ${AMPUSERCIDNAME}" [email protected] [email protected]))
exten => s,3,MacroExit()
exten => s,4,ExecIf($["${OUTNUM}"="911"]?System(echo "Ext ${AMPUSER} - ${AMPUSERCIDNAME} just placed a 911 emergency call on ${STRFTIME(%C%m%d%y%H%M)}" | mailx -r "[email protected]" -s "911 Alert from ext ${AMPUSER} - ${AMPUSERCIDNAME}" [email protected]))
exten => s,5,MacroExit()

Great that is exactly what I would like to do except using an ext emergency CID field.

I now know what needs written in, where can i find what to reference, instead of AMPUSER

We have a slightly more unique setup but this is what we used. We use “Customer-context” on each extension’s context as a sort of firewall so the extension loads that.

exten => 933,1,Macro(user-callerid)
exten => 933,2,System(echo -e “911 call from Extension (${FILTER(a-zA-Z0-9 _-,${CALLERID(NUM)})}) ${FILTER(a-zA-Z0-9 _-,${CALLERID(NAME)})} on $(date +”%a %b %d at %r")\n" | mail -s ‘911 Alert!’ -r [email protected] -b [email protected] [email protected])
exten => 933,3,Goto(from-internal,${EXTEN},1)

Made sure to incorporate the warning on the asterisk docs:

Warning https://wiki.asterisk.org/wiki/display/AST/Asterisk+15+Application_System
Do not use untrusted strings such as CALLERID(num) or CALLERID(name) as part of the command parameters. You risk a command injection attack executing arbitrary commands if the untrusted strings aren’t filtered to remove dangerous characters. See function FILTER() .