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

#!/bin/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"* ]]
then
(
echo "Subject: Extension is down - 200 Main line."
printf 'System is down...200 main line'
) | /usr/sbin/sendmail ${email}
fi

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.

#!/bin/bash

LOG_FILE=ā€œ/var/log/asterisk/fullā€
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ā€
fi
done

1 Like

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