Notification when trunk is down

Hi Guys,
I`m looking for a solution to get a notification when the trunk is down and unregistered. Can you help me out ?
Using the latest Freepbx version and every now and then my trunk gets down en doesnt register again…
A reload helps, but I want to know when it happens.
Regards ,
Harry

There are 3 parts to this method:

  1. SMTP e-mail relay - info below.
  2. Script to check status of the trunk…‘sip show registry’ shows 0 for me when trunk is up so I use ‘sip show peer mytrunkname’. This may need confirmation. Info below.
  3. A cron entry to run the script at certain times…I don’t include that so you need to find out how elsewhere.

I got the e-mailing portion to work. However, my ISP doesn’t allow sendmail relay unless it uses an ID and password. My work-around was to use the Elaxtix GUI (I prefer Elastix bundled with FreePBX):
Email(tab) > Remote SMTP > ‘Remote SMTP Delivery’. I then entered my gmail login and left the rest at their defaults. Status must be ON and click Save when done.

Here’s the trunk status script based on tons of info at the following post. There are other suggestions in there as well like an AGI script that can be setup in the FreePBX trunk settings: http://fonality.com/trixbox/node/21166

#!/bin/bash

Test Trunk 1

trunk_status=asterisk -rx "sip show peer Test-Trunk-1" | awk 'NR==55, NR==55 {print $3}'

2 debug lines

#trunk_status=$3
#echo “–$trunk_status–”

if [ “$trunk_status” != “OK” ]; then

Use next line with real e-mail info instead

#echo “Error on Test Trunk 1” | mail blah_at_blah.blah -s "Error on Test Trunk 1"
echo "Error on Test Trunk 1"
else
echo "Test Trunk 1 is Registered"
fi

Please note repeated calls to asterisk -rx can make asterisk grumpy.
It is better to use the manager API than -rx if you can. I have a span watchdog that generally does this but it watches DAHDI not Asterisk. It can probably be adapted. I will look at it and post a gist tomorrow.

My watchdog for dahdi is a whole different beast that wasn’t really adaptable.

I threw this together:

Forgive me it is kinda ugly but should give you an idea of “how to” do it with the asterisk manager

Good to know about ‘asterisk -rx’. jfinstrom - Could you please post an example hello world or echo action statement? At this time I’m not at all familiar with Python but I’m looking forward to trying your script. Thanks, jay555