#!/usr/bin/awk -f BEGIN { ACTIVE = 0; ATTRIBUTE_NAME = 2; VALUE = 4; WORST = 5; THRESH = 6; FAIL = 7; RAW_VALUE = 8; # 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 # 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; } function warn_raw_value(thresh) { if ( $RAW_VALUE > thresh ) { print "WARNING : " $ATTRIBUTE_NAME " " $RAW_VALUE ; if ( RET < RET_WARN ) RET = RET_WARN; } } function crit_raw_value(thresh) { if ( $RAW_VALUE > thresh ) { print "ERROR : " $ATTRIBUTE_NAME " " $RAW_VALUE ; if ( RET < RET_CRIT ) RET = RET_CRIT; } } /=== START OF READ SMART DATA SECTION ===/ { ACTIVE = 1} /TYPE[[:space:]]+UPDATED[[:space:]]+WHEN/ { print "Wrong format. Please use smartctl -A -f brief"; exit RET_UNKN; } #(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); } /^[ ]*[0-9]+ [0-9a-zA-Z_]+ / { if ($WORST < $THRESH) { print "ERROR : " $ATTRIBUTE_NAME " " $WORST " < " $THRESH " " $FAIL ; if ( RET < RET_CRIT ) RET = RET_CRIT; } }