Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- REQUIREMENTS
- Symantec Backup Exec (TM) 2014
- .Net Framework 3.5
- #>
- # normally the first import line should be enough
- # but due to the user context that the script may run under when executed by labtech
- # we need the second import that has an explicit path
- # so I'm keeping both lines just in case
- import-module bemcli
- import-module "c:\program files\symantec\backup exec\modules\bemcli\bemcli"
- # START SERVICE CHECK
- # many of the cmdlets will not run properly if some of the services are not running
- # so here we enumerate all the services, and if their state isn't running we restart them
- $services = get-beservice
- foreach($service in $services){
- if($service.status -ne "Running"){
- restart-beservice $service.name
- }
- }
- # END SERVICE CHECK
- # START GLOBALS
- # get all jobs that exist, who's schedule is NOT null, AND are NOT Unscheduled, AND are type Backup OR Duplicate, AND task types are Full OR Incremental OR Duplicate, and sort the results by name
- $jobs = get-bejob | ?{($_.schedule -ne $null) -and ($_.schedule.tostring() -ne "Unscheduled") -and ($_.jobtype -eq "Backup" -or $_.jobtype -eq "Duplicate") -and ($_.tasktype -eq "Full" -or $_.tasktype -eq "Incremental" -or $_.tasktype -eq "Duplicate" -or $_.tasktype -eq "CustomBackup")} | sort name
- # number of days to show in the horizontal table, calendar style
- $daysHistory = 30
- # number of dats to show in the vertical, detailed job history table
- $daysDetail = 10
- # colors for html table elements
- $cSuccess = "palegreen"
- $cWarning = "lemonchiffon"
- $cError = "lightsalmon"
- $cTableHeader = "blue"
- $cColumnHeader = "lavender"
- $cRowEven = "gainsboro"
- # css style
- $style = "<style>body{font-size:10px;font-family:verdana,sans-serif;color:black;font-weight:normal;}" + `
- "table{width:100%;border-width:1px;cellpadding:0;cellspacing:0;border-style:solid;border-color:black;border-collapse:collapse}" + `
- "th{background:$cColumnHeader;white-space:nowrap;font-size:11px;border-width:1px;padding:5px;border-style:solid;border-color:black;}" + `
- "tr{font-size:11px;border-width:1px;padding:10px;border-style:solid;border-color:black;}" + `
- "tr:nth-child(even){background:$cRowEven}" + `
- "td{font-size:10px;border-width:1px;padding:4px;border-style:solid;border-color:black;}" + `
- "td:first-child{white-space:nowrap;width:1px}</style>"
- # END GLOBALS
- # START GENERATE HISTORY DATA
- # generate the beginning on the table and the column group
- # extra columns for name, status, and next scheduled date
- $history = "<table>`n<colgroup><col/><col/><col/>"
- for ($d=0; $d -lt $daysHistory; $d++){
- $history += "</col>"
- }
- $history += "<colgroup/>`n"
- # generate the headers
- $history += "<tr><th>Name</th><th>Status</th><th>Scheduled Next</th>"
- for ($d=0; $d -lt $daysHistory; $d++){
- $history += "<th>"+(get-date).adddays(0-$d-1).ToShortDateString()+"</th>"
- }
- $history += "</tr>`n"
- # generate the data in each row
- foreach ($job in $jobs){
- # open the row for this job
- $history += "<tr>"
- # put the job name, status, and next scheduled in the first three columns / "<td>"++"</td>"
- if($job.Status -eq "Active" -or $job.Status -eq "Dispatched" -or $job.Status -eq "Ready"){
- # color the job, status, and date if it's active/dispatched/ready
- $history += "<td style=`"font-weight: bold; background-color:$cSuccess`">"+$job.Name+"</td><td nowrap style=`"font-weight: bold; background-color:$cSuccess`">"+$job.Status+"</td><td nowrap style=`"font-weight: bold; background-color:$cSuccess`">Started: "+$job.NextStartDate+"</td>"
- }elseif($job.Status -eq "OnHold"){
- # color the job, status, and date if it's on hold
- $history += "<td style=`"background-color:$cWarning`">"+$job.Name+"</td><td nowrap style=`"background-color:$cWarning`">"+$job.Status+"</td><td nowrap>"+$job.NextStartDate+"</td>"
- }else{
- $history += "<td >"+$job.Name+"</td><td nowrap>"+$job.Status+"</td><td nowrap>"+$job.NextStartDate+"</td>"
- }
- # put the history of the job from each day in to the rest of the columns
- for ($d=0; $d -lt $daysHistory; $d++){
- # get the job history for particular day, it's possible it ran multiple times
- $jobHistory = $job | Get-BEJobHistory -fromstarttime (get-date).adddays(0-$d-1).Date -ToStartTime (get-date).adddays(0-$d).Date
- # if more than one job history per day, process it like an array of objects
- if($jobHistory.length -gt 1){
- # shade cell background based on status
- # here we check of any object of the collection contains the desired status, this means there is precedence
- # for example, if "Succeeded" is matched, we will use that color regardless of what the jobstatus of other objects in the collection is
- # this works out desireable as we usually just care about a single success per day
- if(($jobHistory | ?{$_.JobStatus -contains "Succeeded"}) -ne $NULL){
- $history += "<td style=`"background-color:$cSuccess`">"
- }elseif((($jobHistory | ?{$_.JobStatus -contains "Canceled"}) -ne $NULL) -or (($jobHistory | ?{$_.JobStatus -contains "Error"}) -ne $NULL)){
- $history += "<td style=`"background-color:$cError`">"
- }elseif((($jobHistory | ?{$_.JobStatus -contains "SucceededWithExceptions"}) -ne $NULL) -or (($jobHistory | ?{$_.JobStatus -contains "Missed"}) -ne $NULL)){
- $history += "<td style=`"background-color:$cWarning`">"
- }else{
- $history += "<td>"
- }
- # since this is a collection of objects, we need to parse them and aggregate the statuses for display purposes
- foreach($item in $jobHistory){
- $history += $item.JobStatus.toString()+" "
- }
- # if just one job history per day, process it as a single object
- }else{
- # shade cell background based on status
- if($jobHistory.JobStatus -contains "Succeeded"){
- $history += "<td style=`"background-color:$cSuccess`">"
- }elseif($jobHistory.JobStatus -contains "Canceled" -or $jobHistory.JobStatus -contains "Error"){
- $history += "<td style=`"background-color:$cError`">"
- }elseif($jobHistory.JobStatus -contains "SucceededWithExceptions" -or $jobHistory.JobStatus -contains "Missed"){
- $history += "<td style=`"background-color:$cWarning`">"
- }else{
- $history += "<td>"
- }
- $history += $jobHistory.JobStatus
- }
- $history += "</td>"
- }
- #close the row for this job
- $history += "</tr>`n"
- }
- $history += "<table/>`n"
- # STOP GENERATE HISTORY DATA
- # START GENERATE DETAIL DATA
- $detailErrorCanceled = get-bejob | Get-BEJobHistory -FromStartTime (get-date).adddays(0-$daysDetail-1).Date -ToStartTime (get-date).Date | ?{$_.jobstatus -eq "Error" -or $_.jobstatus -eq "Canceled"} | sort StartTime -descending | select Name,JobType,JobStatus,@{name='Size (GB)';expression={"{0:N2}" -f ($_.TotalDataSizebytes/1073741824)}},StartTime,ElapsedTime,ErrorMessage | Convertto-html -fragment
- $detailSucceeded = get-bejob -jobtype backup | Get-BEJobHistory -FromStartTime (get-date).adddays(0-$daysDetail-1).Date -ToStartTime (get-date).Date -jobstatus Succeeded | sort StartTime -descending | select Name,JobType,JobStatus,@{name='Size (GB)';expression={"{0:N2}" -f ($_.TotalDataSizebytes/1073741824)}},StartTime,ElapsedTime | Convertto-html -fragment
- $detailSucceededWE = get-bejob -jobtype backup | Get-BEJobHistory -FromStartTime (get-date).adddays(0-$daysDetail-1).Date -ToStartTime (get-date).Date -jobstatus SucceededWithExceptions | sort StartTime -descending | select Name,JobType,JobStatus,@{name='Size (GB)';expression={"{0:N2}" -f ($_.TotalDataSizebytes/1073741824)}},StartTime,ElapsedTime | Convertto-html -fragment
- $detail = "<table><tr><th style=`"text-align: center; font-weight: bold; background-color: $cError`">JOBS WITH ERRORS/CANCELED</th></tr></table>`n" + `
- $detailErrorCanceled + "`n" + `
- "<table><tr><th style=`"text-align: center; font-weight: bold; background-color: $cWarning`">SUCCESSES WITH EXCEPTIONS</th></tr></table>`n" + `
- $detailSucceededWE + "`n" + `
- "`n<table><tr><th style=`"text-align: center; font-weight: bold; background-color: $cSuccess`">SUCCESSES</th></tr></table>`n" + `
- $detailSucceeded + "`n"
- # STOP GENERATE DETAIL DATA
- # START GENERATE STORAGE DATA
- $storage = "<table>`n<colgroup><col/><col/><col/><col/><col/><col/></colgroup>`n" + `
- "<tr><th>Disk Name</th><th>Type</th><th>Path</th><th>Is Online</th><th>Status</th><th>Used/Total (GB) - Used %</th></tr>`n"
- $disks = Get-BEDiskStorageDevice | sort name
- foreach($disk in $disks){
- # if capacity % is above threshold, print the row out with alternate colors
- # first check is for the highest usage, or red alert at 95%
- if(($disk.UsedCapacityBytes/$disk.TotalBackupStorageBytes*100) -gt 95){
- $storage += "<tr style=`"background-color: $cError`"><td>"+$disk.Name+"</td>" + `
- "<td nowrap>"+($disk.Servers)[0].ConnectionType+"</td>" + `
- "<td nowrap>"+($disk.Servers)[0].Path+"</td>" + `
- "<td nowrap>"+($disk.Servers)[0].IsOnline+"</td>" + `
- "<td nowrap>"+$disk.CapacityStatus+"</td>" + `
- "<td nowrap>"+"{0:N2}" -f ($disk.UsedCapacityBytes/1073741824)+"/{0:N2}" -f ($disk.TotalBackupStorageBytes/1073741824)+" - {0:N2}" -f($disk.UsedCapacityBytes/$disk.TotalBackupStorageBytes*100)+"%</td></tr>`n"
- # second check is for the warning usage level, or yellow alert at 85%
- }elseif(($disk.UsedCapacityBytes/$disk.TotalBackupStorageBytes*100) -gt 85){
- $storage += "<tr style=`"background-color: $cWarning`"><td>"+$disk.Name+"</td>" + `
- "<td nowrap>"+($disk.Servers)[0].ConnectionType+"</td>" + `
- "<td nowrap>"+($disk.Servers)[0].Path+"</td>" + `
- "<td nowrap>"+($disk.Servers)[0].IsOnline+"</td>" + `
- "<td nowrap>"+$disk.CapacityStatus+"</td>" + `
- "<td nowrap>"+"{0:N2}" -f ($disk.UsedCapacityBytes/1073741824)+"/{0:N2}" -f ($disk.TotalBackupStorageBytes/1073741824)+" - {0:N2}" -f($disk.UsedCapacityBytes/$disk.TotalBackupStorageBytes*100)+"%</td></tr>`n"
- # otherwise we default to normal rows
- }else{
- $storage += "<tr><td>"+$disk.Name+"</td>" + `
- "<td nowrap>"+($disk.Servers)[0].ConnectionType+"</td>" + `
- "<td nowrap>"+($disk.Servers)[0].Path+"</td>" + `
- "<td nowrap>"+($disk.Servers)[0].IsOnline+"</td>" + `
- "<td nowrap>"+$disk.CapacityStatus+"</td>" + `
- "<td nowrap>"+"{0:N2}" -f ($disk.UsedCapacityBytes/1073741824)+"/{0:N2}" -f ($disk.TotalBackupStorageBytes/1073741824)+" - {0:N2}" -f($disk.UsedCapacityBytes/$disk.TotalBackupStorageBytes*100)+"%</td></tr>`n"
- }
- }
- $storage += "<table>`n"
- # STOP GENERATE STORAGE DATA
- # START COMPILE OUTPUT
- $output = "<html><head>$style</head>"
- $output += "<body>" + `
- "<table><tr><th style=`"font-size:12px;text-align: center; font-weight: bold; color: white; background-color: $cTableHeader`">JOB HISTORY (last $daysHistory days)</th></tr></table>`n" + `
- $history + "`n" + `
- "<table><tr><th style=`"font-size:12px;text-align: center; font-weight: bold; color: white; background-color: $cTableHeader`">STORAGE DETAILS</th></tr></table>`n" + `
- $storage + "`n" + `
- "<table><tr><th style=`"font-size:12px;text-align: center; font-weight: bold; color: white; background-color: $cTableHeader`">DETAILED JOB BREAKDOWN (last $daysDetail days)</th></tr></table>`n" + `
- $detail + "`n" + `
- "</body>"
- $output | out-file ($args[0])
- # STOP COMPILE OUTPUT
Advertisement
Add Comment
Please, Sign In to add comment