Page History
...
Find a sample report for download that includes the report with its OrderTask-History worksheet: jobscheduler_reporting.xlsx
...
Please consider that the below job is an example that has to be adjusted for your environment.
Download: jdOrderHistoryReportjdTaskHistoryReport.workflow.json
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
@@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 Get-JSOrderHistoryJSTaskHistory -Timezone (Get-Timezone) -RelativeDateFrom -3d ` | Select-Object -Property @{name="Controller ID"; expression={$_.controllerId}}, ` @{name="HistoryAgent IDURL"; expression={$_.historyIdagentUrl}}, ` @{name="OrderTask History ID"; expression={$_.orderIdtaskId}}, ` @{name="Order StatusID"; expression={$_.state._textorderId}}, ` @{name="Order PositionStatus"; expression={$_.state.position_text}}, ` @{name="WorkflowOrder Position"; expression={$_.workflowposition}}, ` @{name="History StatusWorkflow"; expression={$_.state._textworkflow}}, ` @{name="Planned Start TimeJob"; expression={ Get-Date $_.plannedTime job}}, ` @{name="Start TimeCriticality"; expression={Get-Date $_.startTimecriticality}}, ` @{name="End TimeSequence"; expression={ Get-Date $_.endTime sequence}}, ` @{name="Duration (sec.)Retry Counter"; expression={ (New-Timespan -Start "$($_.startTime)" -End "$($_.endTime)").Seconds retryCounter}}, ` | Export-Excel -Path /tmp/jobscheduler_reporting.xlsx -WorksheetName "Order-History" -ClearSheet Write-Output ".. report created: /tmp/jobscheduler_reporting.xlsx" |
Explanation:
- Line 1: The job is executed with a Windows Agent and makes use of the PowerShell shebang for Windows, see above explanation.
- Line 3-4: The required PowerShell modules are imported. They could be installed with 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 specified in a number of ways:- Consider JS7 - How to connect to JOC Cockpit using the PowerShell Module.
- Use of JS7 - Job Resources that inject environment variables to the PowerShell job.
- Use of a PowerShell profile.
- Line 10: The Get-JS7TaskHistory cmdlet is invoked
- with the parameter
-Timezone
to specify to which time zone date values in the report should be converted. The parameter value-Timezone (Get-Timezone)
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 as UTC dates to the report. - optionally with additional parameters, for example to specify the date or date range for which the report is created 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.
- with the parameter
- Line 11-21: From the output of the
Get-JS7TaskHistory
cmdlet a number of properties are selected and and are specified for the sequence in which they should occur in the report.- To add more speaking column headers the property names are mapped to a more readable textual representation.
- Consider the handling of date formats in line 17-21. Use of the
Get-Date
cmdlet converts the output format of dates (not the time zone) to the default format that is in place on the Agent's server. Without using theGet-Date
cmdlet any date values will be stored to 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 21 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 list of properties per Task History item is piped to the
Export-Excel
cmdlet that is available with the ImportExcel PowerShell Module. The report file name is specified and optionally the worksheet. For a full list of parameters see the ImportExcel PowerShell Module.
Windows Version
Download: report_task_history_windows.job.xml
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<?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 | Out-Null; # Dates in local timezone, output includes local date format Get-JSTaskHistory -Timezone (Get-Timezone ) ` | Select-Object -Property @{name="JobSchedulerExit IDCode"; expression={$_.jobschedulerIdexitCode}}, ` @{name="TaskHistory IDStatus"; expression={$_.taskId}}, ` @{name="Job"; expression={$_.job.state._text}}, ` @{name="StatusArguments"; expression={$_.state._textarguments}}, ` @{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}} ` | Export-Excel -Path /tmp/jobscheduler_reporting.xlsx -WorksheetName "Task-History" -ClearSheet; Write-Output ".. report created: /tmp/jobscheduler_reporting.xls"; ]]></script> <run_time/> </job> |
Explanations
xlsx"
|
Explanation:
- Line 1Line 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.and makes use of the PowerShell shebang for Windows, see above explanation.
- Line 3-4Line 4-5: The required PowerShell modules are imported. They could be installed with any location in the file system
- Line 6-7: The Connect-JSJS7 cmdlet is used to authenticate with the JOC Cockpit JS7 REST Web Service API. The required URL and credentials are arguments for
-Url
,-Credentials
and-Id
can specified in a PowerShell profile, see PowerShell CLI 1.2 - Use Cases - Credentials Managementnumber of ways:- Consider JS7 - How to connect to JOC Cockpit using the PowerShell Module.
- Use of JS7 - Job Resources that inject environment variables to the PowerShell job.
- Use of a PowerShell profile.
- Line 10: The Get-JSTaskHistoryJS7TaskHistory cmdlet is called invoked
- with the parameter
-Timezone
to specify to which timezone time zone date values in the report should be converted. The parameter value-Timezone (Get-Timezone)
specifies that the timezone time zone of the Agent's server is used. Otherwise specify the desired timezone e.g. time zone, for example like this:-Timezone (Get-Timezone -Id 'GMT Standard Time')
. Without using this parameter any date values are stored as UTC dates to the report. - optionally with additional parameters, e.g. for example to specify the date or date range for which the report is created A value
-DateFrom (Get-Date -Hour 0 -Minute 0 -Second 0).AddDays(-7).ToUniversalTime()RelativeDateTo -3d
specifies that the report should cover the last 7 3 days (from until midnight). Keep in mind that dates have to be specified for the UTC timezonetime zone. Without this parameter the report will be created for the last next day. - see the Get-JSTaskHistory cmdlet JS7TaskHistory cmdlet for a full parameter reference.
- with the parameter
- Line 11-1928: From the output of the
Get-
JSTaskHistoryJS7TaskHistory
cmdlet a number of properties are selected and and are specified for the sequence in which they should occur in the report.- To add more speaking column headers the property names are mapped to a more readable textual representation.
- Consider the handling of date formats in lines 15, 16line 17-21. Use of the
Get-Date
cmdlet converts the output format of dates (not the timezonetime zone) to the default format that is in place on the Agent's server. Without using theGet-Date
cmdlet any date values will be stored to the report in ISO format, e.g.2020-12-31 10:11:12+02:00
for a date in the European central timezone time zone that is UTC+1 in winter time and UTC+2 in summer time. - Lines 17 Line 28 introduces a new property, a calculated duration. From the start time and end time values of a past planned start the difference in seconds is calculated and is forwarded added to the report.
- Line 2029: The list of properties per task history Task History item is piped to the
Export-Excel
cmdlet that is available with the ImportExcel PowerShell Module. The report file name is specified and optionally the worksheet. For a full list of parameters see the ImportExcel PowerShell Module.
Explanations
- Basically the same explanations as for the Windows version of the job apply.
- Line 4: The PowerShell has to be invoked with
pwsh
. Consider that any subsequent PowerShell commands are quoted within a string that starts with line 3 and that ends with line 29.- As the string is using a single quote all subsequent PowerShell commands make use of double quotes when required.
- You could apply a different quoting style, however, quotes have to be consistent.
- Line 5: As an example a PowerShell profile is invoked that provides the variables for URL and credentials to access the JOC Cockpit REST Web Service. Such profiles can be stored in different locations and can be invoked automatically by
pwsh
on startup.
Overview
Content Tools