Skip to content

Commit ad11cd2

Browse files
committed
Small fixes for devices which don't support SMART
* initialise smart_healthy to -1, since an int defaults to 0 if empty, which broke some logic further down; as a result we no longer emit healthy=0 for devices with no SMART support. * add a return to parse_smartctl_info to indicate if the device supports smart. if it doesn't, don't bother pulling stats for it
1 parent b323e37 commit ad11cd2

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

smartmon.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ parse_smartctl_scsi_attributes() {
109109
}
110110

111111
parse_smartctl_info() {
112-
local -i smart_available=0 smart_enabled=0 smart_healthy=
112+
local -i smart_available=0 smart_enabled=0 smart_healthy=-1
113113
local disk="$1" disk_type="$2"
114114
local model_family='' device_model='' serial_number='' fw_version='' vendor='' product='' revision='' lun_id=''
115115
while read -r line; do
@@ -147,7 +147,12 @@ parse_smartctl_info() {
147147
echo "device_info{disk=\"${disk}\",type=\"${disk_type}\",vendor=\"${vendor}\",product=\"${product}\",revision=\"${revision}\",lun_id=\"${lun_id}\",model_family=\"${model_family}\",device_model=\"${device_model}\",serial_number=\"${serial_number}\",firmware_version=\"${fw_version}\"} 1"
148148
echo "device_smart_available{disk=\"${disk}\",type=\"${disk_type}\"} ${smart_available}"
149149
echo "device_smart_enabled{disk=\"${disk}\",type=\"${disk_type}\"} ${smart_enabled}"
150-
[[ "${smart_healthy}" != "" ]] && echo "device_smart_healthy{disk=\"${disk}\",type=\"${disk_type}\"} ${smart_healthy}"
150+
[[ "${smart_healthy}" != "-1" ]] && echo "device_smart_healthy{disk=\"${disk}\",type=\"${disk_type}\"} ${smart_healthy}"
151+
if [[ "${smart_available}" == 1 ]]; then
152+
return 0
153+
else
154+
return 1
155+
fi
151156
}
152157

153158
output_format_awk="$(
@@ -188,8 +193,8 @@ for device in ${device_list}; do
188193
echo "device_active{disk=\"${disk}\",type=\"${type}\"}" "${active}"
189194
# Skip further metrics to prevent the disk from spinning up
190195
test ${active} -eq 0 && continue
191-
# Get the SMART information and health
192-
smartctl -i -H -d "${type}" "${disk}" | parse_smartctl_info "${disk}" "${type}"
196+
# Get the SMART information and health; if the device doesn't support SMART, skip to next device
197+
smartctl -i -H -d "${type}" "${disk}" | parse_smartctl_info "${disk}" "${type}" || continue
193198
# Get the SMART attributes
194199
case ${type} in
195200
sat) smartctl -A -d "${type}" "${disk}" | parse_smartctl_attributes "${disk}" "${type}" ;;

0 commit comments

Comments
 (0)