Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mbierman
Last active February 17, 2023 06:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mbierman/50bde96e2205a725a13fc38ab2b3dd95 to your computer and use it in GitHub Desktop.
Save mbierman/50bde96e2205a725a13fc38ab2b3dd95 to your computer and use it in GitHub Desktop.
Firewalla script to log upgrades and reboots and notify you.
#!/bin/bash
# v 1.2.2
dir=$(dirname "$0")
IFTTTKEY="$(cat $dir/rebootdata.txt | grep IFTTTKEY | cut -f2 -d "=" )"
IFTTTrigger="$(cat $dir/rebootdata.txt | grep IFTTTTrigger | cut -f2 -d "=" )"
version=$(cat ~/firewalla/net2/config.json | jq '.version')
version=${version:=Not Found}
OS=$(lsb_release -r | cut -f2)
build=$(grep -a "FIREWALLA.UPGRADECHECK.CHECK" /log/firewalla/firelog.log | tail -1 | cut -f12 -d" " | cut -c 1-8)
build=${build:=Not Found}
ONLINE=1
name=$(redis-cli get groupName)
name="$(echo $name | sed -e "s|’|'|")"
IMAGE="https://avatars2.githubusercontent.com/u/21322342?s=200&v=4"
URL="firewalla://" # opens the firewalla app on iOS
# URL="https://my.firewalla.com" # opens the firewalla web app Uncomment if you want this and comment the previous line
edate=$(date +'%a %b %d %H:%M:%S %Z %Y')
json='{"value1":"'$name' has rebooted @ '$edate'.\nRunning '$version' ('$build'), on Ubuntu '$OS'","value2":"'$URL'","value3":"'$IMAGE'"}'
retention=300
data=/data
logfile=$data/fw_reboot.txt
if ! [ -w $logfile ] ; then
sudo touch $logfile
sudo chmod a+w $logfile
fi
if ! [[ -d "$data" ]] ; then
sudo mkdir $data
sudo chmod 777 $data
fi
while [ $ONLINE -ne 0 ]
do
ping -4 -q -c1 -w 1 ifttt.com >/dev/null 2>&1
ONLINE=$?
if [ $ONLINE -ne 0 ]
then
sleep 15
fi
done
echo "We are on line!"
pushAlert () {
# This requires an IFTTT pro key
if [ -n "IFTTTKEY" ]; then
curl -X POST -H "Content-Type: application/json" --data "$json" https://maker.ifttt.com/trigger/$IFTTTrigger/with/key/$IFTTTKEY
fi
}
pushAlert $URL $IMAGE
if [ "$1" = "nolog" ] ; then
echo -e "\n\n$edate FW $name Rebooted $OS box: $version ($build) "
else
echo $edate FW $name Rebooted $OS box: $version \($build\) | tee -a $logfile
sudo touch ${logfile}.tmp
sudo chmod a+wr ${logfile}.tmp
sudo tail -n $retention $logfile > ${logfile}.tmp
sudo mv ${logfile}.tmp $logfile
fi
IFTTTKEY=Xxx
IFTTTTrigger=FWGReboot
@mbierman
Copy link
Author

mbierman commented Feb 16, 2022

Set up

  1. ssh to your Firewalla. If you don't know how, see firewalla's instructions.
  2. Put fg_reboot.sh in ~/.firewalla/config/post_main.d. If post_main.d doees not exist, create it first.
  3. If you are going to use IFTTT for notifications, add the rebootdata.txt file as well and edit rebootdata.txt to have your IFTTT key and trigger. (only required if you are using IFTTT). IFTTT should be configured with a Rich Notification notification, not JSON.
  4. Create an IFTTT applet with a Webhook (trigger) that sends a notification.

Sample notification

alerts

Here is an example of the IFTTT applet that sends a notification and an email.
Every time Firewalla updates or reboots it will log to /data/fwg_reboot.txt and send a notification unless you leave the IFTTT key empty.
Screen Shot 2022-02-17 at 11 23 57 AM

Screen Shot 2022-02-17 at 11 22 15 AM

Notes

  • Currently only the last 100 updates/reboots are stored. You can change this by updating the "retention" variable.
  • Tested on Firewalla Gold, Purple, and Blue Plus

Sample log

Wed Feb 16 12:56:35 PST 2022 FWG Rebooted 1.974 (4b86eafc)
Fri Feb 18 04:56:15 PST 2022 FW Rebooted 1.974 (4b86eafc)
Fri Feb 18 10:51:55 PST 2022 FW Rebooted 1.974 (f219acd1)
Fri Feb 18 10:54:39 PST 2022 FW Rebooted 1.974 (a014b05d)
Sat Feb 19 04:05:38 PST 2022 FW Rebooted 1.974 (356a8420)
Sat Feb 19 05:06:41 PST 2022 FW Rebooted 1.974 (356a8420)
Mon Feb 21 11:11:10 PST 2022 FW Rebooted 1.974 (4b2bf59e)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment