1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
Dismiss Notice

Welcome To SNBForums

SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.

If you'd like to post a question, simply register and have at it!

While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!

Watchdog script to monitor device availability on local network?

Discussion in 'Asuswrt-Merlin' started by XIII, Aug 25, 2019.

  1. XIII

    XIII Very Senior Member

    Joined:
    Feb 27, 2014
    Messages:
    796
    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?
     
  2. octopus

    octopus Very Senior Member

    Joined:
    Jul 17, 2012
    Messages:
    1,206
    Do a forum search that give you a start.
     
  3. Bamsefar

    Bamsefar Senior Member

    Joined:
    Oct 11, 2014
    Messages:
    260
    I have, back home, a script that reads all wifi mac adresses, will that do?
     
  4. XIII

    XIII Very Senior Member

    Joined:
    Feb 27, 2014
    Messages:
    796
    Did that before I posted, but I was not lucky with the search terms I used...

    Even if it's not exactly my use case I would love to see an example that will get me started. Please share it?
     
  5. octopus

    octopus Very Senior Member

    Joined:
    Jul 17, 2012
    Messages:
    1,206
    What about to use "pushover" as search word, working for me.
     
    XIII likes this.
  6. XIII

    XIII Very Senior Member

    Joined:
    Feb 27, 2014
    Messages:
    796
    I tried "watchdog", "monitor", "script", etc., but not "pushover" (because I know how to use that).

    Using that term does indeed give a good start. Thank you!
     
    QuikSilver, Marin and octopus like this.
  7. XIII

    XIII Very Senior Member

    Joined:
    Feb 27, 2014
    Messages:
    796
    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
     
  8. octopus

    octopus Very Senior Member

    Joined:
    Jul 17, 2012
    Messages:
    1,206
    Run script with "set -x" and trace it.
     
  9. XIII

    XIII Very Senior Member

    Joined:
    Feb 27, 2014
    Messages:
    796
    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: Sep 1, 2019
    octopus likes this.
  10. Natey2

    Natey2 Occasional Visitor

    Joined:
    Jun 27, 2018
    Messages:
    42
    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