Created
September 16, 2014 11:15
-
-
Save Freeaqingme/d369293ed80d148c0145 to your computer and use it in GitHub Desktop.
Check_disk NRPE script that more or less works on Solaris
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/bash | |
# | |
# Version 0.0.2 - Jan/2009 | |
# Changes: df -P (to avoid it from breaking long lines) | |
# | |
# by Thiago Varela - [email protected] | |
# Ripped from: http://exchange.nagios.org/directory/Plugins/Operating-Systems/Linux/check_disk--2D-%25-used-space/details | |
function help { | |
echo -e "\n\tThis plugin shows the % of used space of a mounted partition, using the 'df' utility\n\n\t$0:\n\t\t-c <integer>\tIf the % of used space is above <integer>, returns CRITICAL state\n\t\t-w <integer>\tIf the % of used space is below CRITICAL and above <integer>, returns WARNING state\n\t\t-d <device>\tThe partition or mountpoint to be checked. eg. "/dev/sda1", "/home", "/"" | |
exit -1 | |
} | |
# Getting parameters: | |
while getopts "d:w:c:h" OPT; do | |
case $OPT in | |
"d") device=$OPTARG;; | |
"w") warning=$OPTARG;; | |
"c") critical=$OPTARG;; | |
"h") help;; | |
esac | |
done | |
# Checking parameters: | |
( [ "$warning" == "" ] || [ "$critical" == "" ] ) && echo "ERROR: You must specify warning and critical levels" && help | |
# [ "$device" == "" ] && echo "ERROR: You must specify the partition to be checked" && help | |
[[ "$warning" -ge "$critical" ]] && echo "ERROR: Critical level must be highter than warning level" && help | |
device_warning="" | |
used_warning="" | |
while read device | |
do | |
# ( [[ `df | grep -w $device | wc -l` -gt 1 ]] || [[ `df | grep -w $device | wc -l` -lt 1 ]] ) && echo "ERROR: Partition incorrectly specified" && help | |
( [[ `df | grep -w $device | wc -l` -gt 1 ]] || [[ `df | grep -w $device | wc -l` -lt 1 ]] ) && continue | |
# Doing the actual check: | |
used=`df -P | grep -w $device | awk '{ print $5 }' | cut -d% -f1` | |
# Comparing the result and setting the correct level: | |
if [[ $used -ge $critical ]]; then | |
echo "CRITICAL - $device space used=$used% | '$device usage'=$used%;$warning;$critical;" | |
exit 2 | |
else if [[ $used -ge $warning ]]; then | |
device_warning=$device | |
used_warning=$used | |
fi | |
fi | |
done < <(mount | awk '{print $1}') | |
if [[ $device_warning != "" ]]; then | |
echo "WARNING - $device_warning space used=$used_warning% | '$device usage'=$used_warning%;$warning;$critical;" | |
exit 1 | |
fi | |
echo "OK - Sth here?" # | '$device usage'=$used%;$warning;$critical;" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment