hw-test/scripts/parse-smart-attr

88 lines
2 KiB
Text
Raw Normal View History

2016-12-15 23:07:30 -06:00
#!/usr/bin/awk -f
BEGIN {
ACTIVE = 0;
ATTRIBUTE_NAME = 2;
VALUE = 4;
WORST = 5;
THRESH = 6;
FAIL = 7;
RAW_VALUE = 8;
2016-12-16 05:52:04 -06:00
# Threshold warning values for new drives
Error_Rate_Thresh = 1000000; #1M
Power_On_Thresh = 720; #30d
Power_Cycle_Thresh = 30;
Hardware_ECC_Thresh = 1000000; #1M
2016-12-22 23:27:50 -06:00
# https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/pluginapi.html
RET_OK = 0;
RET_WARN = 1;
RET_CRIT = 2;
RET_UNKN = 3;
RET = RET_OK;
}
END {
exit RET;
2016-12-16 05:52:04 -06:00
}
function warn_raw_value(thresh) {
2016-12-22 23:27:50 -06:00
if ( $RAW_VALUE > thresh ) {
2016-12-16 05:52:04 -06:00
print "WARNING : " $ATTRIBUTE_NAME " " $RAW_VALUE ;
2016-12-22 23:27:50 -06:00
if ( RET < RET_WARN )
RET = RET_WARN;
}
2016-12-16 05:52:04 -06:00
}
function crit_raw_value(thresh) {
2016-12-22 23:27:50 -06:00
if ( $RAW_VALUE > thresh ) {
2016-12-16 05:52:04 -06:00
print "ERROR : " $ATTRIBUTE_NAME " " $RAW_VALUE ;
2016-12-22 23:27:50 -06:00
if ( RET < RET_CRIT )
RET = RET_CRIT;
}
2016-12-15 23:07:30 -06:00
}
/=== START OF READ SMART DATA SECTION ===/ { ACTIVE = 1}
/TYPE[[:space:]]+UPDATED[[:space:]]+WHEN/ {
print "Wrong format. Please use smartctl -A -f brief";
2016-12-22 23:27:50 -06:00
exit RET_UNKN;
2016-12-15 23:07:30 -06:00
}
2016-12-16 05:52:04 -06:00
#(Raw Read|Seek) Error Rate
/^ (1|7)/ { warn_raw_value(Error_Rate_Thresh); }
#Power On Hours
/^ 9/ { warn_raw_value(Power_On_Thresh); }
#Power Cycle Count
/^ 12/ { warn_raw_value(Power_Cycle_Thresh); }
#Hardware ECC Recovered
/^195/ { warn_raw_value(Hardware_ECC_Thresh); }
#Reallocated Sector
/^ 5/ { crit_raw_value(0); }
#Spin Retry Count
/^ 10/ { crit_raw_value(0); }
#Runtime Bad Block
/^183/ { crit_raw_value(0); }
#End-to-End Error
/^184/ { crit_raw_value(0); }
#Reported Uncorrect
/^187/ { crit_raw_value(0) ;}
#Command Timeout
/^188/ { crit_raw_value(0); }
#Reallocation Event Count
/^196/ { crit_raw_value(0); }
#Current Pending Sector
/^197/ { crit_raw_value(0); }
#Offline Uncorrectable
/^198/ { crit_raw_value(0); }
#Soft Read Error Rate
/^201/ { crit_raw_value(0); }
#Drive Life Protection Status
/^230/ { crit_raw_value(0); }
2016-12-15 23:07:30 -06:00
2016-12-16 08:02:21 -06:00
/^[ ]*[0-9]+ [0-9a-zA-Z_]+ / {
2016-12-22 23:27:50 -06:00
if ($WORST < $THRESH) {
2016-12-16 05:52:04 -06:00
print "ERROR : " $ATTRIBUTE_NAME " " $WORST " < " $THRESH " " $FAIL ;
2016-12-22 23:27:50 -06:00
if ( RET < RET_CRIT )
RET = RET_CRIT;
}
2016-12-16 05:52:04 -06:00
}
2016-12-15 23:07:30 -06:00