Truncate SWD_DeploymentResults.log
Log In or Register to download the BES file, and more.

0 Votes

Description

This fixlet takes the last 200 lines of SWD_DeploymentResults.log and discards the rest. It's relevant for logfiles with over 300 lines, giving 100 lines of wiggle room before it becomes relevant again.

Property Details

ID27331
StatusQA - Ready for Production Level Testing
TitleTruncate SWD_DeploymentResults.log
SourceInternal
Source Release Date3/12/2024 12:00:00 AM
KeywordsTruncate, log, SWD, SWD_DeploymentResults, reduce, logging, shorten, tail
Is TaskTrue
Added by on 3/13/2024 7:48:44 AM
Last Modified by on 3/13/2024 7:50:44 AM
Counters 132 Views / 0 Downloads
User Rating 1 star 2 star 3 star 4 star 5 star * Average over 0 ratings. ** Log In or Register to add your rating.

Relevance

Used in 1 fixlet   * Results in a true/false
Show indented relevance
number of lines of file "SWD_DeploymentResults.log" of folder "SWDDeployData" of folder "__Global" of data folder of client > 300

Actions

Action 1 (default)

Action Link Click here to deploy this action.
Script Type BigFix Action Script
parameter "mainSWDLogFolder" = "{parent folder of client folder of current site}/__Global/SWDDeployData"
folder create "{parameter "mainSWDLogFolder"}"
parameter "logFile" = "SWD_DeploymentResults.log"
parameter "logFolder" = "{parameter "mainSWDLogFolder"}"

parameter "logPath" = "{pathname of file "SWD_DeploymentResults.log" of folder "SWDDeployData" of folder "__Global" of data folder of client}"
parameter "targetLength" = "200"

if {windows of operating system}
waithidden cmd.exe /C echo %DATE% %TIME% >> "{parameter "logFolder"}\{parameter "logFile"}"
waithidden cmd.exe /C echo Action ID: {id of active action} >> "{parameter "logFolder"}\{parameter "logFile"}"
delete prometheus.ps1
delete __createfile
createfile until _EOF_
$truncatedContent = Get-Content "{parameter "logPath"}" -tail {parameter "targetLength"}
Remove-Item -Path "{parameter "logPath"}"
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
[System.IO.File]::WriteAllLines("{parameter "logPath"}", $truncatedContent, $Utf8NoBomEncoding)
#https://stackoverflow.com/a/5596984/5458134
Copy-Item "SWD_DeploymentResults.log" -Destination "{parameter "logPath"}"
Remove-Item -Path "SWD_DeploymentResults.log"
_EOF_
copy "__createfile" "prometheus.ps1"
waithidden powershell.exe -executionpolicy bypass -File "prometheus.ps1"
parameter "error" = "{exit code of action}"
waithidden cmd.exe /C echo Log truncated to {parameter "targetLength"} lines >> "{parameter "logFolder"}\{parameter "logFile"}"
waithidden cmd.exe /C echo Return Code: {parameter "error"} >> "{parameter "logFolder"}\{parameter "logFile"}"
waithidden cmd.exe /C echo. >> "{parameter "logFolder"}\{parameter "logFile"}"
delete "prometheus.ps1"

else
wait sh -c "echo '' >> '{parameter "mainSWDLogFolder"}/{parameter "logFile"}'"
wait sh -c "echo $(date +%Y_%m_%d' '%T) >> '{parameter "mainSWDLogFolder"}/{parameter "logFile"}'"
wait sh -c "echo Action ID: {id of active action} >> '{parameter "mainSWDLogFolder"}/{parameter "logFile"}'"
delete prometheus.sh
delete __createfile
createfile until _EOF_
#!/bin/sh
tail -n {parameter "targetLength"} "{parameter "logPath"}" > SWD_DeploymentResults.log
rm -rf "{parameter "logPath"}"
mv -f SWD_DeploymentResults.log "{parameter "logPath"}"
rm -rf SWD_DeploymentResults.log
_EOF_
copy "__createfile" "prometheus.sh"
wait chmod +x "prometheus.sh"
wait /bin/sh "prometheus.sh"
parameter "error" = "{exit code of action}"
wait sh -c "echo Log truncated to {parameter "targetLength"} lines >> '{parameter "mainSWDLogFolder"}/{parameter "logFile"}'"
wait sh -c "echo Return Code: {parameter "error"} >> '{parameter "mainSWDLogFolder"}/{parameter "logFile"}'"
delete "prometheus.sh"
endif

if {parameter "error" != "0"}
exit {parameter "error"}
endif

exit {parameter "error"}
Success Criteria

This action will be considered successful when the applicability relevance evaluates to false.


Sharing

Social Media:
Share this page on Yammer

Comments

Log In or Register to leave comments!