Add shell script to warn notify if storage is near full
This commit is contained in:
parent
4430883df6
commit
13939f3a6e
1 changed files with 23 additions and 0 deletions
23
shell/scripts/diskUsageAlert.sh
Executable file
23
shell/scripts/diskUsageAlert.sh
Executable 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
|
Loading…
Reference in a new issue