Is there anyway to write a bash that can notify me via email when my phone extensions are unreachable?
Output from /var/log/asterisk/full
[Nov 15 13:25:16] NOTICE[7884] chan_sip.c: Peer '7778' is now UNREACHABLE! Last qualify: 17
[Nov 15 13:25:17] NOTICE[7884] chan_sip.c: Peer '7169' is now UNREACHABLE! Last qualify: 17
[Nov 15 13:25:17] NOTICE[7884] chan_sip.c: Peer '7176' is now UNREACHABLE! Last qualify: 18
[Nov 15 13:25:18] NOTICE[7884] chan_sip.c: Peer '7771' is now UNREACHABLE! Last qualify: 14
[Nov 15 13:25:18] NOTICE[7884] chan_sip.c: Peer '7606' is now UNREACHABLE! Last qualify: 17
[Nov 15 13:25:18] NOTICE[7884] chan_sip.c: Peer '7773' is now UNREACHABLE! Last qualify: 14
[Nov 15 13:25:19] NOTICE[7884] chan_sip.c: Peer '7125' is now UNREACHABLE! Last qualify: 15
[Nov 15 13:25:20] NOTICE[7884] chan_sip.c: Peer '7772' is now UNREACHABLE! Last qualify: 15
[Nov 15 13:25:22] NOTICE[7884] chan_sip.c: Peer '7605' is now UNREACHABLE! Last qualify: 16
[Nov 15 13:25:22] NOTICE[7884] chan_sip.c: Peer '7183' is now UNREACHABLE! Last qualify: 18
[Nov 15 13:25:29] NOTICE[7884] chan_sip.c: Peer '7601' is now UNREACHABLE! Last qualify: 24
[Nov 15 13:25:30] NOTICE[7884] chan_sip.c: Peer '7776' is now UNREACHABLE! Last qualify: 47
[Nov 15 13:25:32] NOTICE[7884] chan_sip.c: Peer '7604' is now UNREACHABLE! Last qualify: 25
[Nov 15 13:25:34] NOTICE[7884] chan_sip.c: Peer '7774' is now UNREACHABLE! Last qualify: 46
[Nov 15 13:25:38] NOTICE[7884] chan_sip.c: Peer '7770' is now UNREACHABLE! Last qualify: 41
[Nov 15 13:25:41] NOTICE[7884] chan_sip.c: Peer '7775' is now UNREACHABLE! Last qualify: 42
As you can see, I don't know the phones are down until people complain they can't make a phone call.
What I have done so far:
#!/bin/bash
email="[email protected]"
offlineExtensions=$(cat /var/log/asterisk/full | grep -i unreachable)
if [ "$offlineExtensions" ]
then
printf 'Extensions that are currently offline...\n''\n'"$offlineExtensions" | mail -s 'Extensions OFFLINE' "$email"
fi
I would like to use sed and awk, but I'm brand new to bash scripting.
It would be nice if this script is constantly checking the Asterisk log file to find out if an extension is unreachable.