This simple script will monitor your node and send alert to your telegram chat/group when your bioauth is about to end or already in inactive state.
#!/bin/bash
telegram_token='<YOUR_API_KEY>'
telegram_group='<YOUR_TELEGRAM_GROUP>'
telegram_user_tag="@<YOUR_TELEGRAM_USERNAME>"
# Stop editing
# Script starts here
server_ip=$(curl -s https://api.ipify.org)
telegram_bot="https://api.telegram.org/bot${telegram_token}/sendMessage"
status=$(curl -s http://127.0.0.1:9933 -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"bioauth_status","params":[],"id":1}' | jq '.result')
if [ "$(echo "$status" | tr '[:upper:]' '[:lower:]')" == "$(echo '"inactive"' | tr '[:upper:]' '[:lower:]')" ]; then
message="🚨Your Humanode (${server_ip}) is not active, please proceed to do re-authentication ${telegram_user_tag}"
else
current_timestamp=$(date +%s)
expires_at=$(curl -s http://127.0.0.1:9933 -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"bioauth_status","params":[],"id":1}' | jq '.result.Active.expires_at')
difference=$(( (expires_at / 1000 - current_timestamp) / 60 ))
if (( difference > 25 && difference < 31 )); then
message="🟡Your Humanode (${server_ip}) will be deactivated in 30 minutes, please prepare for re-authentication ${telegram_user_tag}"
elif (( difference > 0 && difference < 6 )); then
message="🔴Your Humanode (${server_ip}) will be deactivated in 5 minutes, please prepare for re-authentication ${telegram_user_tag}"
else
message="NULL"
fi
fi
if [ "$message" != "NULL" ]; then
curl -X POST -H "Content-Type:multipart/form-data" -F chat_id=${telegram_group} -F text="${message}" ${telegram_bot}
fi
Replace <YOUR_API_KEY>
with the key you get from previous step
For telegram_group
you can change it to your own chat/group.
Replace telegram_user_tag
with your own username
chmod ug+x /path/to/your/script.sh
You need to install the cronjob to make this alert work.
*/5 * * * * /path/to/your/script.sh
This cron will run the script every 5 minutes
Remember to replace /path/to/your/script.sh
to your actual script location