What's new

Watchdog script to monitor device availability on local network?

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

XIII

Very Senior Member
I want to be notified when one particular device in my local network goes offline. I was first thinking of writing a script on a Raspberry Pi, but then I thought it might be possible on the router (RT-AC86U, running Asuswrt-Merlin 384.13) itself?

My general idea is to ping the device a couple of times (every x minutes) and if all those attempts fail send a push notification via Pushover to my mobile devices.

Does somebody already have a similar script that (s)he wants to share?

Or any tips on how to start from scratch?
 
I want to be notified when one particular device in my local network goes offline. I was first thinking of writing a script on a Raspberry Pi, but then I thought it might be possible on the router (RT-AC86U, running Asuswrt-Merlin 384.13) itself?

My general idea is to ping the device a couple of times (every x minutes) and if all those attempts fail send a push notification via Pushover to my mobile devices.

Does somebody already have a similar script that (s)he wants to share?

Or any tips on how to start from scratch?
Do a forum search that give you a start.
 
Did that before I posted, but I was not lucky with the search terms I used...

What about to use "pushover" as search word, working for me.
 
I'm trying this for now; feedback is welcome!
Code:
#!/bin/sh

check_reachable() {
    ping -c1 -q -w10 "$1" >/dev/null 2>&1
}

notify() {
    curl -s \
    --form-string "token=<APP>" \
    --form-string "user=<USER>" \
    --form-string "title=AC86U" \
    --form-string "message=$1 unreachable!" \
    --form-string "sound=siren" \
    --form-string "priority=1" \
    https://api.pushover.net/1/messages.json
}

for HOST in device1 device2 device3 device4
do
    if ! check_reachable ${HOST}
    then
        notify ${HOST}
    fi
done
where device1, device2, device3, and device4 are (local) hostnames for some devices in my network.

With this line added to services-start:
Code:
cru a Reachable "55 * * * * sh /jffs/scripts/check_reachable.sh"

And this line to services-stop:
Code:
cru d Reachable
 
Run script with "set -x" and trace it.
 
Run script with "set -x" and trace it.
It’s working as far as I know.

Since I’m no script guru I am wondering if this can be improved, and how.

EDIT: Did a real-life test by disconnecting a device just before 19:55 and did get a push notification on my Apple Watch at 19:55 :)
 
Last edited:
I want to be notified when one particular device in my local network goes offline.

My ASUS RT-AC88U supports IFTTT.
I've used it to detect and alert me when a Roku connects to my WiFi.
It might be able to detect and alert on device disconnects too.

Sent using Tapatalk
 
I'm trying this for now; feedback is welcome!
Code:
#!/bin/sh

check_reachable() {
    ping -c1 -q -w10 "$1" >/dev/null 2>&1
}

notify() {
    curl -s \
    --form-string "token=<APP>" \
    --form-string "user=<USER>" \
    --form-string "title=AC86U" \
    --form-string "message=$1 unreachable!" \
    --form-string "sound=siren" \
    --form-string "priority=1" \
    https://api.pushover.net/1/messages.json
}

for HOST in device1 device2 device3 device4
do
    if ! check_reachable ${HOST}
    then
        notify ${HOST}
    fi
done
where device1, device2, device3, and device4 are (local) hostnames for some devices in my network.

With this line added to services-start:
Code:
cru a Reachable "55 * * * * sh /jffs/scripts/check_reachable.sh"

And this line to services-stop:
Code:
cru d Reachable
I am not too familiar with scripts, I have the wan notification and firmware update ones running properly and can execute them from a command line to test but when I try to do the same with this one I get

-sh: ./check_reachable.sh: not found
 
so I am still having some trouble, when I have this line and trigger from a command line nothing happens:

cru a Reachable "55 * * * * sh /jffs/scripts/check_reachable.sh"

if I simply change it to
/jffs/scripts/check_reachable.sh

I get the pushover notification from the command line but I never actually get notified when the device I am trying to monitor goes offline, do I need to change something in the ping line?
 
Last edited:
I don't know what you mean by "when I have this line and trigger from a command line nothing happens". All that command does is schedule the script to run once an hour at 5 minutes to the hour. So you have to wait until that time.
 

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top