'******************************************************************** '* '* Henrik Møller Jørgensen : Check for SMARt/PFA errors on harddisks '* '* Module Name: smartpfa.vbs '* '* Arguments: none '* '* Parameters : none '* '* Output : Nagios compatible Exit code (Ok, Warning, Critical or Unknown) '* '* and output message with monitored processes and results. '* '* Example: '* '* OK : No PFA/S.M.A.R.T errors detected; '* '* '* License GNU free license, no warranties '******************************************************************** Err.Clear 'Constant declaration CONST Exit_OK = 0 CONST Exit_Warning = 1 CONST Exit_Critical = 2 CONST Exit_Unknown = 3 strComputer = "." Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\wmi") Set Fails = objWMIService.ExecQuery ("Select * from MSStorageDriver_FailurePredictStatus") 'Now we have queried the SMART status for the harddisks 'We are facing that if there are no failures, then the result is NULL 'So we set errorcount=0 and loop through the fails 'If there are no fails, then we simply skip to reporting 0 errorcount=0 disksreporting =0 on error resume next for each Fail in Fails IF (Err.Number = 0) AND ISObject(Fail) Then disksreporting=disksreporting+1 ' debugging - see actual failed disks, hoping it is never needed ' With Fail ' WScript.Echo .Active ' WScript.Echo .InstanceName ' WScript.Echo "predictfail:" & .PredictFailure ' WScript.Echo .Reason ' End With if Fail.PredictFailure Then errorcount=errorcount+1 end if end if next 'debug wscript.echo errorcount 'Cleans up a little Set objWMIService = Nothing Set Fails = Nothing 'Treats results If disksreporting=0 Then wscript.echo "WARNING : No disks report SMART status" Wscript.Quit(Exit_Warning) ElseIf errorcount=0 Then wscript.echo "OK : No PFA/S.M.A.R.T errors detected" Wscript.Quit(Exit_OK) ElseIf errorcount >0 Then wscript.echo "CRITICAL : " & errorcount & "harddisks reporting S.M.A.R.T/PFA failures" Wscript.Quit(Exit_Critical) Else wscript.echo "UNKNOWN : PFA something went wrong" wscript.Quit(Exit_Unknown) End If ' This line should never been executed wscript.Quit(Exit_Unknown)