Sydney Senior SRE/Sysadmin/Something.

Asterisk – Email notifications

· by Robert Mibus · Read in about 2 min · (245 Words)
asterisk sysadmin voip

One of the things I like about Asterisk, is its ability to send email notifications to me if certain things happen. There’s no built-in ability to send emails by itself, so we’ll use its integration with the underlying server to do it.

Let’s start by sending me an email if someone uses my VoIP line to make an international call. In Australia, all international calls are prefixed with “0011″…

[regular_outbound]
; Email me for international calls
exten => _0011.,1,System(mail -s "International Call to ${EXTEN}" example@mibus.org < /home/mibus/Documents/international-call.msg)
exten => _0011.,n,Dial(SIP/${EXTEN}@nodephone,,)
; Handle other calls out
exten => _XX.,1,Dial(SIP/${EXTEN}@nodephone,,)
;

Note that the subject is InternationalCall, the destination email address is example@mibus.org, and the body of the email comes from a file I’ve already saved to /home/mibus/Documents/international-call.msg. From now on, I’ll know whenever an expensive international call is made.

A rarely-used feature of extensions.conf is the built-in h extension. Let’s use that (inside whatever context rings your real internal phone) to let us know by email when we’ve missed a call for any reason. For example, if my phone is rung on extension 99…

exten => 99,1,NoOp(Inbound)
exten => 99,n,Dial(SIP/myphone,30,)
exten => 99,n,Hangup()

exten => h,1,GotoIf($["${DIALSTATUS}" = "ANSWER"]?done)
exten => h,n,System(mail -s "Missed Call From ${CALLERID(num)}" example@mibus.org < /home/mibus/Documents/missed-call.msg)
exten => h,n(done),NoOp()
;

Note that I’m specifically using only the number component of the Caller-ID – if your VSP supports sending textual Caller-ID alongside it, it means that random foreign callers can alter your System() call!