This will monitor the asterisk log file and check for some pattern and restart the asterisk & dahdi service. ( can be used as a work around till you find the real problem).

  • Install swatch

# yum install swatch
  • Create file daemon script


# Simple Log Watcher Program

case "$1" in
 /usr/bin/swatch --daemon --config-file=/etc/swatch.conf --tail-file=/var/log/asterisk/full --pid-file=/var/run/
 PID=`cat /var/run/`
 kill $PID
 echo "Usage: $0 { start | stop }"
exit 0

  • Make it executable and enable autostart.

# sudo chmod 755 /etc/init.d/swatch
# sudo ln -s /etc/init.d/swatch /etc/rc2.d/S99swatch
# sudo ln -s /etc/init.d/swatch /etc/rc3.d/S99swatch
# sudo ln -s /etc/init.d/swatch /etc/rc5.d/S99swatch
  • Create swatch config and commands.

vi /etc/swatch.conf

watchfor /Span 1: D-channel is down!|Primary D-Channel on span 1 down/
# echo
 write root
 mail addresses=user1\\, subject=PRI down. Trying to restart.


  • Add commands in  script and make it executable.

vi /usr/bin/

sudo asterisk -rx "logger rotate"
sleep 3
sudo /etc/init.d/asterisk stop
sleep 3
sudo /etc/init.d/dahdi restart
sleep 3
sudo /etc/init.d/asterisk start
sleep 2

# chmod 755 /usr/bin/

One thought on “Swatch : Simple Log Watcher to monitor Asterisk PRI status

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s