Date: Fri, 29 Mar 2024 06:15:08 +0000 (UTC) Message-ID: <1834807917.12459.1711692908468@change.sos-berlin.com> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_12458_1633343618.1711692908468" ------=_Part_12458_1633343618.1711692908468 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
JS7 does not make use of files for log output of order logs and task log= s, see JS7 - O= rder Logs and Task Logs. Instead, JS7 streams log output from Agents to= the Controller and the JOC Cockpit without use of files.
A number of users prefer to have log files available for each order exec= ution and job execution, for example to consolidate log files on a file ser= ver or to submit log files to specific tools for log analysis.
To support a situation when log output should be consolidated to files, = the JS7 - REST Web Serv= ice API allows access to log output of orders and jobs. The <= a href=3D"/display/JS7/JS7+-+PowerShell+Module">JS7 - PowerShell Module= is a lightweight wrapper for the REST Web Service API which is used for th= e examples below with Linux and Windows. Users are free to use the JS7 REST= Web Service from their preferred scripting language to provide similar fun= ctionality.
For similar handling of order logs see JS7 - How to make order logs= available from files.
The following cmdlets are provided:
$l= ogs =3D Get-JS7TaskHistory | Get-JS7TaskLog
Explanation:
Get-JS7TaskHistory
cmdlet returns history results whic=
h can be filtered by folders, workflows, date range, jobs - see the cmdlet =
description. By default today's task executions are returned.Get-JS7TaskLog
cmdlet is used in a pipeline and return=
s the task log object for each history entry.$logs
array will hold the list of task log=
objects.A task log object carries a number of attributes as shown in the followi=
ng console example:
PS= /> $logs =3D Get-JS7TaskHistory | Get-JS7TaskLog PS /> $logs[0] controllerId : jobscheduler agentUrl : http://apmaccs:4449 taskId : 15247 orderId : #2022-03-06#P31960629618-pdCyclicSimpleWorkflowTicking workflow : /ProductDemo/CyclicExecution/pdCyclicSimpleWorkflowTicking position : 0/cycle+end=3D1646607600000,scheme=3D1,i=3D10,next=3D1646564= 721361:2 job : job3 criticality : normal exitCode : 0 state : @{severity=3D6; _text=3DSUCCESSFUL} startTime : 06.03.2022 12:05:31 endTime : 06.03.2022 12:05:36 log : 2022-03-06 12:05:31.388+0100 [MAIN] [Start] Job=3Djob3, A= gent (url=3Dhttp://apmaccs:4449, id=3Dagent_002) 2022-03-06 12:05:31.795+0100 [STDOUT] using workflow: pdCyc= licSimpleWorkflowTicking running job: job3 2022-03-06 12:05:36.399+0100 [MAIN] [End] [Success] retur= nCode=3D0
Ge= t-JS7TaskHistory | Get-JS7TaskLog | Out-File /tmp/history/tasks.log -Encodi= ng Unicode
Explanation:
Reads the logs of today's tasks and writes the logs to a common file= .
Ge= t-JS7TaskHistory -RelativeDateFrom -8h | Get-JS7TaskLog | Select-Object @{n= ame=3D'path'; expression=3D{ "/tmp/$(Get-Date $_.startTime -f 'yyyyMMdd-hhm= mss')-$([io.path]::GetFileNameWithoutExtension($_.job)).task.log"}}, @{name= =3D'value'; expression=3D{ $_.log }} | Set-Content
Explanation:
Reads the logs of tasks that have completed within the last 8 hours =
and writes the log output to individual files in the /tmp
dire=
ctory.
The log file names are created from the start time and from the job = name of each task.
# = execute once $lastHistory =3D Get-JS7TaskHistory -RelativeDateFrom -8h | Sort-Object -Pr= operty startTime # execute in intervals Get-JS7TaskHistory -DateFrom $lastHistory[0].startTime | Tee-Object -Variab= le lastHistory | Get-JS7TaskLog | Select-Object @{name=3D'path'; expression= =3D{ "/tmp/$(Get-Date $_.startTime -f 'yyyyMMdd-hhmmss')-$([io.path]::GetFi= leNameWithoutExtension($_.job)).task.log"}}, @{name=3D'value'; expression= =3D{ $_.log }} | Set-Content
Explanation:
Provides a mechanism to subsequently retrieve previous logs. Startin=
g from initial execution of the Get-JS7TaskHistory
cmdlet, the=
resulting $lastHistory
object is used for any subsequent call=
s.
Consider use of the Tee-Object
cmdlet in the pipeline that upd=
ates the $lastHistory
object which can be used for later execu=
tions of the same pipeline.
This pipeline can e.g. be executed in a cyclic job.
A workflow is created that runs the above commands in a cycle. The workf= low operates 24/7 and writes task logs to files.
Download (.json upload): pdwTaskLogsToFiles.workflow.json
Explanation:
get-history-task-logs
is executed at th=
e point in time when the order arrives that starts the workflow.
write-task-logs-to-files
is executed w=
ithin a JS7 - Cycle Instru=
ction:
The first job get-history-task-logs
looks like this:
#!= /usr/bin/env pwsh Import-Module JS7 Connect-JS7 -Url http://root:root@localhost:4446 -Id Controller | Out-Null $lastHistory =3D Get-JS7TaskHistory -RelativeDateFrom -30m | Sort-Object -P= roperty startTime # forward a variable for the object "lastHistory=3Djson:$($lastHistory | ConvertTo-Json -Compress)" | Out-F= ile $env:JS7_RETURN_VALUES -Append Disconnect-JS7
Explanation:
#!= /usr/bin/env pwsh
@@= findstr/v "^@@f.*&" "%~f0"|pwsh.exe -&goto:eof
Controller
.the Get-JS7TaskHistory
cmdlet for which task lo=
gs should be created. This variable is in fact a PowerShell object that is =
serialized to JSON and prefixed with the string json:
for late=
r use with the second job in the workflow.The second job write-task-logs-to-files
looks like thi=
s:
#!= /usr/bin/env pwsh Import-Module JS7 Connect-JS7 -Url http://root:root@localhost:4446 -Id Controller | Out-Null # restore object from json by a temporary file $lastHistory =3D ( (Get-Content $env:LAST_HISTORY_FILE).Substring(5) | = ConvertFrom-Json ) Get-JS7TaskHistory -DateFrom $lastHistory[0].startTime | Tee-Object -Variab= le lastHistory | Get-JS7TaskLog | Select-Object @{name=3D'path'; expression= =3D{ "/tmp/history/$(Get-Date $_.startTime -f 'yyyyMMdd-hhmmss')-$([io.path= ]::GetFileNameWithoutExtension($_.job)).task.log"}}, @{name=3D'value'; expr= ession=3D{ $_.log }} | Set-Content # forward a variable for the object "lastHistory=3Djson:$($lastHistory | ConvertTo-Json -Compress)" | Out-F= ile $env:JS7_RETURN_VALUES -Append Disconnect-JS7
Explanation:
Line 10: When reading the task history then the variable carrying th= e list of task log objects is updated and is forwarded to the workflow for = next execution of the cycle.