-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from alagoutte/ping
Add Test-ArubaSWPing cmdlet
- Loading branch information
Showing
4 changed files
with
133 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# | ||
# Copyright 2018-2020, Alexis La Goutte <alexis dot lagoutte at gmail dot com> | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
function Test-ArubaSWPing { | ||
|
||
<# | ||
.SYNOPSIS | ||
Send a PING (ICMP) to a target | ||
.DESCRIPTION | ||
Send a PING (ICMP) to a target | ||
Get the status and latency | ||
.EXAMPLE | ||
Test-ArubaSWPing -ipv4_address 192.2.0.1 | ||
Send a PING to IPv4 address 192.2.0.1 | ||
.EXAMPLE | ||
Test-ArubaSWPing -hostname www.arubanetworks.com | ||
Send a PING to hostname www.arubanetworks.com | ||
#> | ||
|
||
Param( | ||
[Parameter (Mandatory = $false, ParameterSetName = "ipv4_address")] | ||
[ipaddress]$ipv4_address, | ||
[Parameter (Mandatory = $false, ParameterSetName = "hostname")] | ||
[string]$hostname, | ||
[Parameter (Mandatory = $False)] | ||
[ValidateNotNullOrEmpty()] | ||
[PSObject]$connection = $DefaultArubaSWConnection | ||
) | ||
|
||
Begin { | ||
} | ||
|
||
Process { | ||
|
||
$uri = "rest/v4/ping" | ||
$dest = New-Object -TypeName PSObject | ||
|
||
if ($PsBoundParameters.ContainsKey('ipv4_address')) { | ||
|
||
$ipv4 = New-Object -TypeName PSObject | ||
$ipv4 | Add-Member -name "version" -MemberType NoteProperty -Value "IAV_IP_V4" | ||
|
||
$ipv4 | Add-Member -name "octets" -MemberType NoteProperty -Value $ipv4_address.ToString() | ||
|
||
$dest | Add-Member -name "ip_address" -Membertype NoteProperty -Value $ipv4 | ||
} | ||
elseif ($PsBoundParameters.ContainsKey('hostname')) { | ||
$dest | Add-Member -name "hostname" -Membertype NoteProperty -Value $hostname | ||
} | ||
else { | ||
throw "You need to use a parameter (-ipv4_address, -hostname)" | ||
} | ||
|
||
$ping = New-Object -TypeName PSObject | ||
$ping | Add-Member -name "destination" -Membertype NoteProperty -Value $dest | ||
|
||
$response = Invoke-ArubaSWWebRequest -method "POST" -body $ping -uri $uri -connection $connection | ||
|
||
$run = ($response | ConvertFrom-Json) | ||
$run | ||
} | ||
|
||
End { | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# | ||
# Copyright 2018-2020, Alexis La Goutte <alexis dot lagoutte at gmail dot com> | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
. ../common.ps1 | ||
|
||
Describe "Ping (ipv4_address)" { | ||
beforeAll { | ||
$script:ipv4_gateway = (Get-ArubaSWSystem).default_gateway.octets | ||
} | ||
|
||
It "Ping a valid IP(v4) address (Default Gateway:$script:ipv4_gateway)" { | ||
$ping = Test-ArubaSWPing -ipv4_address $script:ipv4_gateway | ||
$ping.result | Should -Be "PR_OK" | ||
$ping.rtt_in_milliseconds | Should -Not -BeNullOrEmpty | ||
} | ||
|
||
It "Ping a invalid IP(v4) address (0.0.0.0)" { | ||
$ping = Test-ArubaSWPing -ipv4_address 0.0.0.0 | ||
$ping.result | Should -Be "PR_INVALID_ADDRESS" | ||
} | ||
} | ||
|
||
|
||
Describe "Ping (-hostname)" { | ||
|
||
BeforeAll { | ||
#Always remove DNS Settings... | ||
Remove-ArubaSWDns -noconfirm | ||
} | ||
|
||
It "Ping a hostname (without DNS config)" { | ||
$ping = Test-ArubaSWPing -hostname www.arubanetworks.com | ||
$ping.result | Should -Be "PR_UNABLE_TO_RESOLVE_HOST_NAME" | ||
} | ||
|
||
It "Ping a hostname (with DNS config $pester_dns1 / $pester_dns2)" { | ||
#Configure DNS | ||
Set-ArubaSWDns -mode Manual -server1 $pester_dns1 -server2 $pester_dns2 | ||
$ping = Test-ArubaSWPing -hostname www.arubanetworks.com | ||
$ping.result | Should -Be "PR_OK" | ||
$ping.rtt_in_milliseconds | Should -Not -BeNullOrEmpty | ||
} | ||
|
||
AfterAll { | ||
#Always remove DNS Settings... | ||
Remove-ArubaSWDns -noconfirm | ||
} | ||
|
||
} | ||
|
||
Disconnect-ArubaSW -noconfirm |