From 13939f3a6eef46501546033509a87e795874046f Mon Sep 17 00:00:00 2001 From: Nikurasu Date: Mon, 5 Jun 2023 14:11:13 +0200 Subject: [PATCH] Add shell script to warn notify if storage is near full --- shell/scripts/diskUsageAlert.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 shell/scripts/diskUsageAlert.sh diff --git a/shell/scripts/diskUsageAlert.sh b/shell/scripts/diskUsageAlert.sh new file mode 100755 index 0000000..988af69 --- /dev/null +++ b/shell/scripts/diskUsageAlert.sh @@ -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