You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 18 Current »

Introduction

  • Instead of the tabular visualization in report files, users can add a more lively visual design to their Excel® reports by using the Import Excel Module (3rd-party).
  • Reports start as usual with data in rows and columns, however, with a choice of colors, Pivot Tables, and Charts, designs can be developed that provide better visualization and better decision making.

Use Cases

The PowerShell Command Line Interface 2.0 is used by jobs to extract data and to create reports. Two modules are available for designing better reports:

  • The JS7 - PowerShell Module,
  • A reporting PowerShell Module. This example makes use of the ImportExcel PowerShell Module (3rd party) which can be used to create Excel® reports and to add Pivot Tables and Pivot Charts to reports. The module can be operated for Windows and Linux computers and does not require prior installation of Microsoft Excel®.

A sample report is available here: jobscheduler_task_history_designed_report.xlsx

Job for Windows: report_design_task_history_windows
@@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 zone, output includes local date format
$reportData = Get-JS7TaskHistory -Timezone (Get-Timezone ) `
                  |  Select-Object -Property @{name="CONTROLLER ID"; expression={$_.controllerId}}, `
                                             @{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["M1"]
      SourceWorkSheet = $excel.$WorkSheetName
      PivotRows       = @("CONTROLLER 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";
Disconnect-JS7


Explanations

  • Line 1: The job is executed with a Windows Agent and makes use of the PowerShell shebang for Windows.
  • Line 3-4: The required PowerShell modules are imported. They could be installed in any location in the file system.
  • Line 6-7: The Connect-JS7 cmdlet is used to authenticate with the JS7 REST Web Service API. The required arguments for -Url , -Credentials and -Id can be specified in a number of ways:
  • Line 10: The Get-JS7TaskHistory cmdlet is invoked:
    • with the -Timezone parameter to specify the time zone which date values in the report should be converted to. The -Timezone (Get-Timezone) parameter value specifies that the time zone of the Agent's server is used. Otherwise specify the desired time zone, for example like this: -Timezone (Get-Timezone -Id 'GMT Standard Time'). Without using this parameter any date values are stored in the report as UTC dates.
    • optionally with additional parameters, for example, to specify the date or date range which the report is created for. A value -RelativeDateTo -3d specifies that the report should cover the last 3 days (until midnight). Keep in mind that dates have to be specified for the UTC time zone. Without this parameter the report will be created for the next day.
    • see the Get-JS7TaskHistory cmdlet for a full parameter reference.
  • Line 11-20: From the output of the Get-JS7TaskHistory cmdlet a number of properties are selected and are specified for the sequence in which they should occur in the report. 
    • To add more appropriate column headers the property names are mapped to a more readable textual representation.
    • Consider the handling of date formats in lines 16-20. The use of the Get-Date cmdlet converts the output format of dates (not the time zone) to the default format which is in place on the Agent's server. Without using the Get-Date cmdlet, any date values will be stored in the report in ISO format, e.g. 2020-12-31 10:11:12+02:00 for a date in the European central time zone that is UTC+1 in winter time and UTC+2 in summer time.
    • Line 18 introduces a new property, a calculated duration. From the start time and end time values of a planned start the difference in seconds is calculated and is added to the report.
  • Line 22: The location where the Excel file will be stored is specified with the $xlsxFile variable.
  • Line 24: Create a variable $workSheetName which is used to store the name of the worksheet.
  • Line 26-31: 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 you are updating an existing worksheet and the new data wouldn’t completely cover the area consumed by previous data, then you may be left with “ghost” data. To ensure this doesn’t happen, you 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 you 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 conditional text is used 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 35: 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 37:  $excel.$WorkSheetName refers to the worksheet in which the source data are found.
  • Line 38: The -PivotRows parameter is used for fields to set as rows in the Pivot Table.
  • Line 39: 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 40: 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.
  • Line 48: The Disconnect-JS7 cmdlet is used to close the connection to JOC Cockpit.


Sample Report Sheet with colored status:

  • The screenshot below  contains the output of the  Get-JS7TaskHistory cmdlet stored in the Excel report sheet. Users can change the colors of text and background of cells according to their choice.

  • The example below presents the status of jobs with different colors using the -ConditionalText parameter of the ImportExcel module.


Sample Charts:

  • There is a sample Pivot Chart created with the parameter -ChartType ColumnClustered3D.
  • This chart type is used in this example to display the number of jobs per state (successful, incomplete, failed) of jobs. 



Sample Pivot Table:

  • The sample Pivot Table displays the RowHeaderCaption as "By JobScheduler ID, Job, Status". Users can adjust the style of the table by using the  -PivotTableStyle parameter.
  • Users can expand and collapse the Pivot Table.



  • No labels