Last active
July 22, 2020 01:41
-
-
Save bmgSpark/045e8f610cdb793d7773181c8154f1ee to your computer and use it in GitHub Desktop.
bash script to alert via pushover if disk free percentage falls before a certain amount on a particular device [change DevMon var to a different variable to use something different]. Tested on readynas 516
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
#! /usr/bin/env bash | |
let notify=75 | |
let criticalnotify=91 | |
let doAct=0 | |
DevMon="/dev/md0" | |
let percval=`df -h | grep -i $DevMon | awk '{ print +$5 }'` | |
echo percval = $percval | |
echo notify = $notify | |
sSev="INFO" | |
##check for critical warning -- can be disabled by making $criticalnotify a crazy number | |
if [ $percval -ge $criticalnotify ]; then | |
echo "we should notify as CRITICAL as $percval is gte than $criticalnotify" | |
let doAct=2 | |
#critical notify | |
sSev="CRIT" | |
echo "Sending Pushover using curl with $sSev" | |
curl -s \ | |
-F "token=<API-Token-APP>" \ | |
-F "user=<API-Token-User>" \ | |
-F "title=DiskFree Alert sev: $sSev" \ | |
-F "priority=$doAct" \ | |
-F "retry=180" \ | |
-F "priority=$doAct" \ | |
-F "retry=180" \ | |
-F "sound=siren" \ | |
-F "expire=3620" \ | |
-F "message=DiskFree Perc: $percval" \ | |
http://api.pushover.net/1/messages > /dev/null | |
fi | |
### handle warning level -- seperated to allow different alerting sources or actions | |
elif [ $percval -ge $notify ]; then | |
echo "we should notify as $percval is gte than $notify" | |
let doAct=1 | |
sSev="WARN" | |
else | |
echo no notification needed $percval less than $notify | |
fi | |
echo doAct = $doAct | |
echo "magic severity = $sSev ... DOACT = $doAct" | |
if [ $sSev == "WARN" ] ; then | |
echo "normal severity messsge going out" | |
echo "Sending Pushover using curl with $sSev" | |
curl -s \ | |
-F "token=<API-Token-APP>" \ | |
-F "user=<API-Token-User" \ | |
-F "title=DiskFree Alert sev: $sSev" \ | |
-F "priority=$doAct" \ | |
-F "message=DiskFree Perc: $percval" \ | |
http://api.pushover.net/1/messages > /dev/null | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment