SIP Registration Alert

Hi to all,

I wonder if there is a way to make Freepbx to alert me when my SIP or Trunk is not registered, I have found that when service provider do some sort of maintenance on the VOIP Line my freepbx does not re-register then I have to login to my Freepbx PC and refresh it for the registration to happen.

It would really help if there is a way to make the Freepbx to sent me a mail to notify me that there is no SIP or Trunk Registered.

FreePBX Ver
Asterisk Ver.

Thank you


Just put the script in the “monitor trunk” field in the trunk.

You can run any shell command from that location.

Hi, Thank you for the info, Now I have done so and added a alert but now I only receive the alert when I try to make a call and the sip or trunk is not registered, can any one help me with a script that I can use to basically check the connection say every 10,20 or 30 minutes to make sure that the sip or trunk is registered, This will help me to eliminate problems quicker.

Thank you

Hi try this below

  1. Change snooze for recheck times in secs
  2. Change “trunkname” or “anothertrunkname” to your actual trunk name [ if you don’t know, run "asterisk -rx “sip show peers” and see the trunkname there put i
  3. To run this in the background, run the script like this trunkname > /dev/null 2>&1 & anothertrunkname > /dev/null 2>&1 &

####script start####

asteriskbin=which asterisk
while [[ “$run” == “true” ]]; do
checkifok=$asteriskbin -rx "sip show peer $thistrunk" | grep Status | grep -wc OK
if [[ $checkifok == 0 ]]; then
echo "Do something here like send email"
echo "Trunk OK, don’t have to do anything"
sleep $snooze

####script end####

But I’m not that familiar with FreePBX, I have started this server about 4 months back, please be more specific.

asteriskbin='which name` ? what should be in here is it a directory of some sort.

thistrunk= should this be my trunk name

Can I run this scrip in the monitor field of FPBX as I have done with alert.agi or does it only run from command line.

Thank you fore your reply.

The line asteriskbin='which name` uses the command “which” to locate where the asterisk executable file is located based on lookin in the PATH variable. Do a “man which” at a shell prompt and it should return something like /usr/sbin/asterisk

the line thistrunk=$1 takes the command line argument in variable $1 and places it in the variable named thistrunk.

But I can’t see that it works, I even have simulated a trunk failure but still nothing, Have a look at this picture this is what I get if i run this script is this right or not, and sorry I don’t know how to do screen captures with centos 5.5.

dev/null 2>&1 &

will sent all output to the bit bucket. remove that bit and try over. Control C to stop it running

I have setup a script and I’m running it via a cron job ever 30min, the only thing it does is it ping’s my host and when it returns with a 0 it sent me a e-mail, I think this will work much better then the actual trunk alert, But I will test it for a while and see what it does maybe I’ll play around with different scripts until I’m familiar with this.

Thanks to all that have helped me to get this far, until later.

Pings are meaningless. ICMP is the first traffic to be discarded when interfaces get busy. The actual carrier proxy is probably not even the host responding to the ping. You need to test at the application layer.

If you do a asterisk -rx ‘sip show peer xxx’ you can get the peer qualify status. That is much better as it is based on a SIP transaction.

Thanks for that info, my problem is that if I use the scrip that you stated on top I get all sorts of funny stuff that I don’t understand, look at my post with the picture, I also tried to run the command “bash” and I have edited the scrip to do a certain trunk thistrunk=Screamer then I get this message
" Asterisk already running on /var/run/asterisk/asterisk.ctl. Use ‘asterisk -r’ to connect. line 15: -rx: command not found"

I’m not sure what to do else, I have tried to take out the bin from 'asteriskbin -rx but it’s the same problem, I’m really not sure in where to look anymore.

Hope that there is something I can do to get this running if this is going to be the better way.


Your picture shows nothing apart from that you are sending all the output of your script to a place where no-one can read i., ( I told you that already.) > /dev/null 2>&1, and running the script in the background &, for now just remove them

As to “The funny stuff”, while as yet unintelligible to you, is likely to be helpful to all those trying to help you.

I suggest you try the whole thing over without doing your own Improvizations , be aware of the difference between a back-tic ` and a single quote ’ this time.

First I suggest though that you get a decent bash tutorial and learn how to cut (ctrl-c) and paste (ctrl-v) and how to select the text you want to do that with using your mouse. It will save you taking pictures and save you time mistyping scripts.

I have to mention that for the ease of doing this I’m using WEBMIN with the file manager this way I can copy paste using my Windows PC, I only run the command strait from the Centos PC server.

I will try doing it again, I will also get my self a bash scrip manual for learning this.

I will do this tonight and see if I get this running.


I don’t think webmin makes it easier. In fact it is the source of your issues. Cutting and pasting is easy in putty. Use a native editor like vi or nano.

I have tried this script again, I made the executable with chmod +x and copied it to /usr/bin and run it only as " Screamer " and still receive this message " Asterisk already running on /var/run/asterisk/asterisk.ctl. Use asterisk -r to connect. line 15: -rx: command not found "

I don’t know what to do, I have copied and past the script over to the file I didn’t retype it.

This is line 15 (copied and pasted)
checkifok=$asteriskbin -rx "sip show peer $thistrunk" | grep Status | grep -wc OK

If there is anything ells I can try I will.


" Asterisk already running on /var/run/asterisk/asterisk.ctl. Use asterisk -r to connect. line 15: -rx: command not found "

says that you are erroring on

checkifok=$asteriskbin -rx "sip show peer $thistrunk" | grep Status | grep -wc OK

$asteriskbin should resolve to


and $thistrunk to $1 (your calling argument) Screamer

checkforit i set to the return of so the line sent to bash:-

/usr/sbin/asterisk -rx “sip show peer Screamer” | grep Status | grep -wc OK.

from bash yourself try without prejuduice

/usr/sbin/asterisk -rx “sip show peer Screamer”


/usr/sbin/asterisk -rx “sip show peer Screamer” | grep Status


/usr/sbin/asterisk -rx “sip show peer Screamer” | grep Status | grep -wc OK

hopefully you get the idea ( the script does works but personally it is a little inelegant for my taste, )

When you get a script working that only says something when there is a problem, then I suggest you make a cron job out of it, the granularity can be as little as a minute. By default any output will be automatically emailed to the default cron job owner’s email, no output, no email. Be aware that cron jobs run under /bin/sh, so you will need fully qualified program names and file names as /bin/sh has a far more restricted “path” than /bin/bash.

(see I told you you needed a bash tutorial :wink: )

so the cron job could be a very simple “one-liner”:-

/usr/sbin/rasterisk -x “sip show peers”|/bin/grep -r “^[a-z,A-Z]”|/bin/grep UNREACHABLE

which will only enail you if the peer name starts with a letter (your extensions won’t, make sure your trunks do), they are expected to be Reachable (OK) but they are UNREACHABLE

It will work for all your trunks at the same time, so if they all disapper, then it is probably your network.

Deconstruct by going left to right stopping before each “pipe” | character until you “get it”

You can synthesize it’s behavior with

/usr/sbin/rasterisk -x “sip show peers”|/bin/grep -r “^[a-z,A-Z]”|/bin/grep UNREACHABLE|mail [email protected]

as you play with it . .

one of the previous posts…

/usr/sbin/rasterisk -rx “sip show Registry” | grep Status | grep -wc Registered But no go…

I might have put -rx but I have tried it with -x only as well, and it returns only a 0 and that means that it doesn’t see it as registered.

If I use only /usr/sbin/rasterisk -rx “sip show Registry” | grep Status , it returns me to the prompt with no status to show.

I have done this in the steps you told me to,

/usr/sbin/asterisk -rx “sip show peer Screamer”


/usr/sbin/asterisk -rx “sip show peer Screamer” | grep Status


/usr/sbin/asterisk -rx “sip show peer Screamer” | grep Status | grep -wc OK

But now when I do the last command I get a 0 , so I have check my status and it shows “Unmonitored” so that means I cant use the “OK” it will keep on retuning a 0 and not a 1 if I’m right, so I won’t able to do this command.

are there any way I can make this status show me OK and not like the bottom status of my trunks,


If you “register” the trunk or “qualify” the peer, it will show otherwise, try it.

Stangely though it might sound it will be hard to “nonitor” a trunk that you have set up to not be “monitored”, This is where hopefully the brain will kick in :slight_smile:

try instead:-

rasterisk -x ‘sip show registry’

notice that you have both extensions 100 and 199 registered at and both on port 5061, this will cause more brain pain in the near future.

Darn man you are good, I have just set qualify to yes… dumb me… thanks now I can go ahead and test the scripts again…