...
Windows Version
Download: report_taskjobstream_history_windows.job.xml
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<?xml version="1.0" encoding="UTF-8" ?> <job title="Report Job Stream 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-JSJobStreamHistory -Timezone (Get-Timezone ) -WithTasks ` | Select-Object -Property @{name="JobScheduler ID"; expression={$_.jobschedulerId}}, ` @{name="Job Stream"; expression={$_.jobStream}}, ` @{name="Job Stream Starter"; expression={$_.jobStreamStarter.title}}, ` @{name="Cluster Member"; expression={$_.clusterMember}}, ` @{name="Task ID"; expression={$_.taskId}}, ` @{name="Job"; expression={$_.job}}, ` @{name="Criticality"; expression={$_.criticality}}, ` @{name="Exit Code"; expression={$_.exitCode}}, ` @{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 }} ` | Export-Excel -Path /tmp/jobscheduler_reporting.xlsx -WorksheetName "JobStream-History" -ClearSheet; Write-Output ".. report created: /tmp/jobscheduler_reporting.xls"; ]]></script> <run_time/> </job> |
...
- 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 with 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: The Get-JSJobStreamHistory cmdlet is called
- with the parameter
-Timezone
to specify to which timezone date values in the report should be converted. The parameter value-Timezone (Get-Timezone)
specifies that the timezone of the Agent's server is used. Otherwise specify the desired timezone e.g. 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. to specify the date range for which the report is created A value
-RelativeDateFrom -7d
specifies that the report should cover the last 7 days (from UTC midnight). Without this parameter the report will be created for the last day. - see the Get-JSJobStreamHistory cmdlet for a full parameter reference.
- with the parameter
- Line 11-1922: From the output of the Get-JSJobStreamHistory 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, 16. Use of the
Get-Date
cmdlet converts the output format of dates (not the timezone) 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 that is UTC+1 in winter time and UTC+2 in summer time. - Lines 17 introduces a new property, a calculated duration. From the start time and end time values of a past start the difference in seconds is calculated and is forwarded to the report.
- Line 2023: The list of properties per job stream 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.
Linux Version
Download: report_taskjobstream_history_linux.job.xml
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<?xml version="1.0" encoding="UTF-8" ?> <job title="Report Job Stream History" process_class="agent_linux"> <script language="shell"><![CDATA[ pwsh -NoLogo -NonInteractive -Command '& { . $env:SCHEDULER_DATA/config/powershell/JobScheduler.PowerShell_profile.ps1; 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-JSJobStreamHistory -Timezone (Get-Timezone ) -WithTasks ` | Select-Object -Property @{name="JobScheduler ID"; expression={$_.jobschedulerId}}, ` @{name="Job Stream"; expression={$_.jobStream}}, ` @{name="Job Stream Starter"; expression={$_.jobStreamStarter.title}}, ` @{name="Cluster Member"; expression={$_.clusterMember}}, ` @{name="Task ID"; expression={$_.taskId}}, ` @{name="Job"; expression={$_.job}}, ` @{name="Criticality"; expression={$_.criticality}}, ` @{name="Exit Code"; expression={$_.exitCode}}, ` @{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 }} ` | Export-Excel -Path /tmp/jobscheduler_reporting.xlsx -WorksheetName "JobStream-History" -ClearSheet; Write-Output ".. report created: /tmp/jobscheduler_reporting.xls"; }' ]]></script> <run_time/> </job> </job> |
...