-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
318 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# Search-TssSystemLog | ||
|
||
## SYNOPSIS | ||
Search the Secret Server System Log | ||
|
||
## SYNTAX | ||
|
||
``` | ||
Search-TssSystemLog [-TssSession] <Session> [-SearchText <String>] [-LogLevel <LogLevel>] [-SortBy <String>] | ||
[<CommonParameters>] | ||
``` | ||
|
||
## DESCRIPTION | ||
Search the Secret Server System Log | ||
|
||
## EXAMPLES | ||
|
||
### EXAMPLE 1 | ||
``` | ||
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred | ||
Search-TssSystemLog -TssSession $session -SearchText "powershell" | ||
``` | ||
|
||
Return Log messages matching the text "powershell" | ||
|
||
## PARAMETERS | ||
|
||
### -TssSession | ||
TssSession object created by New-TssSession for authentication | ||
|
||
```yaml | ||
Type: Session | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: True | ||
Position: 1 | ||
Default value: None | ||
Accept pipeline input: True (ByValue) | ||
Accept wildcard characters: False | ||
``` | ||
### -SearchText | ||
Text to search for in System Log | ||
```yaml | ||
Type: String | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -LogLevel | ||
Log Level to filter on | ||
```yaml | ||
Type: LogLevel | ||
Parameter Sets: (All) | ||
Aliases: | ||
Accepted values: Emergency, Alert, Critical, Error, Warning, Notice, Information, Debug | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -SortBy | ||
Sort by specific property, default SystemLogName | ||
```yaml | ||
Type: String | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: False | ||
Position: Named | ||
Default value: SystemLogName | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### CommonParameters | ||
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). | ||
## INPUTS | ||
## OUTPUTS | ||
### Thycotic.PowerShell.Diagnostics.SystemLog | ||
## NOTES | ||
Requires TssSession object returned by New-TssSession | ||
## RELATED LINKS | ||
[https://thycotic-ps.github.io/thycotic.secretserver/commands/diagnostics/Search-TssSystemLog](https://thycotic-ps.github.io/thycotic.secretserver/commands/diagnostics/Search-TssSystemLog) | ||
[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/diagnostics/Search-TssSystemLog.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/diagnostics/Search-TssSystemLog.ps1) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/Thycotic.SecretServer/classes/diagnostics/SystemLog.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using System.Management.Automation; | ||
using System.Management.Automation.Runspaces; | ||
using Thycotic.PowerShell.Enums; | ||
|
||
namespace Thycotic.PowerShell.Diagnostics | ||
{ | ||
public class SystemLog | ||
{ | ||
public string CorrelationId { get; set; } | ||
public DateTime? DateRecorded { get; set; } | ||
public LogLevel LogLevel { get; set; } | ||
public string LogMessage { get; set; } | ||
public string MachineName { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using System.Management.Automation; | ||
using System.Management.Automation.Runspaces; | ||
|
||
namespace Thycotic.PowerShell.Enums | ||
{ | ||
public enum LogLevel | ||
{ | ||
Emergency, | ||
Alert, | ||
Critical, | ||
Error, | ||
Warning, | ||
Notice, | ||
Information, | ||
Debug | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
function Search-TssSystemLog { | ||
<# | ||
.SYNOPSIS | ||
Search the Secret Server System Log | ||
.DESCRIPTION | ||
Search the Secret Server System Log | ||
.LINK | ||
https://thycotic-ps.github.io/thycotic.secretserver/commands/diagnostics/Search-TssSystemLog | ||
.LINK | ||
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/diagnostics/Search-TssSystemLog.ps1 | ||
.EXAMPLE | ||
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred | ||
Search-TssSystemLog -TssSession $session -SearchText "powershell" | ||
Return Log messages matching the text "powershell" | ||
.EXAMPLE | ||
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred | ||
Search-TssSystemLog -TssSession $session -SearchText "Azure AD" | ||
Return Log messages matching the text "Azure AD" | ||
.NOTES | ||
Requires TssSession object returned by New-TssSession | ||
#> | ||
[CmdletBinding()] | ||
[OutputType('Thycotic.PowerShell.Diagnostics.SystemLog')] | ||
param ( | ||
# TssSession object created by New-TssSession for authentication | ||
[Parameter(Mandatory,ValueFromPipeline,Position = 0)] | ||
[Thycotic.PowerShell.Authentication.Session] | ||
$TssSession, | ||
|
||
# Text to search for in System Log | ||
[string] | ||
$SearchText, | ||
|
||
# Log Level to filter on | ||
[Thycotic.PowerShell.Enums.LogLevel] | ||
$LogLevel, | ||
|
||
# Sort by specific property, default DateRecorded | ||
[string] | ||
$SortBy = 'DateRecorded' | ||
) | ||
begin { | ||
$tssParams = $PSBoundParameters | ||
$invokeParams = . $GetInvokeApiParams $TssSession | ||
} | ||
process { | ||
Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)" | ||
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) { | ||
. $CheckVersion $TssSession '11.0.000000' $PSCmdlet.MyInvocation | ||
$uri = ($TssSession.ApiUrl -replace 'v1','v2'), 'diagnostics', 'system-logs' -join '/' | ||
$uri = $uri, "sortBy[0].direction=desc&sortBy[0].name=$SortBy&take=$($TssSession.Take)" -join '?' | ||
$invokeParams.Method = 'GET' | ||
|
||
$filters = @() | ||
switch ($tssParams.Keys) { | ||
'SearchText' { $filters += "filter.searchTerm=$SearchText" } | ||
'LogLevel' { $filters += "filter.logLevel=$LogLevel"} | ||
} | ||
if ($filters) { | ||
$uriFilter = $filters -join '&' | ||
Write-Verbose "Filters: $uriFilter" | ||
$uri = $uri, $uriFilter -join '&' | ||
} | ||
$invokeParams.Uri = $uri | ||
|
||
Write-Verbose "Performing the operation $($invokeParams.Method) $uri" | ||
try { | ||
$apiResponse = Invoke-TssApi @invokeParams | ||
$restResponse = . $ProcessResponse $apiResponse | ||
} catch { | ||
Write-Warning "Issue on search request" | ||
$err = $_ | ||
. $ErrorHandling $err | ||
} | ||
|
||
if ($restResponse.records.Count -le 0 -and $restResponse.records.Length -eq 0) { | ||
Write-Warning "No messages found in the System Log" | ||
} | ||
if ($restResponse.records) { | ||
[Thycotic.PowerShell.Diagnostics.SystemLog[]]$restResponse.records | ||
} | ||
} else { | ||
Write-Warning "No valid session found" | ||
} | ||
} | ||
} |
Oops, something went wrong.