image source: www.iconarchive.com
Hi all, hope 2016 has been good to you so far ..
Here’s a little script that I did to list out and do any kinds of actions to calls (right now, echo output and email with a kill switch to kill offending calls) that exceed certain number of seconds and gathers all (or just one) of the calls and output in pretty Nagios output or sends you an email. It will also show some important information about that CHANNEL (call) so you can take necessary action.
Purpose of this script is to perhaps check on your PBX call action, ensure there aren’t dead channels running around, track billing usage (you can program it to check against a pre-set DB against each channel to calculate rates vs balance in realtime) and many other things you can imagine.
You can download it here www.orencloud.com/public/checkduration.sh
It supports Nagios return codes (NAGIOSMODE=YES) or sends email otherwise
- Set warning vs critical values
- Runs in native Asterisk CLI, so it should be tech independent and fast as it uses pure channel variables
- Put up in cron to check periodically
- Something like this */2 * * * * /usr/local/bin/checkdur.sh -w 1800 -c 2400 2>&1 | /usr/bin/logger -i -t ASTIOSALERTS
- This above example will check every 2 minutes and output the result to /var/log/syslog (or similar) the result of the script in the tag ASTIOSALERT
- Place as Nagios script to be executed by Nagios
- Tested on CentOS/Debian6/7, Asterisk 11 and FreePBX 2.11 , FreePBX Distro
- I believe it should work on almost all systems and variations
- If you do have an improvement, do suggest.
- There’s a kill channel switch, –k 1 where it will kill the “critical” time exceeding channel.
- The output may produce duplicates as a full leg call can contain 2 or more channels. Look for the the first part of the UNIQUEID to identify dupes.
- This script may not run in some OS-es or environment so test it out first before going into production
Place the script anywhere and ensure its executable, here’s how..
# cd /usr/local/bin
#chmod +x /usr/local/bin/checkduration.sh
Be sure to change bold highlighted values, edit the script
# nano /usr/local/bin/checkduration.sh
EMAILSUBJECT="DURATION OF CALLS ALERT"
MYAST=/usr/sbin/asterisk #change this if its not there.
Test like this, also be sure you can send emails already using “mail”. Setup your local relay, etc..
#/usr/local/bin/checkduration.sh -w 60 -c 90 [-k 1]
Where, 60,90 are seconds for alert warning and critical respectively. Make some test calls and check the script output in action. –k 1 switch kills that channel when time exceeds “critical” only.
Output looks like this on a typical Asterisk system