forked from Voxer/nagios-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_hard_errors
executable file
·88 lines (74 loc) · 1.66 KB
/
check_hard_errors
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/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 <[email protected]>
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"