summaryrefslogtreecommitdiffstats
path: root/abs/core/xymon/xymon-smart.sh
blob: 8998778bca844e7a464521b789c44c1a506e44c9 (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
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
#!/bin/sh

# NOTE: Must be run as root, so you probably need to setup sudo for this.

if test -f /tmp/dres; then rm -f /tmp/dres; fi

ls /dev/disk/by-id/* | grep -ve '-part' -ve '/wwn-' -ve '/md-' |
while read DISK
do
    DISKDEV=`ls -l $DISK | awk -F/ '{print $NF}'`

    #check if device is optical
    if [[ $DISKDEV == "sr"* ]]
    then
        continue
    fi

    #check if device is mounted
    if ! mount | grep -q /dev/$DISKDEV
    then
        # check if device is used by mdadm
        if ! cat /proc/mdstat | grep -q $DISKDEV
        then
            continue
        fi
    fi

    DRES=`sudo /usr/bin/smartctl -H -n standby $DISK`
    DCODE=$?

    #check if SMART is disabled and enable
    if [[ $DRES == *"SMART Disabled. Use option -s with argument 'on'"* ]]
    then
        sudo /usr/bin/smartctl -s on $DISK
        DRES=`sudo /usr/bin/smartctl -H -n standby $DISK`
        DCODE=$?
    fi

    DSTBY=$(( $DCODE & 2 ))
    DFAIL=$(( $DCODE & 8 ))
    DWARN=$(( $DCODE & 32 ))

    if test $DSTBY -ne 0
    then
        COLOR="4&clear"
    elif test $DFAIL -ne 0
    then
        COLOR="1&red"
    elif test $DWARN -ne 0
    then
        COLOR="2&yellow"
    else
        COLOR="3&green"
    fi

    echo "${COLOR} $DISK (/dev/$DISKDEV)"

    echo "${COLOR} $DISK (/dev/$DISKDEV)" | cut -c2- >>/tmp/dres
    echo "" >>/tmp/dres
    echo "$DRES" | egrep -v "^smartctl|^Copyright|^$|^===" >>/tmp/dres
    echo "-----------------------------------------------------------------------------" >>/tmp/dres
    echo "" >>/tmp/dres
    echo "" >>/tmp/dres
done >/tmp/dcheck

COLOR=`cat /tmp/dcheck | awk '{print $1}' | sort | uniq | head -1 | cut -c3-`

$XYMON $XYMSRV "status ${MACHINE}.smart ${COLOR} SMART Health Check

`cat /tmp/dcheck | cut -c2-`

============================== Detailed status ==============================

`cat /tmp/dres`
"

rm -f /tmp/dres /tmp/dcheck

exit 0