functions/external-vaults/Search-TssExternalVaultLog.ps1
|
function Search-TssExternalVaultLog { <# .SYNOPSIS Search the log of an external vault .DESCRIPTION Lists the log entries of an external vault (pulls, pushes and their errors), optionally filtered by log level and message text. .PARAMETER TssSession TssSession object created by New-TssSession for authentication .PARAMETER Id External vault id .PARAMETER LogLevel Only return entries with these numeric log levels, as shown in the LogLevel property of the entries .PARAMETER SearchText Only return entries whose message matches this text .EXAMPLE $session = New-TssSession -SecretServer https://alpha -Credential $ssCred Search-TssExternalVaultLog -TssSession $session -Id 2 List the log of external vault 2 .EXAMPLE $session = New-TssSession -SecretServer https://alpha -Credential $ssCred Search-TssExternalVaultLog -TssSession $session -Id 2 -SearchText timeout List the log entries of external vault 2 that mention timeout .LINK https://thycotic-ps.github.io/thycotic.secretserver/commands/external-vaults/Search-TssExternalVaultLog .LINK https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/external-vaults/Search-TssExternalVaultLog.ps1 .NOTES Requires TssSession object returned by New-TssSession #> [CmdletBinding()] [OutputType('Thycotic.PowerShell.ExternalVaults.Log[]')] param ( [Parameter(Mandatory, ValueFromPipeline, Position = 0)] [Thycotic.PowerShell.Authentication.Session] $TssSession, [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [Alias('ExternalVaultId')] [int[]] $Id, [int[]] $LogLevel, [string] $SearchText ) begin { $tssParams = $PSBoundParameters $invokeParams = . $GetInvokeApiParams $TssSession } process { Get-TssInvocation $PSCmdlet.MyInvocation if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) { Compare-TssVersion $TssSession '11.7.000000' $PSCmdlet.MyInvocation foreach ($currentId in $Id) { $restResponse = $null $uri = $TssSession.ApiUrl, 'external-vaults', 'vaults', $currentId, 'logs' -join '/' $queryParams = @() $queryParams += "take=$($TssSession.Take)" switch ($tssParams.Keys) { 'LogLevel' { foreach ($queryValue in $LogLevel) { $queryParams += "filter.logLevel=$($queryValue)" } } 'SearchText' { $queryParams += "filter.searchText=$([uri]::EscapeDataString($SearchText))" } } if ($queryParams) { $uri = $uri, ($queryParams -join '&') -join '?' } $invokeParams.Uri = $uri $invokeParams.Method = 'GET' Write-Verbose "Performing the operation $($invokeParams.Method) $uri" try { $apiResponse = Invoke-TssApi @invokeParams $restResponse = . $ProcessResponse $apiResponse } catch { Write-Warning 'Issue with Search-TssExternalVaultLog request' $err = $_ . $ErrorHandling $err } if ($restResponse.records) { [Thycotic.PowerShell.ExternalVaults.Log[]](. $FilterTssResponse $restResponse.records ([Thycotic.PowerShell.ExternalVaults.Log])) } } } else { Write-Warning 'No valid session found' } } } |