-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env bash | ||
|
||
# vars # | ||
disk="/dev/mapper/fedora-root" # disk to monitor | ||
current_blocks=$(df -m | grep ${disk} | awk {'print $2'}) # get amount of blocks used | ||
mounted=$(df -m | grep ${disk} | awk {'print $6'}) # get disk information | ||
max_threshold="20000" # max 20000 amount of blocks | ||
|
||
email="[email protected]" # mail to sent alert to | ||
|
||
# functions # | ||
function max_blocks_exceeded() { | ||
|
||
# tell that mail is being sent | ||
echo "Max amount of MB blocks (${max_threshold}) has exceeded as your MB block amount is set at ${max_threshold} mounted on ${mounted}." | ||
echo "Sending Alert..." | ||
|
||
# check if the mail program exist | ||
type email > /dev/null 2>&1 || { | ||
echo >&2 "Mail does not exist. Install it and run script again. Aborting script..."; exit; | ||
} | ||
|
||
# if the mail program exist we continue to this and send the alert | ||
mailbody="Max amount of MB blocks (${max_threshold}) exceeded. Current disk (${disk}) usage is at ${current_blocks} mounted on ${mounted}." | ||
echo ${mailbody} | mail -s "MB Blocks alert!" "${email}" | ||
|
||
echo "Mail was sent to ${email}" | ||
} | ||
|
||
function abort() { | ||
|
||
echo "No problems. Disk (${disk}) mounted on ${mounted} current MB block limit is at ${current_blocks}. Threshold is set to ${max_threshold}." | ||
} | ||
|
||
function main() { | ||
|
||
# check if a valid disk is chosen | ||
if [ ${current_blocks} ]; then | ||
# check if current MB block disk usage is greater than or equal to max usage. | ||
if [ ${current_blocks%?} -ge ${max_threshold%?} ]; then | ||
# if it is greater than or equal to max usage we call our max_exceeded function and send mail | ||
max_blocks_exceeded | ||
else | ||
# if it is ok we do nothing | ||
abort | ||
fi | ||
else | ||
# if the disk is not valid, print valid disks on system | ||
echo "Set a valid MB block env, and run script again. Your environment looks like the following: " | ||
df -m | ||
fi | ||
} | ||
|
||
# init # | ||
main |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env bash | ||
|
||
# vars # | ||
disk="/dev/mapper/fedora-root" # disk to monitor | ||
current_capacity=$(df -P | grep ${disk} | awk {'print $5'}) # get disk usage from monitored POSIX disk | ||
mounted=$(df -P | grep ${disk} | awk {'print $6'}) # get disk information via POSIX | ||
max_capacity="90%" # max 90% mount capacity | ||
|
||
email="[email protected]" # email to | ||
|
||
# functions # | ||
function max_exceeded() { | ||
|
||
# tell that mail is being sent | ||
echo "Max capacity of (${max_capacity}) has exceeded as your disk usage is it at ${current_capacity} mounted on ${mounted}." | ||
echo "Sending Alert..." | ||
|
||
# check if the mail program exist | ||
type email > /dev/null 2>&1 || { | ||
echo >&2 "Mail does not exist. Install it and run script again. Aborting script..."; exit; | ||
} | ||
|
||
# if the mail program exist we continue to this and send the alert | ||
mailbody="Max capacity (${max_usage}) exceeded. Current disk (${disk}) usage is at ${current_capacity} mounted on ${mounted}." | ||
echo ${mailbody} | mail -s "Disk alert!" "${email}" | ||
|
||
echo "Mail was sent to ${email}" | ||
} | ||
|
||
function abort() { | ||
|
||
echo "No problems. Disk (${disk}) mounted on ${mounted} capacity is at ${current_capacity}. Max is set to ${max_capacity}." | ||
} | ||
|
||
function main() { | ||
|
||
# check if a valid disk is chosen | ||
if [ ${current_capacity} ]; then | ||
# check if current disk usage is greater than or equal to max usage. | ||
if [ ${current_capacity%?} -ge ${max_capacity%?} ]; then | ||
# if it is greater than or equal to max usage we call our max_exceeded function and send mail | ||
max_exceeded | ||
else | ||
# if it is ok we do nothing | ||
abort | ||
fi | ||
else | ||
# if the disk is not valid, print valid disks on system | ||
echo "Set a valid POSIX disk env, and run script again. Your environment looks like the following: " | ||
df -P | ||
fi | ||
} | ||
|
||
# init # | ||
main |