Skip to content

Commit

Permalink
Get-TssDiagnosticConnectivityReport - new command to get the Internet…
Browse files Browse the repository at this point in the history
… connection test
  • Loading branch information
wsmelton committed Oct 7, 2021
1 parent 608485a commit a5b3425
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 0 deletions.
58 changes: 58 additions & 0 deletions docs/commands/diagnostics/Get-TssDiagnosticConnectivityReport.md
@@ -0,0 +1,58 @@
# Get-TssDiagnosticConnectivityReport

## SYNOPSIS
Get Connectivity Report

## SYNTAX

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

## DESCRIPTION
Get Connectivity Report, built-in test to check for Internet connectivity (google.com, yahoo.com and updates.thycotic.net)

## EXAMPLES

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

Return test results for Internet connection from Secret Server web node

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

## RELATED LINKS

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

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

@@ -0,0 +1,13 @@
using System;
using System.Threading.Tasks;
using System.Management.Automation;
using System.Management.Automation.Runspaces;

namespace Thycotic.PowerShell.Diagnostics
{
public class ConnectivityReport
{
public string Address {get; set;}
public bool IsSuccess {get;set;}
}
}
75 changes: 75 additions & 0 deletions src/functions/diagnostics/Get-TssDiagnosticConnectivityReport.ps1
@@ -0,0 +1,75 @@
function Get-TssDiagnosticConnectivityReport {
<#
.SYNOPSIS
Get Connectivity Report
.DESCRIPTION
Get Connectivity Report, built-in test to check for Internet connectivity (google.com, yahoo.com and updates.thycotic.net)
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Get-TssDiagnosticConnectivityReport -TssSession $session
Return test results for Internet connection from Secret Server web node
.LINK
https://thycotic-ps.github.io/thycotic.secretserver/commands/diagnostics/Get-TssDiagnosticConnectivityReport
.LINK
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/diagnostics/Get-TssDiagnosticConnectivityReport.ps1
.NOTES
Requires TssSession object returned by New-TssSession
#>
[CmdletBinding()]
[OutputType('Thycotic.PowerShell.Diagnostics.ConnectivityReport')]
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', 'connectivity-report' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'GET'

Write-Verbose "$($invokeParams.Method) $uri with: `n$($invokeParams.Body)"
try {
$apiResponse = Invoke-TssApi @invokeParams
$restResponse = . $ProcessResponse $apiResponse
} catch {
Write-Warning 'Issue warning message'
$err = $_
. $ErrorHandling $err
}

if ($restResponse) {
$results = $restResponse.Trim('"').Split(' ')
foreach ($r in $results) {
if ($r) {
switch ($r) {
{ $_ -match 'yahoo.com' } { $address = 'www.yahoo.com' }
{ $_ -match 'google.com' } { $address = 'www.google.com' }
{ $_ -match 'updates.thycotic.net' } { $address = 'updates.thycotic.net' }
}
[boolean]$successful = if ($results[1].split(']')[1].Trim() -match 'FAILED') { $false } else { $true }
[Thycotic.PowerShell.Diagnostics.ConnectivityReport]@{
Address = $address
IsSuccess = $successful
}
}
}
}
} else {
Write-Warning 'No valid session found'
}
}
}
24 changes: 24 additions & 0 deletions tests/diagnostics/Get-TssDiagnosticConnectivityReport.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.ConnectivityReport" -TestCases $commandDetails {
$_.OutputType.Name | Should -Be 'Thycotic.PowerShell.Diagnostics.ConnectivityReport'
}
}
}

0 comments on commit a5b3425

Please sign in to comment.