[SOLVED] Slack/Email notifications on array start at boot, v6.8.3


Recommended Posts

Hello! I had been dealing with an issue and finally found a solution, I don't know if this is the best solution but it does get the job done. I really couldn't find anything when searching google or this forum that addresses what I was experiencing below and so I thought I would just create this post so it's out here on the internet for others.

 

I'm using User Scripts to send me notifications in Slack when my array is stopped and started for any reason, I specifically wanted to know this for reboots. The events I configured my script for is "At Startup of Array" and "At Stopping of Array".  There's also a "At First Array Start Only" if you want to narrow this down a boot up only alert.

 

The issue I ran into is that the notifications which send over the internet worked in every case where the array was stopped and started except on system boot up. I finally realized this is because it's not guaranteed that internet connectivity will be available at the moment "At Startup of Array" triggers in User Scripts.

 

The solution I implemented in my startup event is a bash 'until' condition which pings google.com one time every second and greps for a positive result, when the script confirms DNS resolution and IPv4 connectivity are both working then the script continues. I implemented some extra stuff so that if the server ever boots without internet connectivity (ISP actually down, etc) then it won't try to ping forever.

 

Script for "At Stopping of Array" is straight forward.

/usr/local/emhttp/webGui/scripts/notify -s "unRAID Array STOPPED." -i "alert" -m "unRAID array has stopped, plex is down."  -d "unRAID array has stopped, plex is down."

 

Script for "At Startup of Array" requires extra steps.

The 'maxpings' variable is the number of times the script will check for internet connectivity and then exits. There's a 1 second sleep between each try. 300 checks means it'll try for about 5 minutes, based on my own system it could take up to 1m 45s to fully boot with web server up, so it seemed like a decent default, adjust as needed.

maxpings=300
numpings=0
until [[ $(ping -q -W 1 -c 1 google.com | grep '1 received' -o) == "1 received" ]]
do
    sleep 1s
    ((numpings=numpings+1))
    if [ $numpings -gt $maxpings ]
    then
        exit 1
    fi
done

/usr/local/emhttp/webGui/scripts/notify -s "unRAID Array STARTED." -i "alert" -m "unRAID array has started, plex will be online momentarily."  -d "unRAID array has started, plex will be online momentarily."

 

Victory!

 

Edited by SixClover
Link to comment
  • JorgeB changed the title to [SOLVED] Slack/Email notifications on array start at boot, v6.8.3
  • 6 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.