-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathcheck_smart.sh
executable file
·86 lines (76 loc) · 1.79 KB
/
check_smart.sh
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
#!/usr/bin/env bash
#
# Check application disk(s) health
#
# Usage: check_smart.sh
# -h, --help Display this screen
#
# (c) 2015, Benjamin Dos Santos <[email protected]>
# https://github.com/bdossantos/nagios-plugins
#
while [[ -n "$1" ]]; do
case $1 in
--help | -h)
sed -n '2,10p' "$0" | tr -d '#'
exit 3
;;
*)
echo "Unknown argument: $1"
exec "$0" --help
exit 3
;;
esac
shift
done
if ! hash lsblk 2>/dev/null; then
echo 'UNKNOWN - Could not find `lsblk` utility'
exit 3
fi
if ! hash smartctl 2>/dev/null || [[ -x smartctl ]]; then
echo 'UNKNOWN - Could not find or execute `smartctl` utility'
exit 3
fi
smart_available=()
unknown_disks=()
unhealthy_disks=()
healthy_disks=()
disks=$(lsblk -nro NAME,TYPE | grep 'disk' | awk '{ print $1 }')
for disk in $disks; do
device="/dev/${disk}"
smart=$(smartctl -i "$device")
if echo "$smart" | grep -q 'SMART support is: Available'; then
smart_available=("${smart_available[@]}" "$device")
fi
done
for device in "${smart_available[@]}"; do
health=$(smartctl -a "$device")
if echo "$health" | grep -q 'ATA Error Count:'; then
unhealthy_disks=("${unhealthy_disks[@]}" "$device")
elif echo "$health" | grep -q 'No Errors Logged'; then
healthy_disks=("${healthy_disks[@]}" "$device")
else
unknown_disks=("${unknown_disks[@]}" "$device")
fi
done
if [[ ${#unhealthy_disks[@]} -gt 0 ]]; then
output=$(
IFS=,
echo "${unhealthy_disks[*]}"
)
echo "CRITICAL - unhealthy disk(s) found : ${output}"
exit 2
fi
if [[ ${#unknown_disks[@]} -gt 0 ]]; then
output=$(
IFS=,
echo "${unknown_disks[*]}"
)
echo "CRITICAL - unknown disk(s) found : ${output}"
exit 2
fi
output=$(
IFS=,
echo "${healthy_disks[*]}"
)
echo "OK - disk(s) look healthy : ${output}"
exit 0