Last active
April 12, 2017 08:36
-
-
Save xopr/d0275cc0bb8031d93c0cf11f4bad8ebe to your computer and use it in GitHub Desktop.
Check FreeSWITCH services, space|nl|de node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add it to `crontab -e` with | |
# */10 * * * * ~/check_fs.sh PUBLICNODEPART_OR_SPACE | |
# where space as node name is a special scenario | |
# NOTE: crontab uses `sh` which is somewhat spartan compared to `bash` | |
# Column number to place the status message | |
RES_COL=60 | |
# Command to move out to the configured column number | |
MOVE_TO_COL="echo -en \\033[${RES_COL}G" | |
# Command to set the color to SUCCESS (Green) | |
SETCOLOR_SUCCESS="echo -en \\033[1;32m" | |
# Command to set the color to FAILED (Red) | |
SETCOLOR_FAILURE="echo -en \\033[1;31m" | |
# Command to set the color to UNKNOWN (Yellow) | |
SETCOLOR_UNKNOWN="echo -en \\033[1;33m" | |
# Command to set the color back to normal | |
SETCOLOR_NORMAL="echo -en \\033[0;39m" | |
# Function to print the SUCCESS status | |
echo_success() { | |
if [[ -z $1 ]]; then message=" OK "; else message="$1"; fi | |
$MOVE_TO_COL | |
echo -n "[" | |
$SETCOLOR_SUCCESS | |
echo -n "$message" | |
$SETCOLOR_NORMAL | |
echo -n "]" | |
echo -ne "\r" | |
return 0 | |
} | |
# Function to print the FAILED status message | |
echo_failure() { | |
if [[ -z $1 ]]; then message="FAILED"; else message="$1"; fi | |
$MOVE_TO_COL | |
echo -n "[" | |
$SETCOLOR_FAILURE | |
echo -n "$message" | |
$SETCOLOR_NORMAL | |
echo -n "]" | |
echo -ne "\r" | |
return 1 | |
} | |
# Function to print the N/A status message | |
echo_unknown() { | |
if [[ -z $1 ]]; then message=" N/A "; else message="$1"; fi | |
$MOVE_TO_COL | |
echo -n "[" | |
$SETCOLOR_UNKNOWN | |
echo -n "$message" | |
$SETCOLOR_NORMAL | |
echo -n "]" | |
echo -ne "\r" | |
return 1 | |
} | |
KEY="<SPACEAPI_KEY>" | |
status="https://ackspace.nl/spaceAPI/?key=${KEY}&update=sensors&type=service&address=$1node" | |
#&spacenode=true | |
echo Gateways: | |
echo -ne "\tbudgetphone.nl" | |
status="${status}&budgetphone=" | |
fs_cli -x "sofia status gateway budgetphone.nl"|grep -eREGED -eREGISTER > /dev/null | |
if [ $? -ne 1 ]; then echo_success; status="${status}true"; else echo_failure; status="${status}false"; fi; echo | |
if [ "$1"=="space" ]; then | |
echo -ne "\tackspace.nl" | |
status="${status}&ackspace=" | |
fs_cli -x "sofia status gateway ackspace.nl"|grep -eREGED -eREGISTER > /dev/null | |
if [ $? -ne 1 ]; then echo_success; status="${status}true"; else echo_failure; status="${status}false"; fi; echo | |
echo -ne "\t\tping" | |
ping=`fs_cli -x "sofia status gateway ackspace.nl"|grep PingTime|sed -r 's/[^0-9]+([0-9]+)\.([0-9]{2})/\1\20/'` | |
status="${status}&ackspace_lag=$ping" | |
if [ $ping -gt 35000 ]; then echo_failure "${ping}n"; | |
elif [ $ping -lt 10000 ]; then echo_success " ${ping}n"; | |
elif [ $ping -lt 20000 ]; then echo_success "${ping}n"; | |
else echo_unknown "${ping}n"; | |
fi; echo | |
echo -ne "\tvoipbuster.com" | |
status="${status}&voipbuster=" | |
fs_cli -x "sofia status gateway voipbuster.com"|grep -eREGED -eREGISTER > /dev/null | |
if [ $? -ne 1 ]; then echo_success; status="${status}true"; else echo_failure; status="${status}false"; fi; echo | |
echo -ne "\t\tping" | |
ping=`fs_cli -x "sofia status gateway voipbuster.com"|grep PingTime|sed -r 's/[^0-9]+([0-9]+)\.([0-9]{2})/\1\20/'` | |
status="${status}&voipbuster_lag=$ping" | |
if [ $ping -gt 35000 ]; then echo_failure "${ping}n"; | |
elif [ $ping -lt 10000 ]; then echo_success " ${ping}n"; | |
elif [ $ping -lt 20000 ]; then echo_success "${ping}n"; | |
else echo_unknown "${ping}n"; | |
fi; echo | |
echo -ne "\tintervoip.com" | |
status="${status}&intervoip=" | |
fs_cli -x "sofia status gateway intervoip.com"|grep NOREG > /dev/null | |
if [ $? -ne 1 ]; then echo_success; status="${status}true"; else echo_failure; status="${status}false"; fi; echo | |
echo -ne "\t\tping" | |
ping=`fs_cli -x "sofia status gateway intervoip.com"|grep PingTime|sed -r 's/[^0-9]+([0-9]+)\.([0-9]{2})/\1\20/'` | |
status="${status}&intervoip_lag=$ping" | |
if [ $ping -gt 35000 ]; then echo_failure "${ping}n"; | |
elif [ $ping -lt 10000 ]; then echo_success " ${ping}n"; | |
elif [ $ping -lt 20000 ]; then echo_success "${ping}n"; | |
else echo_unknown "${ping}n"; | |
fi; echo | |
echo Extensions: | |
echo -ne "\tslACKspace" | |
status="${status}&slackspace=" | |
fs_cli -x "sofia_contact 101"|grep "sip:101@" > /dev/null | |
if [ $? -ne 1 ]; then echo_success; status="${status}true"; else echo_failure; status="${status}false"; fi; echo | |
echo -ne "\thACKspace" | |
status="${status}&hackspace=" | |
fs_cli -x "sofia_contact 102"|grep "sip:102@" > /dev/null | |
if [ $? -ne 1 ]; then echo_success; status="${status}true"; else echo_failure; status="${status}false"; fi; echo | |
echo -ne "\tstACKspace" | |
status="${status}&stackspace=" | |
fs_cli -x "sofia_contact 103"|grep "sip:103@" > /dev/null | |
if [ $? -ne 1 ]; then echo_success; status="${status}true"; else echo_failure; status="${status}false"; fi; echo | |
else | |
echo -ne "\tvoipbuster.com" | |
status="${status}&voipbuster=" | |
fs_cli -x "sofia status gateway voipbuster.com"|grep NOREG > /dev/null | |
if [ $? -ne 1 ]; then echo_success; status="${status}true"; else echo_failure; status="${status}false"; fi; echo | |
echo -ne "\tcheapconnect.net" | |
status="${status}&cheapconnect=" | |
fs_cli -x "sofia status gateway cheapconnect.net"|grep -eREGED -eREGISTER > /dev/null | |
if [ $? -ne 1 ]; then echo_success; status="${status}true"; else echo_failure; status="${status}false"; fi; echo | |
echo -ne "\tspeakup" | |
status="${status}&speakup=" | |
fs_cli -x "sofia status gateway speakup"|grep -eREGED -eREGISTER > /dev/null | |
if [ $? -ne 1 ]; then echo_success; status="${status}true"; else echo_failure; status="${status}false"; fi; echo | |
echo Extensions: | |
echo -ne "\tackspace" | |
status="${status}&ackspace=" | |
fs_cli -x "sofia_contact [email protected]"|grep "ackspace.nl@" > /dev/null | |
if [ $? -ne 1 ]; then echo_success; status="${status}true"; else echo_unknown; status="${status}null"; fi; echo | |
fi | |
#echo $status | |
wget -q -O /dev/null "$status" | |
echo -n "Uploading results" | |
if [ $? -eq 0 ]; then echo_success; else echo_failure; fi; echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment