Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 89 lines (74 sloc) 1.66 KB
#!/usr/bin/env bash
# Copyright 2010-2012 Voxer IP LLC. All rights reserved.
# License: MIT
#
# Check for hard errors with kstat nagios style
#
# Author: Dave Eddy <dave@voxer.com>
usage() {
echo "Version $VERSION"
echo " "
echo Usage
echo "./check_hard_errors [-b sd0<,sd1><,sd2><,...>]"
echo " "
echo " -s : don't consider listed devices (comma separated)"
echo " -h : this help"
echo " "
exit 1
}
# blacklisted vendors
skipvendors=('KVM' 'TEAC')
# blacklisted sd
#skipsd=('1' '2' '3')
while getopts "b:h" opt; do
case $opt in
b)
skipsd=$OPTARG
;;
h)
usage
;;
esac
done
# Get a list of devices
sds=$(kstat -l sderr:::class | awk -F: '{print $2}')
# Function to extract a value from kstat
get_kstat() {
IFS=$'\t' read _ value _ < <(kstat -p "$1")
read value <<< "$value"
echo "$value"
}
ret=0
err=''
# Loop the devices
while read sd; do
skip=false
# Chesk if the sd is blacklisted
IFS=',' read -ra ARR <<< "$skipsd"
for v in "${ARR[@]}"; do
if [[ "sd$sd" == "$v" ]]; then
skip=true
break
fi
done
$skip && continue
# Check the vendor, skip it if it's blacklisted
vendor=$(get_kstat "sderr:$sd::Vendor")
for v in "${skipvendors[@]}"; do
if [[ "$vendor" == "$v" ]]; then
skip=true
break
fi
done
$skip && continue
# Check for hard errors
hard_errors=$(get_kstat "sderr:$sd::Hard Errors")
if (( hard_errors > 0 )); then
# Append to `err` string
err=${err:-critical:}
err="$err sd $sd: $hard_errors hard errors;"
ret=2
fi
done <<< "$sds"
echo "${err:-ok: no hard errors found}"
exit "$ret"