Skip to content

Commit

Permalink
Get-TssDiagnosticBackgroundProcess - new command to get the backgroun…
Browse files Browse the repository at this point in the history
…d process details
  • Loading branch information
wsmelton committed Oct 7, 2021
1 parent a5b3425 commit bd91027
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 0 deletions.
58 changes: 58 additions & 0 deletions docs/commands/diagnostics/Get-TssDiagnosticBackgroundProcess.md
@@ -0,0 +1,58 @@
# Get-TssDiagnosticBackgroundProcess

## SYNOPSIS
Get background process information

## SYNTAX

```
Get-TssDiagnosticBackgroundProcess [-TssSession] <Session> [<CommonParameters>]
```

## DESCRIPTION
Get background process information

## EXAMPLES

### EXAMPLE 1
```
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Get-TssDiagnosticBackgroundProcess -TssSession $session
```

Return background process information

## 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
```

### 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.BackgroundProcess
## NOTES
Requires TssSession object returned by New-TssSession

## RELATED LINKS

[https://thycotic-ps.github.io/thycotic.secretserver/commands/diagnostics/Get-TssDiagnosticBackgroundProcess](https://thycotic-ps.github.io/thycotic.secretserver/commands/diagnostics/Get-TssDiagnosticBackgroundProcess)

[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/diagnostics/Get-TssDiagnosticBackgroundProcess.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/diagnostics/Get-TssDiagnosticBackgroundProcess.ps1)

38 changes: 38 additions & 0 deletions src/Thycotic.SecretServer.Format.ps1xml
Expand Up @@ -3596,5 +3596,43 @@
</TableControl>
</View>

<!-- Thycotic.PowerShell.Diagnostics.BackgroundProcess -->
<View>
<Name>Diagnostics.BackgroundProcess</Name>
<ViewSelectedBy>
<TypeName>Thycotic.PowerShell.Diagnostics.BackgroundProcess</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>ThreadName</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>LastActivity</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>IdentityName</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Hostname</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>ManagedThreadId</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>

</ViewDefinitions>
</Configuration>
17 changes: 17 additions & 0 deletions src/Thycotic.SecretServer/classes/diagnostics/BackgroundProcess.cs
@@ -0,0 +1,17 @@
using System;
using System.Threading.Tasks;
using System.Management.Automation;
using System.Management.Automation.Runspaces;

namespace Thycotic.PowerShell.Diagnostics
{
public class BackgroundProcess
{
public string ApplicationName { get; set; }
public string Hostname { get; set; }
public string IdentityName { get; set; }
public DateTime? LastActivity { get; set; }
public int ManagedThreadId { get; set; }
public string ThreadName { get; set; }
}
}
61 changes: 61 additions & 0 deletions src/functions/diagnostics/Get-TssDiagnosticBackgroundProcess.ps1
@@ -0,0 +1,61 @@
function Get-TssDiagnosticBackgroundProcess {
<#
.SYNOPSIS
Get background process information
.DESCRIPTION
Get background process information
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Get-TssDiagnosticBackgroundProcess -TssSession $session
Return background process information
.LINK
https://thycotic-ps.github.io/thycotic.secretserver/commands/diagnostics/Get-TssDiagnosticBackgroundProcess
.LINK
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/diagnostics/Get-TssDiagnosticBackgroundProcess.ps1
.NOTES
Requires TssSession object returned by New-TssSession
#>
[CmdletBinding()]
[OutputType('Thycotic.PowerShell.Diagnostics.BackgroundProcess')]
param (
# TssSession object created by New-TssSession for authentication
[Parameter(Mandatory,ValueFromPipeline,Position = 0)]
[Thycotic.PowerShell.Authentication.Session]
$TssSession
)
begin {
$tssParams = $PSBoundParameters
$invokeParams = . $GetInvokeApiParams $TssSession
}
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'diagnostics', 'background-processes' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'GET'

Write-Verbose "Performing the operation $($invokeParams.Method) $($invokeParams.Uri)"
try {
$apiResponse = Invoke-TssApi @invokeParams
$restResponse = . $ProcessResponse $apiResponse
} catch {
Write-Warning "Issue getting reference name on [$var name]"
$err = $_
. $ErrorHandling $err
}

if ($restResponse) {
[Thycotic.PowerShell.Diagnostics.BackgroundProcess[]]$restResponse
}
} else {
Write-Warning "No valid session found"
}
}
}
24 changes: 24 additions & 0 deletions tests/diagnostics/Get-TssDiagnosticBackgroundProcess.Tests.ps1
@@ -0,0 +1,24 @@
BeforeDiscovery {
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf
}
Describe "$commandName verify parameters" {
BeforeDiscovery {
[object[]]$knownParameters = 'TssSession'
[object[]]$currentParams = ([Management.Automation.CommandMetaData]$ExecutionContext.SessionState.InvokeCommand.GetCommand($commandName,'Function')).Parameters.Keys
[object[]]$commandDetails = [System.Management.Automation.CommandInfo]$ExecutionContext.SessionState.InvokeCommand.GetCommand($commandName,'Function')
$unknownParameters = Compare-Object -ReferenceObject $knownParameters -DifferenceObject $currentParams -PassThru
}
Context "Verify parameters" -Foreach @{currentParams = $currentParams } {
It "$commandName should contain <_> parameter" -TestCases $knownParameters {
$_ -in $currentParams | Should -Be $true
}
It "$commandName should not contain parameter: <_>" -TestCases $unknownParameters {
$_ | Should -BeNullOrEmpty
}
}
Context "Command specific details" {
It "$commandName should set OutputType to Thycotic.PowerShell.Diagnostics.BackgroundProcess" -TestCases $commandDetails {
$_.OutputType.Name | Should -Be 'Thycotic.PowerShell.Diagnostics.BackgroundProcess'
}
}
}

0 comments on commit bd91027

Please sign in to comment.