blob: 32fc1683037c03de736265068790e22943714896 (
plain)
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
|
#!/usr/bin/env bash
stat=/proc/mdstat
if [ ! -e "$stat" ]; then
echo "WARNING: $stat does not exist"
exit 1
fi
if [ ! -r "$stat" ]; then
echo "WARNING: cannot read $stat"
exit 1
fi
count=$(grep ^md -c "$stat")
if [ "$count" -eq 0 ]; then
echo 'WARNING: no arrays found.'
exit 1
elif [ "$count" -eq 1 ]; then
out="Linux Software RAID: $count array"
else
out="Linux Software RAID: $count arrays"
fi
degrated=$(grep -c '\[.*_.*\]' "$stat")
recovering=$(awk '/recovery/ {print $4}' "$stat")
resyncing=$(awk '/resync/ {print $4}' "$stat")
if [ -n "$recovering" ]; then
out="$out, recovering: $recovering"
elif [ -n "$resyncing" ]; then
out="$out, resyncing: $resyncing"
elif [ "$degrated" -gt 0 ]; then
out="$out, degrated: $degrated"
fi
if [ "$degrated" -gt 0 ]; then
echo "CRITICAL: $out."
exit 2
fi
if [ -n "$recovering$resyncing" ]; then
echo "WARNING: $out."
exit 1
fi
echo "OK: $out."
exit 0
|