This script just a simple logic, when vRouter on Openstack not reachable script will execute Network Agent Report to Telegram
172.20.1.230
is your vRouterTELEGRAM_BOT_TOKEN
is yourCHAT_ID
is your Telegram CHAT ID
nano /root/os-sh/check-netagent.sh
#!/bin/bash
# Environment
DATE="$(date "+%d %b %Y %H:%M")"
TELEGRAM_BOT_TOKEN=""
CHAT_ID=""
ALERT=$(echo -e "\u26A0")
source /root/openstack/admin-openrc.sh
HOSTUP=$(openstack network agent list | grep UP | cut -d "|" -f 4 )
AGENTUP=$(openstack network agent list | grep UP | cut -d "|" -f 3)
AGENTDOWN=$(openstack network agent list | grep DOWN | cut -d "|" -f 3)
HOSTDOWN=$(openstack network agent list | grep DOWN | cut -d "|" -f 4 )
STATUS=$(openstack network agent list | grep UP | cut -d "|" -f 7)
if ! [ "$STATUS" == "UP" ]; then
TEXT="$ALERT *Network Agent Hourly Report :* $ALERT
*This agent is already UP :*
$AGENTUP
*That agent UP runs on :*
$HOSTUP
*This agent is DOWN :*
$AGENTDOWN
*That agent DOWN runs on :*
$HOSTDOWN
*Reported on $DATE*"
curl -s -d "chat_id=$CHAT_ID&text=${TEXT}&disable_web_page_preview=true&parse_mode=markdown" https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage? > /dev/null
fi
nano /root/os-sh/ping.sh
#!/bin/bash
SERVERIP=172.20.1.230
ping -c 3 $SERVERIP > /dev/null 2>&1
if [ $? -ne 0 ]
then
/bin/bash /root/os-sh/check-netagent.sh
fi
chmod 777 /root/os-sh/check-netagent.sh
chmod 777 /root/os-sh/ping.sh
crontab -e
* * * * * /bin/bash /root/os-sh/ping.sh
So, monitor your telegram!