Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / agents / plugins / smart
blob6e28c91faf990e511e00ab7b98081c9512719aa9
1 #!/bin/bash
2 # +------------------------------------------------------------------+
3 # | ____ _ _ __ __ _ __ |
4 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
5 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
6 # | | |___| | | | __/ (__| < | | | | . \ |
7 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
8 # | |
9 # | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
10 # +------------------------------------------------------------------+
12 # This file is part of Check_MK.
13 # The official homepage is at http://mathias-kettner.de/check_mk.
15 # check_mk is free software; you can redistribute it and/or modify it
16 # under the terms of the GNU General Public License as published by
17 # the Free Software Foundation in version 2. check_mk is distributed
18 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
19 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
20 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
21 # tails. You should have received a copy of the GNU General Public
22 # License along with GNU Make; see the file COPYING. If not, write
23 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
24 # Boston, MA 02110-1301 USA.
29 # This will be called on LSI based raidcontrollers and accesses
30 # the SMART data of SATA disks attached to a SAS Raid HBA via
31 # SCSI protocol interface.
32 megaraid_info()
34 #PDINFO=$(MegaCli -PDlist -a0)
35 if [ -z "$1" ]; then
36 PDINFO=$(megacli -PDlist -a0 -NoLog)
37 else
38 PDINFO=$($1 -PDlist -a0 -NoLog)
41 echo "$PDINFO" | \
42 while read line ; do
43 case "$line" in
44 # FIRST LINE
45 "Enclosure Device ID"*) #Enclosure Device ID: 252
46 ENC=$( echo "$line" | awk '{print $4}')
47 unset SLOT LOG_DEV_ID VEND MODEL
49 "Slot Number"*) #Slot Number: 7
50 SLOT=$( echo "$line" | awk '{print $3}')
52 # Identify the logical device ID. smartctl needs it to access the disk.
53 "Device Id"*) #Device Id: 19
54 LOG_DEV_ID=$( echo "$line" | awk '{print $3}')
56 "PD Type"*) #PD Type: SATA
57 VEND=$( echo "$line" | awk '{print $3}')
59 # This is the last value, generate output here
60 "Inquiry Data"*)
61 #Inquiry Data: WD-WCC1T1035197WDC WD20EZRX-00DC0B0 80.00A80
62 # $4 seems to be better for some vendors... wont be possible to get this perfect.
63 MODEL=$( echo "$line" | awk '{print $3}')
65 # /dev/sdc ATA SAMSUNG_SSD_830 5 Reallocated_Sector_Ct 0x0033 100 100 010 Pre-fail Always -
66 smartctl -d megaraid,${LOG_DEV_ID} -v 9,raw48 -A /dev/sg0 | \
67 grep Always | egrep -v '^190(.*)Temperature(.*)' | \
68 sed "s|^|Enc${ENC}/Slot${SLOT} $VEND $MODEL |"
70 esac
71 done
75 # Only handle always updated values, add device path and vendor/model
76 if which smartctl > /dev/null 2>&1 ; then
78 # if the 3ware-utility is found
79 # get the serials for all disks on the controller
81 if which tw_cli > /dev/null 2>&1 ; then
82 # support for only one controller at the moment
83 TWAC=$(tw_cli show | awk 'NR < 4 { next } { print $1 }' | head -n 1)
85 # - add a trailing zero to handle case of unused slot
86 # trailing zeros are part of the device links in /dev/disk/by-id/... anyway
87 # - only the last 9 chars seem to be relevant
88 # (hopefully all this doesn't change with new kernels...)
89 eval `tw_cli /$TWAC show drivestatus | grep -E '^p[0-9]' | awk '{print $1 " " $7 "0"}' | while read twaminor serial ; do
90 twaminor=${twaminor#p}
91 serial=${serial:(-9)}
92 serial=AMCC_${serial}00000000000
93 echo "$serial=$twaminor"
94 done`
95 else:
96 echo "tw_cli not found" >&2
99 echo '<<<smart>>>'
100 SEEN=
101 for D in /dev/disk/by-id/{scsi,ata}-*; do
102 [ "$D" != "${D%scsi-\*}" ] && continue
103 [ "$D" != "${D%ata-\*}" ] && continue
104 [ "$D" != "${D%-part*}" ] && continue
105 N=$(readlink $D)
106 N=${N##*/}
107 if [ -r /sys/block/$N/device/vendor ]; then
108 VEND=$(tr -d ' ' < /sys/block/$N/device/vendor)
109 else
110 # 2012-01-25 Stefan Kaerst CDJ - in case $N does not exist
111 VEND=ATA
113 if [ -r /sys/block/$N/device/model ]; then
114 MODEL=$(sed -e 's/ /_/g' -e 's/_*$//g' < /sys/block/$N/device/model)
115 else
116 MODEL=$(smartctl -a $D | grep -i "device model" | sed -e "s/.*:[ ]*//g" -e "s/\ /_/g")
118 # Excluded disk models for SAN arrays or certain RAID luns that are also not usable..
119 if [ "$MODEL" = "iSCSI_Disk" -o "$MODEL" = "LOGICAL_VOLUME" ]; then
120 continue
123 # Avoid duplicate entries for same device
124 if [ "${SEEN//.$N./}" != "$SEEN" ] ; then
125 continue
127 SEEN="$SEEN.$N."
129 # strip device name for final output
130 DNAME=${D#/dev/disk/by-id/scsi-}
131 DNAME=${DNAME#/dev/disk/by-id/ata-}
132 # 2012-01-25 Stefan Kaerst CDJ - special option in case vendor is AMCC
133 CMD=
134 if [ "$VEND" == "AMCC" -a -n "$TWAC" ]; then
135 DNAME=${DNAME#1}
136 [ -z "${!DNAME}" ] && continue
137 CMD="smartctl -d 3ware,${!DNAME} -v 9,raw48 -A /dev/twa0"
138 # create nice device name including model
139 MODEL=$(tw_cli /$TWAC/p${!DNAME} show model | head -n 1 | awk -F= '{ print $2 }')
140 MODEL=${MODEL## }
141 MODEL=${MODEL// /-}
142 DNAME=${DNAME#AMCC_}
143 DNAME="AMCC_${MODEL}_${DNAME%000000000000}"
144 elif [ "$VEND" != "ATA" ] ; then
145 TEMP=
146 # create temperature output as expected by checks/smart
147 # this is a hack, TODO: change checks/smart to support SCSI-disks
148 eval `smartctl -d scsi -i -A $D | while read a b c d e ; do
149 [ "$a" == Serial ] && echo SN=$c
150 [ "$a" == Current -a "$b" == Drive -a "$c" == Temperature: ] && echo TEMP=$d
151 done`
152 [ -n "$TEMP" ] && CMD="echo 194 Temperature_Celsius 0x0000 000 000 000 Old_age Always - $TEMP (0 0 0 0)"
153 DNAME="${VEND}_${MODEL}_${SN}"
154 else
155 CMD="smartctl -d ata -v 9,raw48 -A $D"
158 [ -n "$CMD" ] && $CMD | grep Always | egrep -v '^190(.*)Temperature(.*)' | sed "s|^|$DNAME $VEND $MODEL |"
159 done 2>/dev/null
162 # Call MegaRaid submodule if conditions are met
163 if type MegaCli >/dev/null 2>&1; then
164 MegaCli_bin="MegaCli"
165 elif type MegaCli64 >/dev/null 2>&1; then
166 MegaCli_bin="MegaCli64"
167 elif type megacli >/dev/null 2>&1; then
168 MegaCli_bin="megacli"
169 else
170 MegaCli_bin="unknown"
173 if [ "$MegaCli_bin" != "unknown" ]; then
174 megaraid_info "$MegaCli_bin"
176 else
177 echo "ERROR: smartctl not found" >&2