Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

I have 2 Asterisk Check examples, one I use for a simple 1 line setup that makes sure the phone is registered and either "Idle" or "InUse" the other checks for a SIP and Device state is "OK".

Note: For CentOS 7 you may need to disable the follwing line in /etc/sudoers to run script in Cron.

#Defaults requiretty
sudo visudo && sudo service sudo restart
xymon   ALL=(ALL) NOPASSWD: /usr/sbin/asterisk

Example 1 for Simple check on 1 Device status

cat << 'EOL' >/usr/share/xymon-client/ext/asterisk.sh
#!/bin/sh

COLUMN=asterisk                             
COLOR=green                             
MSG='sudo asterisk -rx "core show hints" | grep "SIP/201&Custom:DND20  State:{Idle|InUse}'

#In this test, if var = empty = RED
var="$(sudo asterisk -rx "core show hints" | grep "SIP/201&Custom:DND20  State:Idle")"
var1="$(sudo asterisk -rx "core show hints" | grep "SIP/201&Custom:DND20  State:InUse")"
cmd="$(sudo asterisk -rx "core show hints")"


if [ -z "$var" ] && [ -z "$var1" ]

then

COLOR=red
MSG="${MSG}
FAILED
"${cmd}"
"
else

MSG="${MSG}
SUCCESS
"${cmd}"
"
fi

# Leave the rest of script alone
# Tell Xymon about it
$XYMON $XYMSRV "status $MACHINE.$COLUMN $COLOR `date`

${MSG}
"

exit 0
EOL


chown xymon:xymon /usr/share/xymon-client/ext/asterisk.sh
chmod 777 /usr/share/xymon-client/ext/asterisk.sh
 

cat << 'EOL' >/etc/xymon-client/client.d/asterisk.cfg
[asterisk]
 ENVFILE $XYMONCLIENTHOME/etc/xymonclient.cfg
 CMD $XYMONCLIENTHOME/ext/asterisk.sh
 LOGFILE $XYMONCLIENTHOME/logs/asterisk.log
 INTERVAL 15m
EOL
 
chown xymon:xymon /etc/xymon-client/client.d/asterisk.cfg
chmod 777 /etc/xymon-client/client.d/asterisk.cfg

/usr/share/xymon-client/bin/xymoncmd /usr/share/xymon-client/ext/asterisk.sh

/etc/init.d/xymon-client restart

Example 2 check SIP Registered and Device=OK (Only use if device is hardwired and should always be OK!)

cat << 'EOL' >/usr/share/xymon-client/ext/asterisk.sh
#!/bin/sh

COLUMN=asterisk                             
COLOR=green                             
MSG='asterisk -rx "sip show peers" | grep "{SIP|DEVICE}OK"'

#In this test, if var = empty = RED
var="$(sudo asterisk -rx "sip show peers" | grep "SIP.*OK")"
var1="$(sudo asterisk -rx "sip show peers" | grep "DEVICE.*OK")"
cmd="$(sudo asterisk -rx "sip show peers")"

if [ -z "$var" ] && [ -z "$var1" ]

then

COLOR=red
MSG="${MSG}
FAILED
""
"${cmd}"
"
else

MSG="${MSG}
SUCCESS
""
"${cmd}"
"
fi

# Leave the rest of script alone
# Tell Xymon about it
$XYMON $XYMSRV "status $MACHINE.$COLUMN $COLOR `date`

${MSG}
"

exit 0
EOL


chown xymon:xymon /usr/share/xymon-client/ext/asterisk.sh
chmod 777 /usr/share/xymon-client/ext/asterisk.sh
 

cat << 'EOL' >/etc/xymon-client/client.d/asterisk.cfg
[asterisk]
 ENVFILE $XYMONCLIENTHOME/etc/xymonclient.cfg
 CMD $XYMONCLIENTHOME/ext/asterisk.sh
 LOGFILE $XYMONCLIENTHOME/logs/asterisk.log
 INTERVAL 15m
EOL
 
chown xymon:xymon /etc/xymon-client/client.d/asterisk.cfg
chmod 777 /etc/xymon-client/client.d/asterisk.cfg

/usr/share/xymon-client/bin/xymoncmd /usr/share/xymon-client/ext/asterisk.sh

/etc/init.d/xymon-client restart

On Server :

sudo service xymon restart && sudo service apache2 restart

 

 

  • No labels