PRTG Monitoring Script

Add Service Account

useradd -m prtg
passwd prtg

GRANT SQL Access to prtg User

psql -U postgres -d sbcedb
CREATE USER prtg WITH PASSWORD 'xxxxxxxxxxxxxxxx';
GRANT SELECT ON ALL TABLES IN SCHEMA public TO prtg;
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO prtg;
GRANT CONNECT ON DATABASE sbcedb to prtg;

Create Script on SBC Server

vi /sbin/check_sbc.sh

#!/bin/bash localnodeip=`ifconfig M2 |grep "inet "|sed -re 's/inet ([1].*) netmask.*/\1/g'` hainfo=`psql -d sbcedb -c "SELECT status FROM ha_info WHERE ha_ip = '$(echo $localnodeip)';"|sed -re '3! d'|sed 's/^.//'` if [ $1 = "sipstatus" ]; then if [[ $hainfo == "Primary" || -z $localnodeip ]]; then #echo "Is Primary" sipstatus=`psql -d sbcedb -c "select * from sip_server_status_info WHERE NOT hb_status = 'UP';"|tail -n +3|head -n -2` #echo $sipstatus if [[ -z "$sipstatus" ]]; then echo -e "<prtg>\n<result>" echo "<channel>SIP Endpoint Status</channel>" echo "<value>UP</value>" echo -e "</result>\n</prtg>" else echo -e "<prtg>" echo "<error>2</error>" echo "<text>`psql -d sbcedb -c "select ip_address,transport_type, port,hb_status from sip_server_status_info WHERE NOT hb_status = 'UP';"|tail -n +3|head -n -2`</text>" echo -e "</prtg>" fi else echo -e "<prtg>\n<result>" echo "<channel>Is not Primary SBC</channel>" echo "<value>UP</value>" echo -e "</result>\n</prtg>" fi elif [ $1 = "alarmstatus" ]; then alarms=`psql -d sbcedb -c "select * from alarms;"|tail -n +3|head -n -2` if [[ -z "$alarms" ]]; then echo -e "<prtg>\n<result>" echo "<channel>SBC Alarms</channel>" echo "<value>OK</value>" echo -e "</result>\n</prtg>" else echo -e "<prtg>" echo "<error>2</error>" echo -n "<text>" psql -d sbcedb -c "select trap_severity_level,alarm_notes,alarm_timestampsecs from alarms;"|tail -n +3|head -n -2|sed -re 's/.(.*).*\|.(.*).\|.*([0-9]{10}).*/echo "Serverity: \1 Alarmtext: \2 Date: `date -d @\3`\<\/text>"/e' echo -e "</prtg>" fi elif [ $1 = "hastatus" ]; then if [[ $hainfo == "Primary" || $hainfo == "Secondary" ]]; then echo -e "<prtg>\n<result>" echo "<channel>HA Status</channel>" echo "<text>$hainfo</text>" echo "<value>$hainfo</value>" echo -e "</result>\n</prtg>" elif [ -z "$nodeip" ]; then echo -e "<prtg>\n<result>" echo "<channel>HA Status</channel>" echo "<value>NO HA</value>" echo -e "</result>\n</prtg>" else exit 0 fi else echo "No or wrong command suffix used. Possible options: sipstatus, alarmstatus, hastatus" fi

mkdir -p /var/prtg/scriptsxml
ln -s /sbin/check_sbc.sh /var/prtg/scriptsxml/check_sbc.sh
chown -R prtg /var/prtg
chown -R prtg.prtg /sbin/check_sbc.sh
chmod 755 /sbin/check_sbc.sh