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!

New firmware version check - push notification

Discussion in 'Asuswrt-Merlin' started by goaspy, Mar 13, 2017.

  1. goaspy

    goaspy New Around Here

    Joined:
    Oct 30, 2014
    Messages:
    8
    Hi, is there a way to run a script that will send a Pushover notification whenever a new stable version is found?
    I have the new version check option enabled, but I don't know if it's triggered by a web login or runs periodically.
    If it runs periodically then it should be able to trigger a custom script. The only complication I see in this case is to send the message only once, and the script would have to store a last notified version number somewhere.
    Thanks
     
  2. Blinkyz

    Blinkyz Senior Member

    Joined:
    Mar 11, 2015
    Messages:
    281
    Location:
    At work
    the trigger is 48h
     
  3. swetoast

    swetoast Very Senior Member

    Joined:
    Apr 12, 2016
    Messages:
    762
    and for pushover well all you need is to add, tweak it your needs to fit the script instead of email it can send a push

    Code:
    function push {
       curl -s -F "token=YOUR_TOKEN_HERE" \
       -F "user=YOUR_USER_KEY_HERE" \
       -F "title=YOUR_TITLE_HERE" \
       -F "message=$1" https://api.pushover.net/1/messages.json
    }
    
    push "It worked\!"
     
  4. RMerlin

    RMerlin Part of the Furniture

    Joined:
    Apr 14, 2012
    Messages:
    22,060
    Location:
    Canada
    There's a custom script that gets run on new firmware availability. It's documented in the Changelog, but I forgot to add it to the Wiki after that version went out of beta. Check the Changelog for more info. I also posted a sample GMail script in the 380.65 alpha thread here on the forums.
     
    goaspy likes this.
  5. swetoast

    swetoast Very Senior Member

    Joined:
    Apr 12, 2016
    Messages:
    762
    i could volunteer to do a updated sample with pushover and pushbullet notifications planning to do a personal script anyways then i can add it to the wiki
     
  6. swetoast

    swetoast Very Senior Member

    Joined:
    Apr 12, 2016
    Messages:
    762
    tested script :p based on Rmerlins sample script

    Code:
    #!/bin/sh
    use_email="disabled"                                    # enabled / disabled (default: disabled)
    use_pushbullet="disabled"                               # enabled / disabled (default: disabled)
    use_pushover="disabled"                                 # enabled / disabled (default: disabled)
    
    #Pushbullet/Pushover settings
    pushbullet_token=""                                     # Your access token here (https://docs.pushbullet.com/)
    pushover_token=""                                       # Your access token here (https://pushover.net/api)
    pushover_username=""                                    # Pushover User ID (the user/group key (not e-mail address often referred to as USER_KEY)
    
    # email settings
    SMTP="smtp.gmail.com"
    PORT="465"
    USERNAME=""
    PASSWORD=""
    
    # Mail Enveloppe
    FROM_NAME=""
    FROM_ADDRESS=""
    TO_NAME=""
    TO_ADDRESS=""
    
    ### Do not change below
    # Retrieve version
    TMPVERS=$(nvram get webs_state_info)
    VERS=${TMPVERS:5:3}.${TMPVERS:8:10}
    ROUTER_IP=$(nvram get lan_ipaddr)
    
    email_message () {
    echo "From: \"$FROM_NAME\" <$FROM_ADDRESS>" > /tmp/mail.txt
    echo "To: \"$TO_NAME\" <$TO_ADDRESS>" >> /tmp/mail.txt
    echo "Subject: New router firmware notification" >> /tmp/mail.txt
    echo "" >> /tmp/mail.txt
    echo "New firmware version $VERS is now available for your router at $ROUTER_IP." >> /tmp/mail.txt
    curl --url smtps://$SMTP:$PORT \
      --mail-from "$FROM_ADDRESS" --mail-rcpt "$TO_ADDRESS" \
      --upload-file /tmp/mail.txt \
      --ssl-reqd \
      --user "$USERNAME:$PASSWORD" --insecure
    rm /tmp/mail.txt
    }
    
    pushover_message () {
    curl -s \
      --form-string "token=$pushover_token" \
      --form-string "user=$pushover_username" \
      --form-string "message=New firmware version $VERS is now available for your router at $ROUTER_IP." \
      https://api.pushover.net/1/messages.json
    }
    
    pushbullet_message () {
    text="New firmware version $VERS is now available for your router at $ROUTER_IP."
    title="$USER@$HOSTNAME"
    curl -s -u $pushbullet_token: -X POST https://api.pushbullet.com/v2/pushes --header 'Content-Type: application/json' --data-binary '{"type": "note", "title": "'"$title"'", "body": "'"$text"'"}' >/dev/null 2>&1
    }
    
         if [ $use_pushbullet = "enabled" ]; then
            pushbullet_message
         fi
         if [ $use_pushover = "enabled" ]; then
            pushover_message
         fi
         if [ $use_email = "enabled" ]; then
            email_message
         fi
     
    Last edited: Mar 13, 2017
    L&LD likes this.
  7. goaspy

    goaspy New Around Here

    Joined:
    Oct 30, 2014
    Messages:
    8
    Thanks for your help, I've got it working, at least manually for now, I just have to wait for a new release :)

    I was getting this error at first, "curl: option -F: is badly used here", but I've changed it using an example from pushover and it works fine now:

    Code:
    pushover_message () {
    curl -s \
      --form-string "token=$pushover_token" \
      --form-string "user=$pushover_username" \
      --form-string "message=New firmware version $VERS is now available for your router at $ROUTER_IP." \
      https://api.pushover.net/1/messages.json
    }
     
    swetoast likes this.
  8. swetoast

    swetoast Very Senior Member

    Joined:
    Apr 12, 2016
    Messages:
    762
    tnx updated script above, hope this settles the push option :)
     
  9. goaspy

    goaspy New Around Here

    Joined:
    Oct 30, 2014
    Messages:
    8
    One last thing, I've named the script "update-notification", as mentioned in the changelog, and I've placed it in "/jffs/scripts". I should now get notifications every 48h until I switch to the new version.

    Cheers!
     
  10. swetoast

    swetoast Very Senior Member

    Joined:
    Apr 12, 2016
    Messages:
    762
    RMerlin likes this.

Share This Page