Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Find a sample report: jobscheduler_designed_report.xlsx

Please consider that the below jobs are examples that have to be adjusted to your environment.

...

Code Block
languagepowershell
titleJob for Windows: report_design_task_history_windows
linenumberstrue
collapsetrue
<?xml version="1.0" encoding="UTF-8" ?>
<job title="Report Task History" process_class="agent_windows">
  <script language="powershell"><![CDATA[
Import-Module $env:SCHEDULER_DATA/config/powershell/Modules/ImportExcel;
Import-Module $env:SCHEDULER_DATA/config/powershell/Modules/JobScheduler;
 
Connect-JS -Url $JOCCockpitUrl -Credential $JOCCockpitCredential@@findstr/v "^@@f.*&" "%~f0"|pwsh.exe -&goto:eof

Import-Module ImportExcel
Import-Module JS7

$credentials = ( New-Object -typename System.Management.Automation.PSCredential -ArgumentList 'root', ( 'root' | ConvertTo-SecureString -AsPlainText -Force) )
Connect-JS7 -Url $env:JS7_JOC_URL -Credentials $credentials -Id $env:JS7_CONTROLLER_ID | Out-Null;

# Dates in local time timezonezone, output includes local date format
$reportData = Get-JSTaskHistory -Timezone (Get-Timezone ) `
                  |  Select-Object -Property @{name="JobSchedulerCONTROLLER ID"; expression={$_.jobschedulerIdcontrollerId}}, `
                                             @{name="Task ID"; expression={$_.taskId}}, `
                                             @{name="Job"; expression={$_.job}}, `
											 @{name="Workflow"; expression={$_.workflow}}, `
                                             @{name="Status"; expression={$_.state._text}}, `
                                             @{name="Start Time"; expression={ Get-Date $_.startTime }}, `
                                             @{name="End Time"; expression={ Get-Date $_.endTime }}, `
                                             @{name="Duration (sec.)"; expression={ (New-Timespan -Start "$($_.startTime)" -End "$($_.endTime)").Seconds }}, `
                                             @{name="Criticality"; expression={$_.criticality}}, `
                                             @{name="Exit Code"; expression={$_.exitCode}}
 
$xlsxFile = "/tmp/TaskHistory.xlsx"
Remove-Item $xlsxFile -ErrorAction SilentlyContinue
$workSheetName = "TaskHistory"
 
$excel = $reportData | Export-Excel $xlsxFile -ClearSheet -PassThru -AutoSize -AutoFilter -TableName ByJobStatus `
     -ConditionalText $( New-ConditionalText successful white green 
                         New-ConditionalText failed white Red 
                         New-ConditionalText Incomplete black orange 
                       ) `
     -WorksheetName $WorkSheetName -IncludePivotTable  -PivotRows "Job" -PivotColumn "Status" -PivotData @{"status"="count"} `
     -IncludePivotChart -ChartType  ColumnClustered3D
 
$pivotTableParams = @{
      PivotTableName  = "ByJob"
      Address         = $excel.$WorkSheetName.cells["K1M1"]
      SourceWorkSheet = $excel.$WorkSheetName
      PivotRows       = @("JobSchedulerCONTROLLER ID", "Job", "Status")
      PivotData       = @{'Status' = 'count'}
      PivotTableStyle = 'Medium6'
}
 
$pt = Add-PivotTable @pivotTableParams -PassThru
$pt.RowHeaderCaption = "By " + ($pivotTableParams.PivotRows -join ",")
Close-ExcelPackage $excel -Show
 
Write-Output ".. report created: $xlsxFile";
]]></script>
  <run_time/>
</job>


Explanations

  • Line 2-3: The job is executed with a Windows Agent that is assigned by a process class. The job is of type "PowerShell" and will use the PowerShell version provided with the server.
  • Line 4-5: The required PowerShell modules are imported. They could be installed in any location in the file system.
  • Line 7: The Connect-JS cmdlet is used to authenticate with the JOC Cockpit REST Web Service. The required URL and credentials are specified in a PowerShell profile, see PowerShell CLI 1.2 - Use Cases - Credentials Management
  • Line 10: Create an object $reportData from the output of the  Get-JSTaskHistory cmdlet in which a number of properties are selected and are specified for the sequence in which they should occur in the report.
  • Line 21: The location where the Excel file will be saved is specified with the $xlsxFile variable.
  • Line 23: Create a variable $workSheetName that is used to store the name of the worksheet.
  • Line 25-30: Creates a spreadsheet and passes on the Excel Package object which provides the reference to the workbook and turns to the worksheets inside it.
    • $xlsxFile stores the path of the Excel® file.
    • If we are updating an existing worksheet and the new data wouldn’t completely cover the area consumed by previous data, then we may be left with “ghost” data. To ensure this doesn’t happen, we can use the  -ClearSheet option to remove previous data in a worksheet.
    • -PassThru returns the Pivot Table so it can be customized.
    • -AutoSize parameter allows us to resize the columns of the spreadsheet to fit the data added and to get the column-widths right.
    • For adding color to conditional text  -ConditionalText is used. Additional types of conditional format are supported. Here we use conditional text for the job status color like (successful=green, incomplete=orange, failed=red).
    • To assign a name to the worksheet the -WorksheetName parameter is used. The default name of the worksheet is sheet1.

    • The -IncludePivotTable and -IncludePivotChart parameters generate the Pivot Table and Pivot Chart. The parameter -ChartType lets you pick what type of chart you want to use, there are many examples to choose from: Area, Line, Pie, ColumnClustered, ColumnStacked100, ColumnClustered3D, ColumnStacked1003D, BarClustered, BarOfPie, Doughnut, etc.
    • The -PivotRows and -PivotData parameters describe how to tabulate the data.
  • Line 34: The -PivotTableName parameter is used as the name for the new Pivot Table.
  • Line 35: By default, a Pivot Table will be created in its own worksheet, but it can be created in an existing worksheet. In the above job example the $excel.$WorkSheetName.cells["K1"] parameter defines the cell in an existing worksheet where the pivot table will be created.
  • Line 36:  $excel.$WorkSheetName refers to the worksheet in which the source data are found.
  • Line 37: The -PivotRows parameter is used for fields to set as rows in the Pivot Table.
  • Line 38: The -PivotData parameter contains a hash table in the form "FieldName"="Function," where a function is one of Average(), Count(), CountNums(), Max(), Min(), Product(), None(), StdDev(), StdDevP(), Sum(), Var(), VarP().
  • Line 39: To apply a table style to the Pivot Table the -PivotTableStyle parameter is used. The PivotTableStyle Medium6 is the default table style but there are plenty of others to choose from. Example: PivotTableStyles = None, Custom, Light1 to Light21, Medium1 to Medium28, Dark1 to Dark11".

...