Step-01: User Parameters

Step-02: Password Parameter

Step-03: Host parameter

Step-04: Powershell Build Script
[code lang=powershell]
# Stopping the job if it encounters error, ignoring warnings
$ErrorActionPreference = ‘Stop’
$warningPreference = ‘SilentlyContinue’
# Credentials are stored in env and dynamic variables
$SecurePassword = ${ENV:Password} | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList ${ENV:User}, $SecurePassword
# Parameters
[String]$AEMENVNUM = (${ENV:myhost} | %{ $_.Split(‘,’)[3]; })
[String]$AEMENV = (${ENV:myhost} | %{ $_.Split(‘,’)[2]; })
[String]$HOSTENV = (${ENV:myhost} | %{ $_.Split(‘,’)[1]; })
[String]$ServerName = (${ENV:myhost} | %{ $_.Split(‘,’)[0]; })
# Logic to parse the error log
[ScriptBlock]$SDScriptBlock = {
param($AEMENV,$ServerName,$HOSTENV,$AEMENVNUM)
write-output “Executing ErrorLogParsing on HOST Environment=${HOSTENV}, AEM Environment=${AEMENV}, AEM Instance Number=${AEMENVNUM}”
$PATH = “C:\Users\SKYDEVOPS\Desktop\testenv\${AEMENV}\logs\error.log”
$OUTPATH = “C:\Users\SKYDEVOPS\Desktop\backups\”
$TIMESTAMP = $(get-date -f yyyy_MM_dd_hhmmss)
$REGEX = “^.*\*\b(ERROR)\b\*.*$”
select-string -Path $PATH -Pattern $REGEX -AllMatches | % { $_.Matches } | % { $_.Value } | % { $_.substring($_.indexOf(‘:’)+19) } | Get-Unique | Group-object | Format-Table -Wrap -AutoSize -Property Count,Group > ${OUTPATH}errorLogFilter-$AEMENV-$TIMESTAMP.log
}
# Invoke a command on the remote machine.
Invoke-Command -ComputerName $ServerName -Credential $cred -ScriptBlock ${SDScriptBlock} -ArgumentList $AEMENV,$ServerName,$HOSTENV,$AEMENVNUM
[/code]
Step-05: Console Output

Step-06: Parsed Log Output

No comments:
Post a Comment
If you have any doubts or questions, please let us know.