Add shell script to warn notify if storage is near full

This commit is contained in:
Nikurasu 2023-06-05 14:11:13 +02:00
parent 4430883df6
commit 13939f3a6e
Signed by: Nikurasu
GPG key ID: 9E7F14C03EF1F271

23
shell/scripts/diskUsageAlert.sh Executable file
View file

@ -0,0 +1,23 @@
#!/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