Monitor line usage

I only have 8 analog lines connected to a Sangoma card on my Trixbox CE based system.

I would like to receive an email alert when I am using 6 of the 8 lines. Could anyone give me some pointers as to where I can easily access this information to make a script, or if there are any FreePBX modules or anything of the sort to make it easier for me to implement?

Thanks for your time,
Brad

I think the easiest way will be to make a bash script that executes ‘asterisk -rx “core show channels”’ and then grep for your Sangoma DAHDI device.

More complicated solution will be using Asterisk Manager Interface (AMI) or AGI scripts to log the current calls in MySQL and so on…

created a script and it seems to do the trick. if there are more than 5 Zap/ channels open it send me an email:

ADMIN=email1@test.com
ADMIN2=email2@test.com

CALLCOUNT=asterisk -rx "core show channels" | grep -c Zap/
if [ $CALLCOUNT -gt 5 ]; then
echo “Active Calls: $CALLCOUNT” |
mail -s “Active Calls: $CALLCOUNT” $ADMIN -c $ADMIN2
fi

thanks shmaize

Just a suggestion.

I’ve never used a sangoima card, but I assume you can do this

Create two groups of lines. one with 5 of the lines and another group with the remaining three.

in your dial plan for your outbound trunk, dial group 1 if that fails, system() an email script and dial through group 2. Your email script could also include a count on the active channels.

for example

[code][outbound-context]

; Call any number longer than 4 digits via the Dahdi trunk
exten => _XXXXX.,1,NoOp(External Call)
; Try to call on group 1 (first 5)
exten => _XXXXX.,n,Dial(DAHDI/g1/${EXTEN})
; If we are here, then the trunk is full
; Run our script and fork it off the current process so we dont have to wait around with a &
exten => _XXXXX.,n,System(/usr/local/emailsomethingclever.sh&)
; And place the call out on our remaining lines
exten => _XXXXX.,n,Dial(DAHDI/g2/${EXTEN})
[/code]

You can also use it on IP trunks using call-limit=x in sip.conf

[sip-trunk-1]
type=peer
username=mysipuid
password=donttell!!!!
host=sip.mysipprovider.org
call-limit=5
; other relevant stuff

[sip-trunk-2]
type=peer
username=mysipuid
password=donttell!!!!
host=sip.mysipprovider.org
call-limit=3
; other relevant stuff

and then call out in the same manner

[outbound-context]
; Call any number longer than 4 digits via the SIP trunk
exten => _XXXXX.,1,NoOp(External Call)
; Try to call on group 1 (first 5)
exten => _XXXXX.,n,Dial(SIP/sip-trunk-1/${EXTEN})
; If we are here, then the trunk is full
; Run our script and fork it off the current process so we dont have to wait around with a &
exten => _XXXXX.,n,System(/usr/local/emailsomethingclever.sh&)
; And place the call out on our remaining lines
exten => _XXXXX.,n,Dial(SIP/sip-trunk-2/${EXTEN})

Done from within the dial plan, you wouldnt need to run the script from every call

Hope this helps
Cheers
Chris