generateReport.vbs

25 02 2010

Below is the code for the generateReport.vbs file which is the primary script for generating automatic Netbackup reports. This one is pretty length so check it out after the break…

Sadly the script may cut off some lines. If you’d like a copy of the script to play around with drop me an email…

1:  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
2:  ' GENERATE LOG FILES
3:  Option Explicit
4:  Const fileServerList = "servers.txt"
5:  'On Error Resume Next
6:  'Overview status variables
7:  Dim ov_func, ov_status, ov_fail, ov_all, ov_all_status
8:  Dim WshShell, emailBody, filetxt, statusFile, fileToday
9:  Set WshShell = WScript.CreateObject("WScript.Shell")
10:  Set objFSO = CreateObject("Scripting.FileSystemObject")
11:  Set statusFile = objFSO.CreateTextFile("reportsbackupStatus.txt", True)
12:  Set filetxt = objFSO.CreateTextFile("reportsarchivebackupReport_" & Year(Now) & Month(Now) & Day(Now) & ".html", True)
13:  Set fileToday = objFSO.CreateTextFile("reportstoday.html", True)
14:  emailBody = ""
15:  '''''''''''''''''''''''''''''''''''''''''''''''''''''
16:  ' WE ARE NOW GOING TO USE EXCEL SHEETS TO REPORT
17:  ''dim objExcel, objBook, objSheet
18:  ''Set objExcel = CreateObject("Excel.Application")
19:  ''objBook = objExcel.Workbooks.Add()
20:  ''objSheet = objBook.Worksheets.Item(1)
21:  ''objExcel.Visible = False
22:  ''objExcel.Cells(1, 1).Value = "Test value"
23:  '''''''''''''''''''''''''''''''''''''''''''''''''''''
24:  Dim startDate, endDate, prevDay, numDays
25:  'Dates should be in the format mm/dd/yyyy
26:  'Times should be in the format HH:mm:ss
27:  endDate = month(now) & "/" & Day(now) & "/" & Year(now) & " " & "17:00:00"
28:  'Now figure out if we need the error log from just last night or from the whole weekend
29:  If Weekday(now) = 2 then '2 = Monday
30:       numDays = -3 'take us back 3 days to Friday
31:  Else
32:       numDays = -1 'just take us back 1 day to yesterday
33:  End If
34:  prevDay = DateAdd("d", numDays, now)
35:  startDate = CStr(month(prevDay) & "/" & Day(prevDay) & "/" & Year(prevDay) & " " & "17:00:00")
36:  'WScript.Echo "startDate = " & startDate
37:  'WScript.Echo "endDate = " & endDate
38:  'WScript.Echo "activity_errors.bat " & startDate & " " & endDate
39:  'Run the batch scripts with our new date parameters to generate our log files...
40:  backupLogs
41:  WshShell.Run ("jobs_summary.bat")
42:  WshShell.Run ("jobs_report.bat")
43:  WshShell.Run ("activity_errors.bat """ & startDate & """ """ & endDate & """")
44:  'Wait 90 seconds (!!!) for the file to close before we try and read it
45:  WScript.Sleep 90000
46:  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
47:  ' START GENERATING THE HTML HEADER INFO TO THE REPORT FILE
48:  ' #Write HTML header to Log
49:  writeLog "b", "<!DOCTYPE html PUBLIC ""-//W3C//DTD HTML 4.01//EN"">" & _
50:       "<html>" & _
51:       "<head>" & _
52:        "<title>Backup Report</title>" & _
53:        "<style type=""text/css"">" & _
54:             "body {" & _
55:              "font-family: Calibri, Arial, Helvetica; " & _
56:              "color: black;" & _
57:              "font-size: xx-small;" & _
58:                   "background-color: #FFFFFF }" & _
59:             " p {" & _
60:         "     font-size: x-small }" & _
61:             " .big {" & _
62:         "     font-size: x-small;" & _
63:         "     font-weight: bold }" & _
64:             " table {" & _
65:              "      padding: 0px ;" & _
66:              "      border-spacing: 0px ;" & _
67:              "      empty-cells: hide ;" & _
68:              "      border: 1px solid #AAAAAA }" & _
69:             " td {" & _
70:              "      background-color: #EEEEEE;" & _
71:            "      vertical-align: top }" & _
72:        "</style>" & _
73:       "</head>" & _
74:       "<body>"
75:  writeLog "e", "<p><b>*** This email is now automatically generated ***</b><br><br>Please see below for today's backup report.</p>"
76:  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
77:  ' READ IN LIST OF SERVERS AND GENERATE Array
78:  Dim objReadFile, nSched, strServer, aSvrStatus, objFSO, count, strPolicy, aLine, strLine, strGroup
79:  Const ForReading = 1
80:  'Create object for reading from our log file list
81:  Set objReadFile = objFSO.OpenTextFile(fileServerList, ForReading, True)
82:  count = 0
83:  ReDim aSvrStatus(5,count)
84:  ReDim aSvrLogs(3,count)
85:  'aSvrStatus(0,n) = server name
86:  'aSvrStatus(1,n) = catalog policy
87:  'aSvrStatus(2,n) = status code
88:  'aSvrStatus(3,n) = total bytes backed up
89:  'aSvrStatus(4,n) = category/group (e.g. Front Office, Back Office, IT...)
90:  'aSvrLogs(0,n) = server name
91:  'aSvrLogs(1,n) = warning/error messages
92:  'aSvrLogs(2,n) = warning/error messages
93:  Do
94:       strLine = objReadFile.ReadLine
95:       'Check for comments and blank lines...
96:       If strLine = "" Or Left(strLine, 1) = "#" Or isNull(strLine) Then
97:            'do Nothing
98:       Else
99:            aLine = split(strLine, ",")
100:            nSched = aLine(0)
101:            strPolicy = aLine(1)
102:            strServer = aLine(2)
103:            strGroup = aLine(3)
104:            'This has been changed slightly. The hex code now denotes if the REPORT should be run today for this particular client
105:            If logToday(nSched) Then
106:                 'wscript.Echo "nSched = " & nSched
107:                 'wscript.Echo "strPolicy = " & strPolicy
108:                 'wscript.Echo "strServer = " & strServer
109:                 ReDim preserve aSvrStatus(5, count)
110:                 aSvrStatus(0, count) = strServer
111:                 aSvrStatus(1, count) = strPolicy
112:                 aSvrStatus(4, count) = strGroup
113:                 'WScript.Echo count & " - " & aSvrStatus(0, count) & ", " & aSvrStatus(1, count)
114:                 count = count + 1
115:            Else
116:                 'do nothing
117:            End If
118:       End If
119:  Loop Until objReadFile.AtEndOfStream = True
120:  Dim numServers
121:  numServers = count
122:  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
123:  ' FIRST OFF, CREATE A LIST OF JUMP LINKS
124:  jumpLinks
125:  Sub jumpLinks()
126:       writeLog "f", "<b>Jump to...</b><br/>"
127:       Dim count, prevGroup
128:       For count = 0 To numServers - 1
129:            'If the group name In the current element of the array is not the same as before, close and start a new table
130:            If prevGroup <> aSvrStatus(4, count) Then
131:                 writeLog "f", "- <a href=""#" & aSvrStatus(4, count) & """>" & aSvrStatus(4, count) & "</a><br/>"
132:            End If
133:            prevGroup = aSvrStatus(4, count)
134:       Next
135:  End Sub
136:  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
137:  ' SECONDLY, SIMPLY SPIT OUT THE DETAILS OF THE SUMMARY.LOG FILE
138:  'Create object for reading from our log file list
139:  Set objReadFile = objFSO.OpenTextFile("logssummary.log", ForReading, True)
140:  Dim summaryCount
141:  summaryCount = 0
142:  writeLog "b", "<p>"
143:  Do
144:       strLine = objReadFile.readLine
145:       If summaryCount = 0 Then
146:            'Ignore the first line and output it as it appears
147:            writeLog "b", "<b>" & strLine & "</b><table>"
148:       Else
149:            'if line is blank then skip it
150:            If strLine <> "" and not IsNull(strLine) Then
151:                 'Subsqeuent lines need to be split to seperate the category and the total
152:                 strLine = Replace(strLine, "Partially Successful", "Partially-Successful")
153:                 strLine = Replace(strLine, " ", "")
154:                 aLine = Split(strLine, ":")
155:                 writeLog "b", "<tr><td>" & aLine(0) & "&nbsp;</td><td>&nbsp;" & aLine(1) & "&nbsp;</td></tr>"
156:            End If
157:       End If
158:       summaryCount = summaryCount + 1
159:  Loop Until objReadFile.AtEndOfStream = True
160:  writeLog "b", "</table><i>Please note: more than one ""job"" exists per backup client.</i><br><br>"
161:  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
162:  ' NOW WE HAVE OUR ARRAY WE CAN PARSE THE REPORT.CSV FILE FOR EACH SERVER STATUS
163:  Set objReadFile = objFSO.OpenTextFile("logsreport.csv", ForReading, True)
164:  Dim currentStatus
165:  Do
166:       aLine = split(objReadFile.ReadLine, ",")
167:       'For every line in the report, we need to loop through the array searching for a match
168:       For count = 0 To numServers - 1
169:            'aLine(6) = Server name
170:            'aLine(4) = Policy name
171:            'aLine(16) = bytes copied
172:            'If the server name and policy name match then we update information
173:            If aSvrStatus(0, count) = aLine(6) And aSvrStatus(1, count) = aLine(4) Then
174:                 'Check current status. If the current status is less that the new one from this line in the report log, then override it.
175:                 'The reason is that we want to know about ANY errors, so we don't care if drive C backed up successfully if drive D had issues.
176:                 If aSvrStatus(2, count) = "" Or aSvrStatus(2, count) < aLine(3) Then
177:                      'If the status is blank, it MAY be in progress. Check the prev column too which will confirm this.
178:                      If aLine(2) = 1 And aLine(3) = "" Then
179:                           aSvrStatus(2, count) = "IP"
180:                      Else
181:                           'WScript.Echo aSvrStatus(0, count) & " currently: [" & aSvrStatus(2, count) & "]" & VbCrLf & "Changing to: [" & aLine(3) & "]"
182:                           aSvrStatus(2, count) = aLine(3)
183:                      End If
184:                 end If
185:                 'Calculate Total Bytes. Not used. Seems inaccurate.
186:                 aSvrStatus(3, count) = aSvrStatus(3, count) + aLine(16)
187:            End If
188:       Next
189:  Loop Until objReadFile.AtEndOfStream = True
190:  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
191:  ' GO THROUGH THE ERROR LOG AND MATCH UP SERVERS AND FAILED FILES
192:  Set objReadFile = objFSO.OpenTextFile("logserrors.log", ForReading, True)
193:  count = 0
194:  Dim bUseOther : bUseOther = False
195:  Dim otherCount : otherCount = 0
196:  ReDim aSvrLogs(2, count)
197:  ReDim aOtherErrors(otherCount)
198:  Do
199:       strLine = objReadFile.ReadLine
200:       bUseOther = False
201:       'Get the server name from the string. We find the position of the word "client" then add 7 to account for that word and the space after.
202:       'We then search for the semi-colon and finish at 1 before (so as not to include the semi-colon itself.
203:       If InStr(strLine, "client ") > 0 Then
204:            'Being as this text file can change format by quite a lot, we need to put a catch in here.
205:            'If we can't easily extract our information, simply append this error line to the aOtherErrors
206:            'array. At least then the error will still be captured.
207:            On Error Resume Next
208:            strServer = mid(strLine, InStr(strLine, "client ") + 7, inStr(strLine, ":") - InStr(strLine, "client ") - 7)
209:            If Err.Number <> 0 Then
210:                 bUseOther = True
211:            Else
212:                 'add this to the normal Array
213:                 strLine = Mid(strLine, inStr(strLine, ":") + 2)
214:                 If Err.Number <> 0 Then     bUseOther = True
215:            End If
216:            On Error GoTo 0
217:       Else
218:            bUseOther = True
219:       End If
220:       'Here we actually enter the data in to the correct array
221:       If Not bUseOther Then
222:            '???COULD WE LOOP THROUGH THE ARRAY LOOKING FOR DUPLICATE ENTRIES???
223:            redim preserve aSrvLogs(2, count)
224:            aSrvLogs(0, count) = strServer
225:            aSrvLogs(1, count) = strLine
226:            count = count + 1
227:       Else
228:            'If we can't easily extract a server name to associate this error to, store it in a seperate array.
229:            ReDim Preserve aOtherErrors(otherCount)
230:            aOtherErrors(otherCount) = strLine
231:            otherCount = otherCount + 1
232:       End If
233:  Loop Until objReadFile.AtEndOfStream = True
234:  'Call sub to output the details of the array (server names, errors, etc...)
235:  writeArray
236:  writeLog "e", "<br><p>Regards,<br><br><b>Systems Engineering, 2nd Line</b><br>Robert Half International</p>"
237:  writeLog "b", "</body>"
238:  writeLog "b", "</html>"
239:  filetxt.Close
240:  fileToday.Close
241:  'today.html is used by the Daily Checks spreadsheet
242:  objFSO.copyfile "reportsarchivebackupReport_" & Year(Now) & Month(Now) & Day(Now) & ".html", "reportsuk_netbackup.html"
243:  ''' EMAIL NO LONGER AUTOMATICALLY SENT. INSTEAD, THE TODAY.HTML FILE GENERATED IS USED BY ANOTHER SCRIPT
244:  ''' WHICH COLATES ALL NETBACKUP AND FILER SNAPSHOT REPORTS IN TO ONE.
245:  '''SendEmail
246:  'WScript.Echo "Done"
247:  Dim objRange
248:  ''Set objRange = objExcel.usedRange
249:  ''objRange.EntireColumn.AutoFit()
250:  ''objRange.AutoFit()
251:  ''objExcel.SaveAs("c:test.xls")
252:  ''objExcel.Quit()
253:  ' ******** END OF SCRIPT ! ********
254:  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
255:  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
256:  ' FUNCTIONS AND SUB-ROUTINES
257:  Function logToday(hexSchedule)
258:       'All this funtion does is return TRUE if the log file was supposed to have
259:       'been run "today" (or whatever schedule was passed to it).
260:       Dim hs : hs = hexSchedule
261:       Dim isInDate : isInDate = false
262:       Dim Sun : Sun = false
263:       Dim Mon : Mon = false
264:       Dim Tues : Tues = false
265:       Dim Wed : Wed = false
266:       Dim Thur : Thur = false
267:       Dim Fri : Fri = false
268:       Dim Sat : Sat = False
269:       Dim today : today = weekday(date())
270:       ' 1 = Sunday
271:       ' 2 = Monday
272:       ' 3 = Tuesday
273:       ' 4 = Wednesday
274:       ' 5 = Thursday
275:       ' 6 = Friday
276:       ' 7 = Saturday
277:       If hs >= 64 Then
278:            hs = hs - 64
279:            Sat = True
280:       End If
281:       If hs >= 32 Then
282:            hs = hs - 32
283:            Fri = True
284:       End If
285:       If hs >= 16 Then
286:            hs = hs - 16
287:            Thur = True
288:       End If
289:       If hs >= 8 Then
290:            hs = hs - 8
291:            Wed = True
292:       End If
293:       If hs >= 4 Then
294:            hs = hs - 4
295:            Tues = True
296:       End If
297:       If hs >= 2 Then
298:            hs = hs - 2
299:            Mon = True
300:       End If
301:       If hs >= 1 Then
302:            Sun = True
303:       End If
304:       'I've had to change this check. The servers.txt file now states
305:       'when REPORTS should be run, NOT when the clients were due to be backed up.
306:       'REPORTS DO NOT GET RUN AT THE WEEKEND SO WE DON'T NEED SATURDAY OR SUNDAY
307:       Select Case today
308:            Case 2
309:                 If Mon Then isInDate = true
310:            Case 3
311:                 If Tues Then isInDate = true
312:            Case 4
313:                 If Wed Then isInDate = true
314:            Case 5
315:                 If Thur Then isInDate = true
316:            Case 6
317:                 If Fri Then isInDate = true
318:       End select
319:       'MsgBox "logToday = " & isInDate
320:       logToday = isInDate
321:  End Function
322:  Sub writeLog(bEmail, strLine)
323:       'bEmail used to be a boolean variable hence the name
324:       'b = write to both email and HTML file
325:       'e = write to email body onlly
326:       'f = write to HTML file only
327:       Select Case bEmail
328:            Case "e"
329:                 emailBody = emailBody & strLine
330:                 fileToday.Writeline(strLine)
331:            Case "f"
332:                 filetxt.Writeline(strLine)
333:            Case "b"
334:                 emailBody = emailBody & strLine
335:                 fileToday.Writeline(strLine)
336:                 filetxt.Writeline(strLine)
337:       End select
338:  End Sub
339:  Sub backupLogs()
340:       'On Error Resume Next
341:       Dim dayName
342:       ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
343:       'Before we start copying all the log files, we want to move
344:       'the current log folder to a temporary backup folder...
345:       'WScript.Echo "Copying LOGS folder to backup location"
346:       If objFSO.FolderExists("logs") Then
347:            dayName = Weekday(date)
348:            'Take off a day (this will be YESTERDAYS logs we are moving)
349:            dayName = dayName - 1
350:            If dayName = 0 Then dayName = 7 '0 is invalid so go back a week
351:            Select Case dayName
352:                 Case 1
353:                      dayName = "Sunday"
354:                 Case 2
355:                      dayName = "Monday"
356:                 Case 3
357:                      dayName = "Tuesday"
358:                 Case 4
359:                      dayName = "Wednesday"
360:                 Case 5
361:                      dayName = "Thursday"
362:                 Case 6
363:                      dayName = "Friday"
364:                 Case 7
365:                      dayName = "Saturday"
366:            End Select
367:            'First check if our destination folder exists. If so, remove it.
368:            If objFSO.FolderExists("logs" & dayName) then
369:                 objFSO.DeleteFolder "logs" & dayName
370:            End If
371:            objFSO.CopyFolder "logs", "backups" & dayName, True
372:       End If
373:       'Make sure the LOGS folder exists before we begin copying logs in to it
374:       If Not objFSO.FolderExists("logs") Then
375:            objFSO.CreateFolder("logs")
376:       End If
377:       'WScript.Echo " Copied to logs" & dayName
378:       ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
379:  End Sub
380:  Sub SendEmail ()
381:       'Make sure the HTML file has been closed
382:       WScript.Sleep 5000
383:       Dim strComputer, objNetwork, emailSubject, objEmail
384:       Set objNetwork = WScript.CreateObject("WScript.Network")
385:       strComputer = objNetwork.ComputerName
386:       Dim today, backupType
387:       today = weekday(now())
388:       If today = 2 Then
389:            backupType = "Weekly "
390:       Else
391:            backupType = "Daily "
392:       End If
393:       emailSubject = backupType & ucase(Left(strComputer, 2)) & " Backup Report for " & Day(Now) & "/" & Month(Now) & "/" & Year(Now)
394:       set objEmail = CreateObject("CDO.Message")
395:       objEmail.From = "storageTeam@yourCompany.com"
396:       ''objEmail.To = "toaddress@email.com"
397:       objEmail.To = "backupReports@yourCompany.com"
398:       objEmail.Subject = emailSubject
399:       objEmail.HTMLbody = emailBody
400:       'objEmail.CreateMHTMLBody "file://c:/scripts/reports/backupReport_" & Year(Now) & Month(Now) & Day(Now) & ".html"
401:       objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
402:       objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.yourdomain.com"
403:       objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
404:       objEmail.Configuration.Fields.Update
405:       objEmail.AddAttachment "file://c:/scripts/reports/backupReport_" & Year(Now) & Month(Now) & Day(Now) & ".html"
406:       objEmail.Send
407:  End Sub
408:  Sub writeArray ()
409:       Dim count, strOne, strTwo, numSpaces, strSpaces, cntSpace, cntErrors, strError, prevGroup
410:       prevGroup = ""
411:       Dim overview
412:       Set overview = CreateObject("Scripting.Dictionary")
413:       For count = 0 To numServers - 1
414:            'If the group name In the current element of the array is not the same as before, close and start a new table
415:            If prevGroup <> aSvrStatus(4, count) Then
416:                 ov_func = aSvrStatus(4, count)
417:                 'If this is NOT the first iteration of the array then we must already have an open table, so close it off first...
418:                 If count > 0 Then
419:                      writeLog "f", "</table>"
420:                      'save current status to OV_ALL variable
421:                      ov_all = ov_all & "UK Netbackup," & ov_func & "," & ov_status & VbCrLf
422:                 End If
423:                 'reset other variables
424:                 ov_fail = False
425:                 ov_status = "Success"
426:                 writeLog "f", "<h2>" & aSvrStatus(4, count) & "</h2>"
427:                 If count = 0 Then
428:                      writeLog "e", "<table width=""300"" id=""" & aSvrStatus(4, count) & """>"
429:                      'Only write this to the email/today file for the first iteration
430:                      writeLog "b", "<tr class=""big""><td>Client</td><td>Policy</td><td>Status</td><td>Warnings</td></tr>"
431:                 End If
432:                 writeLog "f", "<table id=""" & aSvrStatus(4, count) & """>"
433:                 writeLog "f", "<tr class=""big""><td>Client</td><td>Policy</td><td>Status</td><td>Warnings</td></tr>"
434:            End If
435:            'Now we have done our check, reset the variable for checking in the next iteration of the loop
436:            prevGroup = aSvrStatus(4, count)
437:            writeLog "b", "<tr>"
438:            strOne = aSvrStatus(0, count)
439:            strTwo = aSvrStatus(2, count)
440:            If Len(strOne) < 8 Then
441:                 strOne = strOne & "  "
442:            End If
443:            Select Case strTwo
444:                 Case "IP"
445:                      strTwo = "<font color=""orange"">In progress</font>"
446:                      ov_status = "Failure" : ov_fail = True
447:                 Case "0"
448:                      strTwo = "<font color=""blue"">Success</font>"
449:                 Case "1"
450:                      strTwo = "Success (with warnings)"
451:                      If not ov_fail Then
452:                           ov_status = strTwo
453:                      End If
454:                 Case "11"
455:                      strTwo = "<font color=""red"">FAILURE - System call failed (UKNOWN ERROR)</font>"
456:                      ov_status = "Failure" : ov_fail = True
457:                 Case "48"
458:                      strTwo = "<font color=""red"">FAILURE - Could not contact client</font>"
459:                      ov_status = "Failure" : ov_fail = True
460:                 Case "58"
461:                      strTwo = "<font color=""red"">FAILURE - Could not connect to client</font>"
462:                      ov_status = "Failure" : ov_fail = True
463:                 Case "96"
464:                      strTwo = "<font color=""red"">FAILURE - No media available</font>"
465:                      ov_status = "Failure" : ov_fail = True
466:                 Case "150"
467:                      strTwo = "<font color=""red"">FAILURE - Cancelled by administrator</font>"
468:                      ov_status = "Failure" : ov_fail = True
469:                 Case "156"
470:                      strTwo = "<font color=""red"">FAILURE - Snapshot error encountered</font>"
471:                      ov_status = "Failure" : ov_fail = True
472:                 Case "196"
473:                      strTwo = "<font color=""red"">FAILURE - Backup window expired</font>"
474:                      ov_status = "Failure" : ov_fail = True
475:                 Case "200"
476:                      strTwo = "<font color=""red"">FAILURE - Scheduler found no backups due to run</font>"
477:                      ov_status = "Failure" : ov_fail = True
478:                 Case "800"
479:                      strTwo = "<font color=""red"">FAILURE - Resource request failed</font>"
480:                      ov_status = "Failure" : ov_fail = True
481:                 Case ""
482:                      strTwo = "<font color=""orange"">Queued...</font>"
483:                      ov_status = "Failure"
484:                 Case Else
485:                      strTwo = "Error Code: " & strTwo
486:                      ov_status = "Success (with warnings)"
487:            End Select
488:            numSpaces = 20 - Len(strOne)
489:            For cntSpace = 1 To 20
490:                 strSpaces = strSpaces & " "
491:            Next
492:            writeLog "b", "<td nowrap>" & strOne & "</td><td nowrap>" & aSvrStatus(1, count) & "</td><td nowrap>" & strTwo & "</td>"
493:            writeLog "b", "<td>"
494:            'If this is a mailstore policy do not output the failed files, since they would have already
495:            'been reported against the flatfile backup for that server. Any additional errors should be
496:            'in the aOtherErrors array.
497:            If inStr(aSvrStatus(1, count), "mail") > 0 Then
498:                 writeLog "b", "<i>see below for potential mailstore warnings</i>"
499:            Else
500:                 On Error Resume Next
501:                 For cntErrors = 0 To UBound(aSrvLogs,2)
502:                      'WScript.Echo "Pass " & cntErrors & ". "
503:                      'WScript.echo "strOne = " & strOne
504:                      'wscript.Echo "aSrvLogs(0, cntErrors) = " & aSrvLogs(0, cntErrors)
505:                      If Trim(strOne) = trim(aSrvLogs(0, cntErrors)) Then
506:                           strError = aSrvLogs(1, cntErrors)
507:                           'Trim off unnecessary text:
508:                           strError = Replace(strError, "WRN - ", "")
509:                           strError = Replace(strError, "ERR - ", "")
510:                           strError = Replace(strError, "can't open file: ", "")
511:                           strError = Replace(strError, "failure reading file: ", "")
512:                           writeLog "b", "&bull; " & strError & "<br/>"
513:                      'Else
514:                      '     writeLog "f", "&nbsp;"
515:                      End If
516:                 Next
517:                 On Error GoTo 0
518:            End If
519:            If overview.Exists(aSvrStatus(4, count)) Then
520:                 'Function already exists, so just update status ONLY if it is worse that is currently held
521:                 select case ov_status
522:                      Case "Failure"
523:                           'Status is as bad as it'll get so we'd may as well write it
524:                           overview.Item(aSvrStatus(4, count)) = ov_status
525:                      Case "Success (with warnings)"
526:                           if overview.Item(aSvrStatus(4, count)) <> "Failure" Then
527:                                overview.Item(aSvrStatus(4, count)) = ov_status
528:                           End If
529:                      Case "Success"
530:                           if overview.Item(aSvrStatus(4, count)) <> "Failure" and overview.Item(aSvrStatus(4, count)) <> "Success (with warnings)" Then
531:                                overview.Item(aSvrStatus(4, count)) = ov_status
532:                           End If
533:                 End select
534:            Else
535:                 'Function does NOT exist so create it and write the status
536:                 overview.Add aSvrStatus(4, count), ov_status
537:            End If
538:            writeLog "f", "</td>"
539:            writeLog "b", "</tr>"
540:       Next
541:       'save current status to OV_ALL variable
542:       ov_all = overview.Keys
543:       ov_all_status = overview.Items
544:       writeLog "b", "</table>"
545:       writeLog "f", "<p style=""font-size: x-small"">The following minor errors were unable to be associated to a particular job/client...</p><p style=""font-size: x-small"">"
546:       For cntErrors = 0 To UBound(aOtherErrors)
547:            writeLog "f", "&bull; " & aOtherErrors(cntErrors) & "<br/>"
548:       Next
549:       writeLog "f", "</p>"
550:       Dim aCount
551:       For aCount = 0 To overview.Count - 1
552:            statusFile.WriteLine "UK Netbackup," & ov_all(aCount) & "," & ov_all_status(aCount)
553:       Next
554:       'statusFile.Write ov_all
555:       statusFile.close
556:  End Sub


Actions

Information

5 responses

5 05 2010
Victoria

David,

I would like to have a copy of your scripts for Netbackup reporting. I need a report of only failed jobs and am pretty sure I can use the scripts to accomplish that.

Thanks,

Victoria

9 07 2010
George Hewitt

Hi there,

Any chance I could get a copy of the VBS script as well? Trying to automate our backup checks and this looks like a good starting point :-)

Thanks!

11 07 2010
DavidWarburton

Hi George – check your email. Hopefully you’ll get some use out of it.

24 07 2010
Tony Faulkner

Hello David,

I have been trying to create my own reporting with batch files without much success, not very good with VBS. Could you please send me the scripts to improve my Netbackup reporting. I would greatly appreciate it.

Thanks

4 08 2010
tf44108

Hello David,

Can you send a copy of the VBS script? I have been looking for a better looking netbackup report for a while.

Thanks

Leave a comment