Swatch : Simple Log Watcher to monitor Asterisk PRI status
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).
1
# yum install swatch
- Create file daemon script
/etc/init.d/swatch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/sh
# Simple Log Watcher Program
case "$1" in
'start')
/usr/bin/swatch --daemon --config-file=/etc/swatch.conf --tail-file=/var/log/asterisk/full --pid-file=/var/run/swatch.pid
;;
'stop')
PID=`cat /var/run/swatch.pid`
kill $PID
;;
*)
echo "Usage: $0 { start | stop }"
;;
esac
exit 0
1
2
3
4
# 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
vi /etc/swatch.conf
1
2
3
4
5
watchfor /Span 1: D-channel is down!|Primary D-Channel on span 1 down/
# echo
write root
mail addresses=user1\@mydomain.net:user2\@mydomain.net, subject=PRI down. Trying to restart.
exec="/usr/bin/rstast.sh"
vi /usr/bin/rstast.sh
1
2
3
4
5
6
7
8
9
10
11
#!/bin/sh
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/rstast.sh
This post is licensed under CC BY 4.0 by the author.