dotfiles/shell/scripts/diskUsageAlert.sh

24 lines
731 B
Bash
Executable file

#!/bin/bash
# user declaired variables
DISK=
API_KEY=
DOMAIN=
PRIO=1
TITLE="La Noscea Disk Usage"
THRESHOLD_SIZE=20
THRESHOLD_UNIT=G
# DON'T TOUCH THIS!!!!
declare -A POWER_OF=( ["K"]=0 ["M"]=1 ["G"]=2 ["T"]=3 )
THRESHOLD_IN_K=$(($THRESHOLD_SIZE*1024**${POWER_OF[$THRESHOLD_UNIT]}))
echo $THRESHOLD_IN_K
USAGE=$(df $DISK --output=avail | tail -1 | tr -d ' ' | tr -d '\n' | tr -d '\t' | tr -d '\r')
echo $USAGE
if [ "$USAGE" -lt "$THRESHOLD_IN_K" ]; then
curl --request POST --url "https://$DOMAIN/message" --header 'Content-Type: application/json' --header "X-Gotify-Key: $API_KEY" --data "{\"message\": \"Under $THRESHOLD_SIZE $THRESHOLD_UNIT free!!!\",\"priority\": $PRIO,\"title\": \"$TITLE\"}"
else
echo "higher"
fi