Storage Node uptime script for notifing you when your node is down (Linux)

I developed this code to notify me when my node it’s down

#!/bin/bash

VAR1=`timeout --foreground -s SIGINT 1s docker exec -it storagenode /app/dashboard.sh | grep "Last Contact"`
VAR2=`cat output.txt`

if [[ $VAR1 =~ "ONLINE" ]]; then
  rm output.txt
  echo "Online"
elif [[ -n $VAR2 ]]; then
  echo "Continues Offline"
else
  rm output.txt
  echo "Offline" > output.txt
  GET "http://api.callmebot.com/start.php?user=@telegram user&text=urlencodedmessage&lang=lenguage&rpt=timestorepeat"
fi

It uses the CLI dashboard and the grep command to store the status line as a varible, if it’s online, it does nothing, if it’s offline and it’s first time it sees it offline, it will use GET and CallMeBot to call me on Telegram (you can obtain you URL from callmebot.com with your Telegram user and message in your lenguage and set up the times it repeats the message), then, it will save a file called output.txt so that when the script runs again, it will know that you have been already notified and it won’t call you every minute.
You can set this up as a cron job, so it runs it every minute or what ever you want it to be, I recommend putting it in a folder so output.txt doesn’t mess with other programs outputs.
Keep in mind that this will not work if your server is offline because it is powered off


My Youtube: https://www.youtube.com/channel/UCSX8C8lSkLz1DsDeSSWcHOA

6 Likes

Welcome to storj :slight_smile:

@JavierCastroYT many of us use a third party service like UptimeRobot for pinging the Storj port of our nodes, and get notifications (e-mails mainly) when a node gets offline.

It works around the limitation that you underlined:

1 Like

Thanks :slight_smile:

The problem for me is that I prefer using CallMeBot because it gets more my attention than a normal email, but it’s true that you could do the same by setting a rule so that it forwads from your inbox to IFTTT those emails and then IFTTT triggers CallMeBot

Im using this now and its great! Just a couple notes. The grep should now be for “Status”, and idk if its just me, but I was unable to get the docker exec command to work under cron with the -it. It only ran without the t. Gave me a no TTY error. But thanks for this! Itll save me from having a node down for 3 days without realizing again!