Skip to content

Instantly share code, notes, and snippets.

@discarn8
Created May 2, 2018 07:57
Show Gist options
  • Save discarn8/eea6f68a0d0253c0b6461bffe4c75e2b to your computer and use it in GitHub Desktop.
Save discarn8/eea6f68a0d0253c0b6461bffe4c75e2b to your computer and use it in GitHub Desktop.
hddtemp_wrapper_for_nagios.sh
#!/bin/sh
#February 09, 2008 Vincent Danen
usage() {
echo "${0} -w [warn] -c [crit] [drives]"
}
if [ "${1}" == "-h" -o "${1}" == "--help" ]; then
usage
exit 0
fi
if [ "${1}" == "-w" ]; then
shift
warn="${1}"
shift
else
usage
exit 1
fi
if [ "${1}" == "-c" ]; then
shift
crit="${1}"
shift
else
usage
exit 1
fi
while [ "${1}" != "" ]; do
drives="${drives} ${1}"
shift
done
if [ "${drives}" == "" ]; then
usage
exit 1
fi
status=0
smsg=""
htemp=0
for drive in ${drives}; do
msg=""
stats=`/usr/local/sbin/hddtemp ${drive}`
model=`echo ${stats} | cut -d ':' -f 2`
temp=`echo ${stats} | cut -d ':' -f 3 | cut -d ' ' -f 2`
dev=`echo ${drive}|cut -d '/' -f 3`
if [ "${temp}" -ge "${warn}" ]; then
if [ "${status}" != "2" ]; then
status=1
fi
fi
if [ "${temp}" -ge "${crit}" ]; then
status=2
fi
if [ "${temp}" -gt "${htemp}" ]; then
htemp="${temp}"
fi
smsg="${smsg}${dev}=${temp}C; "
done
case "${status}" in
2)
wmsg="CRITICAL"
;;
1)
wmsg="WARN"
;;
0)
wmsg="OK"
;;
esac
echo "HDDTEMP ${wmsg} - ${smsg}|hddtemp=${htemp};${warn};${crit};0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment