Last active
February 17, 2023 06:35
-
-
Save mbierman/50bde96e2205a725a13fc38ab2b3dd95 to your computer and use it in GitHub Desktop.
Firewalla script to log upgrades and reboots and notify you.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IFTTTKEY=Xxx | |
IFTTTTrigger=FWGReboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Set up
fg_reboot.sh
in~/.firewalla/config/post_main.d
. Ifpost_main.d
doees not exist, create it first.rebootdata.txt
file as well and editrebootdata.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.Sample notification
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.Notes
Sample log