Last active
June 28, 2023 09:23
-
-
Save mbierman/6e305b1efdab5b4c276f33767b7e4076 to your computer and use it in GitHub Desktop.
This file contains 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 | |
diskusage=$(df -H | grep -vE '^Filesystem|mmcblk0p3' | awk '{ print $6 }') | |
name=$(printf "$(redis-cli get groupName)") | |
log=/data/logs/fwcheckspace.log | |
mydate=$(date +"%a %b %d %H:%M %P") | |
dir=$(dirname "$0") | |
IFTTTKEY="$(cat $dir/IFTTT.data | grep IFTTTKEY | cut -f2 -d "=" )" | |
IFTTTrigger="FWGReboot" | |
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 | |
error=false | |
tolerance=(85) | |
date=$(date) | |
for s in ${diskusage[@]}; do | |
# echo $s | |
diskno=$(df -H | grep $s$ | awk '{ print $5 " " $1 }'| cut -f1 -d '%') | |
if [[ "$diskno" -gt "$tolerance" ]] ; then | |
body=$(df | grep $diskno% | cut -f1 -d " ") | |
if [ -n "$IFTTTKEY" ] ; then | |
json='{"value1":"'$name' has excessive diskspace usage @ '$mydate'\n '$body': '$diskno'%","value2":"'$URL'","value3":"'$IMAGE'"}' | |
curl -X POST -H "Content-Type: application/json" \ | |
--data "$json" \ | |
https://maker.ifttt.com/trigger/$IFTTTrigger/with/key/$IFTTTKEY | |
fi | |
echo "$mydate '$name' excessive diskapce $body: $diskno" | tee -a $log | |
error=true | |
fi | |
done | |
if [ "$error" = "true" ] ; then | |
echo -e "\nRemoving files...\n\n" | |
sudo rm /home/pi/core.zeek.* | |
else | |
echo $mydate $name diskpace is normal| tee -a $log | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will check your FW disk space usage and notify you if it is unusually high (change
tolerance
to set notify threshold).Note, this is not necessary for must FW users. FW will take care of disk space utilization for you.
For IFTTT notification, add a file called IFTTT.data in the same directory and put one line formatted like so:
IFTTTKEY=[insert your IFTTT KEY]
You also need to create an IFTTT recipe with a webhook trigger.