' ========================================================= ' Script to read backup_exec log files ' arguments : ' /w : warning level in days ' /c : critical level in days ' /i : weekdays to ignore backup state, ' ========================================================= dim output ' Setlocale must be the same as the DateTime used in the backupexec logfile (defaul en-us (1033)) SetLocale("en-us") set output = wscript.stdout ' Required Variables Const PROGNAME = "check_backupexec" Const VERSION = "0.0.1" Const DEBUGMODE = 0 ' Default settings for your script. backupexeclogfilepath = "D:\Program Files\Symantec\Backup Exec\Data" jobname = "Week_Backupjob" 'Cons for return val's Const OK = 0 Const WARNING = 1 Const CRITICAL = 2 Const UNKNOWN = 3 Set Args = WScript.Arguments If (Args.Count > 0) then backupexeclogfilepath = Args.Item(0) End If If (Args.Count > 0) then jobname = Args.Item(1) End If ' Default settings and variable initialization intDaysSinceLastSuccessDateTime = 9999 intDaysSinceLastFailedDateTime = 9999 intBackupWarning = 1 intBackupCritical = 3 intGbBackedUp = 0 stringDaystoIgnore = "" return_code = UNKNOWN msg = "Error while loading backup exec xml files" '### If we define /warning /critical on commandline it should override the script default. ### If Args.Named.Exists("w") Then intBackupWarning = cint(Args.Named("w")) If Args.Named.Exists("c") Then intBackupCritical = cint(Args.Named("c")) If Args.Named.Exists("i") Then stringTemperatureIgnoreIds = Args.Named("i") stringTemperatureIgnoreIds = "," + stringTemperatureIgnoreIds strBackupStartDateTime = "" strLastBackupEndDateTime = "" BackupFound = 0 Const ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject") Set folder = objFSO.GetFolder(backupexeclogfilepath ) for each file in folder.Files if ( lcase(objFSO.getExtensionName(file.path))="xml") then Set testfile = objFSO.OpenTextFile(file.path, 1, False, - 1) foundJobName = "" foundJobStartDateTime = "" foundJobEndDateTime = "" foundJob = 0 foundJobSuccessful = 0 strFoundBytesBackedup = "0" Do While Not testfile.AtEndOfStream strLine = testfile.readline '### Search for lines with "" ### If(InStr(strLine, "") > 0) Then foundJobName = Right (strLine, Len(strLine) - Instr(strLine,"Job name:") - 9) if foundJobName = jobname then foundJob = 1 If DEBUGMODE then output.writeline "Job Found in: "+ file.path end if end if if foundjob = 1 then BackupFound = 1 If(InStr(strLine, "Job completion status: Successful") > 0) Then foundJobSuccessful = 1 end if If(InStr(strLine, "Backup started on ") > 0) Then foundJobStartDateTime = Right (strLine, Len(strLine) - Instr(strLine,"on ") - 2) foundJobStartDateTime = Left (foundJobStartDateTime, Len(foundJobStartDateTime) - 1) foundJobStartDateTime = Replace (foundJobStartDateTime, " at", "") end if If(InStr(strLine, "Backup completed on ") > 0) Then foundJobEndDateTime = Right (strLine, Len(strLine) - Instr(strLine,"on ") - 2) foundJobEndDateTime = Left (foundJobEndDateTime, Len(foundJobEndDateTime) - 1) foundJobEndDateTime = Replace (foundJobEndDateTime, " at", "") '### Calculate days since last backup DateTime ### intDaysSinceBackupDateTime= int(DateDiff("h", foundJobEndDateTime, now())/24) end if If(InStr(strLine, "Verify completed on ") > 0) Then foundJobEndDateTime = Right (strLine, Len(strLine) - Instr(strLine,"on ") - 2) foundJobEndDateTime = Left (foundJobEndDateTime, Len(foundJobEndDateTime) - 1) foundJobEndDateTime = Replace (foundJobEndDateTime, " at", "") '### Calculate days since last backup DateTime ### intDaysSinceBackupDateTime= int(DateDiff("h", foundJobEndDateTime, now())/24) end if If(InStr(strLine, "Job started: ") > 0) Then foundJobStartDateTime = Right (strLine, Len(strLine) - Instr(strLine,", ") - 1) foundJobStartDateTime = Replace (foundJobStartDateTime, " at", "") end if If(InStr(strLine, "Job ended: ") > 0) Then foundJobEndDateTime = Right (strLine, Len(strLine) - Instr(strLine,", ") - 1) foundJobEndDateTime = Replace (foundJobEndDateTime, " at", "") '### Calculate days since last ackup DateTime ### intDaysSinceBackupDateTime= int(DateDiff("h", foundJobEndDateTime, now())/24) end if If(InStr(strLine, "Processed ") > 0) Then strFoundBytesBackedup = Right (strLine, Len(strLine) - Instr(strLine," ")) strFoundBytesBackedup = Left (strFoundBytesBackedup, Instr(strFoundBytesBackedup," ") - 1) end if end if Loop if foundjob = 1 then If DEBUGMODE then output.writeline "foundJobStartDateTime="+foundJobStartDateTime If DEBUGMODE then output.writeline "foundJobEndDateTime="+foundJobEndDateTime If DEBUGMODE then output.writeline "intDaysSinceBackupDateTime="+Cstr(intDaysSinceBackupDateTime) If DEBUGMODE then output.writeline "intDaysSinceLastSuccessDateTime="+Cstr(intDaysSinceLastSuccessDateTime) If DEBUGMODE then output.writeline "strFoundBytesBackedup="+strFoundBytesBackedup if (foundJobSuccessful = 1) then if (intDaysSinceLastSuccessDateTime > intDaysSinceBackupDateTime) then intDaysSinceLastSuccessDateTime = intDaysSinceBackupDateTime if (intDaysSinceLastSuccessDateTime < intDaysSinceLastFailedDateTime) then strBackupStartDateTime = foundJobStartDateTime strLastBackupEndDateTime = foundJobEndDateTime intGbBackedUp = int(int(strFoundBytesBackedup) / 1024 / 1024 / 1024) intElapsedDateTime= int(DateDiff("n", strBackupStartDateTime, strLastBackupEndDateTime)) end if end if else if (intDaysSinceLastFailedDateTime > intDaysSinceBackupDateTime) then intDaysSinceLastFailedDateTime = intDaysSinceBackupDateTime if (intDaysSinceLastFailedDateTime < intDaysSinceLastSuccessDateTime) then strBackupStartDateTime = foundJobStartDateTime strLastBackupEndDateTime = foundJobEndDateTime intGbBackedUp = int(int(strFoundBytesBackedup) / 1024 / 1024 / 1024) if (strBackupStartDateTime <> "") then if (strLastBackupEndDateTime <> "") then intElapsedDateTime= int(DateDiff("n", strBackupStartDateTime, strLastBackupEndDateTime)) end if end if end if end if end if end if testfile.close end if next '### Convert intDaysSinceLastSuccessDateTime to a string and if it's 9999 replace it by never successfull strDaysSinceLastSuccessDateTime = cstr (intDaysSinceLastSuccessDateTime) if (strDaysSinceLastSuccessDateTime = "9999") then strDaysSinceLastSuccessDateTime = "Never Successfull" end if '### Build a nice looking and consistent date time string if (strLastBackupEndDateTime <> "") then strLastBackupEndDateTime = cstr(Day(strLastBackupEndDateTime)) + "-" + cstr(Month(strLastBackupEndDateTime)) + "-" + cstr(Year(strLastBackupEndDateTime)) + " " + FormatDateTime(strLastBackupEndDateTime,vbShortTime) else strLastBackupEndDateTime = "Never" End If '### Generate returncodes and messages depending on warning and critical levels if (intDaysSinceLastSuccessDateTime < intBackupWarning) then msg = "Job: " + jobname + " last ended on " + strLastBackupEndDateTime + " was Successfull" return_code = OK end if if (intDaysSinceLastSuccessDateTime >= intBackupWarning) then msg = "Job: " + jobname + " last ended on " + strLastBackupEndDateTime + " was Successfull but to long ago" return_code = WARNING end if if (intDaysSinceLastSuccessDateTime >= intBackupCritical) then msg = "Job: " + jobname + " last ended on " + strLastBackupEndDateTime + " was Successfull but to long ago" return_code = CRITICAL end if if (intDaysSinceLastFailedDateTime < intDaysSinceLastSuccessDateTime) then msg = "Job: " + jobname + " ended on " + strLastBackupEndDateTime + " was FAILED" return_code = CRITICAL end if msg = msg + ", Days since last successfull backup: " + strDaysSinceLastSuccessDateTime + ", Bytes Backed Up: " + cstr(intGbBackedUp) + "GB, Elapsed Time: " + cstr(intelapsedDateTime) + " Minutes." if (intDaysSinceLastSuccessDateTime < 0) then msg = "CRITICAL" + ", Could not determine last DateTime of Job: " + jobname return_code = CRITICAL end if if (Backupfound = 0) then msg = "CRITICAL" + ", Job was not found! : " + jobname return_code = CRITICAL end if ' Nice Exit with msg and exitcode output.writeline msg WScript.quit return_code