...
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<?xml version="1.0" encoding="ISO-8859-1"?> <job title="Report Daily Plan" 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-JobScheduler -Url $JOCCockpitUrl -Credential $JOCCockpitCredential | Out-Null # start mode mapping $startModes = @{"0"="single start"; "1"="repeat start-start"; "2"="repeat end-start"} # Dates in local time zone, output includes local date format Get-JSDailyPlan -Timezone (Get-Timezone) ` | Select-Object -Property @{name="Job Chain/Job"; expression={ "$($_.jobChain)$($_.job)"}}, ` @{name="Order ID"; expression={$_.orderId}}, ` @{name="Status"; expression={$_.state._text}}, ` @{name="Job Stream"; expression={$_.jobStream}}, ` @{name="Late"; expression={$_.late}}, ` @{name="Start Type"; expression={ $startModes[ "$($_.startMode)"] }}, ` @{name="Repeat Interval"; expression={$_.period.repeat}}, ` @{name="Planned Start Time"; expression={ Get-Date $_.plannedStartTime }}, ` @{name="Expected End Time"; expression={ Get-Date $_.expectedEndTime }}, ` @{name="Expected Duration (sec.)"; expression={ (New-Timespan -Start "$($_.plannedStartTime)" -End "$($_.expectedEndTime)").Seconds }}, ` @{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 "Daily-Plan" -ClearSheet Write-Output ".. report created: /tmp/jobscheduler_reporting.xls" ]]></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 with any location in the filesystem
- 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: For better readability of the report the start types of jobs are mapped to a textual representation (single start, cyclic start).
- Line 13: The Get-JSDailyPlan 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 Agent's server is used. Otherwise specify the desired timezone e.g. like this:-Timezone (Get-Timezon -Id 'GMT Standard Time')
. Without using this parameter all date values are stored as UTC dates to the report. - optionally with additional parameters, e.g. to specify the date for which the report is created A value
-DateTo (Get-Date -Hour 0 -Minute 0 -Second 0).AddDays(8).ToUniversalTime()
specifies that the report should cover the next 7 days (until midnight). Without this parameter the report will be created for the next day. - see the Get-JSDailyPlan cmdlet for a full parameter reference.
- with the parameter
- The job creates two events that signal start and completion of the job.
- A common event class is used that is assigned the path of the job chain
- Individual event ids are assigned that are created from the job name
- All communication with the JobScheduler Supervisor or Master takes place by internal commands, no additional HTTP/HTTPS connection is used.
...