Skip to main content

Today we were asked to perform an automation for a customer of ours who is operating its own NOC.

The request was that when a critical issue is raised either from their NMS or a critical ticket is opened by one of their customers, besides the email notification that the agents receive they need to also receive a voice call from their PBX playing a pre-defined message.

The NMS & Ticketing system is copying those critical alerts to a second mailbox (ie alerts@domain.com)

We then configured Asterisk to retrieve messages from this POP account (every minute) using fetchmail, parse the exit code of fetchmail and if a new mail is present initiate a call from Asterisk CLI.

1. Installed fetchmail on asterisk

2. Added .fetchmailrc on root account. Note that is alarms here is actually the local mailbox on which the fetchmail will deliver the messages, this is not important for the automation process to work but we are keeping them for logging purposes.

[root@asterisk ~]# more .fetchmailrc 

# set username
set postmaster "alarms"
# set logging
set logfile fetchmail.log

poll pop.server.here with proto POP3
   user 'alarms@domain.com' there with password 'password_here' is alarms here options ssl
[root@asterisk ~]# 

3. Created /bin/automate.sh to call from Asterisk when conditions are met:

[root@asterisk ~]# more /bin/fetchauto.sh 
#!/bin/bash
fetchmail -s >> /root/fetchmail.log 2>>/root/fetchmail.err
if [ "$?" =  "0" ] 
then 
/usr/sbin/asterisk -rx "originate SIP/TrunkName/NumberToBeDialled application Playback zombies"
exit 1
fi
[root@asterisk ~]# 

4. Created cron job to run every minute:

[root@asterisk ~]# more /var/spool/cron/root 
* * * * * /bin/fetchauto.sh
[root@asterisk ~]#