I want to get reporting of voip peers on daily basis and set an alert if any peer goes down

my network is not a good network and sometimes phones got un-registered and I want to pull an active peer list of today and use it as the benchmark to compare a daily active peer list which will let me know if any peers are removed due to any issues so that our operations team proactively react to that and fix the issues.

waiting for some good suggestions from the experts.

I’m far from an expert, but if it were me wanting to complete such a task, I’d write a perl script to do this and put it in cron to run whenever you want it to. (If you design it correctly, you could run it every few minutes so you’d get more immediate notifications of peers that go offline.) Assuming these are SIP peers, this command should pull a list of all peers:

asterisk -rx “sip show peers”

Then it’s a matter of collecting the output in your perl script, comparing it to what phones should be online, and notify yourself if any are not online.

grep -ir registered  /var/log/asterisk/full*

should get you started

1 Like

I put the following in a file and run it in a cron */3 * * * * /usr/200.sh

email="[email protected]"
/usr/sbin/asterisk -x 'pjsip show endpoint 200' | grep -i Unavailable > /tmp/200status1.txt
A=`comm -23 /tmp/200status1.txt /tmp/200status2.txt`
cp /tmp/200status1.txt /tmp/200status2.txt
if [[ "$A" == *"Unavailable"* ]]
echo "Subject: Extension is down - 200 Main line."
printf 'System is down...200 main line'
) | /usr/sbin/sendmail ${email}

My Extensions are sip based.

yes they are sip peers.

any guide related to the script as there are lot of unspecified or unknown sip peers showing in my case.

Actually this is to use a proactive approach.

for proactive, tail -f the /var/log/asterisk/full for events that match a regex of ‘registered’ , matches can then trigger anything you want

1 Like

yes but this will trigger the event when extension got Registered chan_sip.c: – Registered SIP ‘389’

what about the extensions which got unregistered and goes down.

grep -E -i "unreachable|reachable|lagged" /var/log/asterisk/full

or you can tail -f and pipe to the grep command

1 Like

Minimalist approach

tail -F /var/log/messages| while :; do read LINE;[[ $LINE =~ eachable ]] && mail -s $LINE [email protected];done

‘eachable’ matches both ‘Reachable’ and ‘Unreachable’,

1 Like

I write this code.


EMAIL="[email protected]"

tail -n0 -F “$LOG_FILE” |
while read -r line; do
if [[ $line =~ “Registered SIP” || $line =~ “Reachable” || $line =~ “UNREACHABLE!” || $line =~ “Lagged” ]]; then
echo “Log event: $line” | mail -s “Asterisk Log Event” “$EMAIL”

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.