From d6a3c01fead30ebcfac7839295b6a0b0687ca59b Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Wed, 24 Feb 2021 20:58:50 +0100 Subject: [PATCH 01/15] DeviceFingerprint: Add Get-ArubaCPDeviceFingerprint you can get with ip_address or mac_address --- PowerArubaCP/Public/DeviceFingerprint.ps1 | 65 +++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 PowerArubaCP/Public/DeviceFingerprint.ps1 diff --git a/PowerArubaCP/Public/DeviceFingerprint.ps1 b/PowerArubaCP/Public/DeviceFingerprint.ps1 new file mode 100644 index 0000000..3781c10 --- /dev/null +++ b/PowerArubaCP/Public/DeviceFingerprint.ps1 @@ -0,0 +1,65 @@ +# +# Copyright 2021, Alexis La Goutte +# +# SPDX-License-Identifier: Apache-2.0 +# + + +function Get-ArubaCPDeviceFingerprint { + + <# + .SYNOPSIS + Get Device Fingerprint info on CPPM + + .DESCRIPTION + Get Device Fingerprint (hostname, ip, device category/name/family) + + .EXAMPLE + Get-ArubaCPDeviceFingerprint -mac_adress 000102030405 + + Get Device FingerPrint about Endpoint 000102030405 Aruba on the ClearPass + + .EXAMPLE + Get-ArubaCPDeviceFingerprint -ip_address 192.0.2.1 + + Get Device FingerPrint about Endpoint 192.0.2.1 Aruba on the ClearPass + + #> + + Param( + [Parameter (ParameterSetName = "mac_address", Mandatory = $true)] + [string]$mac_address, + [Parameter (ParameterSetName = "ip_address", Mandatory = $true)] + [IPAddress]$ip_address, + [Parameter (Mandatory = $false)] + [ValidateNotNullOrEmpty()] + [PSObject]$connection = $DefaultArubaCPConnection + ) + + Begin { + } + + Process { + + $invokeParams = @{ } + + $uri = "api/device-profiler/device-fingerprint/" + + switch ( $PSCmdlet.ParameterSetName ) { + "mac_address" { + $uri += $mac_address + } + "ip_address" { + $uri += $ip_address.ToString() + } + default { } + } + + $dfp = Invoke-ArubaCPRestMethod -method "GET" -uri $uri @invokeParams -connection $connection + + $dfp + } + + End { + } +} \ No newline at end of file From 5ed18ffde6e90a6a7c91e4b9cf1cdbb6a3737c03 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Thu, 25 Feb 2021 09:34:48 +0100 Subject: [PATCH 02/15] DeviceFingerprint: Add pipeline for Get-ArubaCPDeviceFingerprint with Get-ArubaCPEndpoint --- PowerArubaCP/Public/DeviceFingerprint.ps1 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/PowerArubaCP/Public/DeviceFingerprint.ps1 b/PowerArubaCP/Public/DeviceFingerprint.ps1 index 3781c10..e88cac2 100644 --- a/PowerArubaCP/Public/DeviceFingerprint.ps1 +++ b/PowerArubaCP/Public/DeviceFingerprint.ps1 @@ -19,6 +19,11 @@ function Get-ArubaCPDeviceFingerprint { Get Device FingerPrint about Endpoint 000102030405 Aruba on the ClearPass + .EXAMPLE + Get-ArubaCPEndpoint 000102030405 | Get-ArubaCPDeviceFingerprint + + Get Device FingerPrint using Endpoint 000102030405 + .EXAMPLE Get-ArubaCPDeviceFingerprint -ip_address 192.0.2.1 @@ -31,6 +36,9 @@ function Get-ArubaCPDeviceFingerprint { [string]$mac_address, [Parameter (ParameterSetName = "ip_address", Mandatory = $true)] [IPAddress]$ip_address, + [Parameter (ParameterSetName = "endpoint", Mandatory = $true, ValueFromPipeline = $true)] + [ValidateScript( { Confirm-ArubaCPEndpoint $_ })] + [psobject]$endpoint, [Parameter (Mandatory = $false)] [ValidateNotNullOrEmpty()] [PSObject]$connection = $DefaultArubaCPConnection @@ -52,6 +60,9 @@ function Get-ArubaCPDeviceFingerprint { "ip_address" { $uri += $ip_address.ToString() } + "endpoint" { + $uri += $endpoint.mac_address + } default { } } From d2ecc9984170586adbc08dd4d58432ef35ef3a75 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Thu, 25 Feb 2021 14:28:15 +0100 Subject: [PATCH 03/15] DeviceFingerprint: Add-DeviceFingerprint You can add Device Fingerprint Endpoint (with Category, Family and Name) --- PowerArubaCP/Public/DeviceFingerprint.ps1 | 85 +++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/PowerArubaCP/Public/DeviceFingerprint.ps1 b/PowerArubaCP/Public/DeviceFingerprint.ps1 index e88cac2..6555fdd 100644 --- a/PowerArubaCP/Public/DeviceFingerprint.ps1 +++ b/PowerArubaCP/Public/DeviceFingerprint.ps1 @@ -4,6 +4,91 @@ # SPDX-License-Identifier: Apache-2.0 # +function Add-ArubaCPDeviceFingerprint { + + <# + .SYNOPSIS + Add an Endpoint on ClearPass + + .DESCRIPTION + Add an Endoint with mac address, description, status, attributes + + .EXAMPLE + Add-ArubaCPEndpoint -mac_address 000102030405 -description "Add by PowerArubaCP" -Status Known + + Add an Endpoint with MAC Address 000102030405 with Known Sattus and a description + + .EXAMPLE + Add-ArubaCPEndpoint -mac_address 00:01:02:03:04:06 -status Unknown + + Add an Endpoint with MAC Address 00:01:02:03:04:06 with Unknown Status + + .EXAMPLE + $attributes = @{"Disabled by"="PowerArubaCP"} + PS >Add-ArubaCPEndpoint -mac_address 000102-030407 -Status Disabled -attributes $attributes + + Add an Endpoint with MAC Address 000102030405 with Disabled Status and attributes to Disabled by PowerArubaCP + #> + + Param( + [Parameter (Mandatory = $true)] + [string]$mac_address, + [Parameter (Mandatory = $false)] + [string]$hostname, + [Parameter (Mandatory = $false)] + [string]$device_category, + [Parameter (Mandatory = $false)] + [string]$device_name, + [Parameter (Mandatory = $false)] + [string]$device_family, + [Parameter (Mandatory = $False)] + [ValidateNotNullOrEmpty()] + [PSObject]$connection = $DefaultArubaCPConnection + ) + + Begin { + } + + Process { + + $uri = "api/device-profiler/device-fingerprint" + + $_dfp = new-Object -TypeName PSObject + + + $_dfp | add-member -name "mac" -membertype NoteProperty -Value (Format-ArubaCPMacAddress $mac_address) + + if ( $PsBoundParameters.ContainsKey('hostname') ) { + $_dfp | add-member -name "hostname" -membertype NoteProperty -Value $hostname + } + + $_device = new-Object -TypeName PSObject + if ( $PsBoundParameters.ContainsKey('device_category') ) { + $_device | add-member -name "category" -membertype NoteProperty -Value $device_category + } + + if ( $PsBoundParameters.ContainsKey('device_name') ) { + $_device | add-member -name "name" -membertype NoteProperty -Value $device_name + } + + if ( $PsBoundParameters.ContainsKey('device_family') ) { + $_device | add-member -name "family" -membertype NoteProperty -Value $device_family + } + + $_dfp | add-member -name "device" -membertype NoteProperty -Value $_device + + <# + if ( $PsBoundParameters.ContainsKey('attributes') ) { + $_dfp | add-member -name "attributes" -membertype NoteProperty -Value $attributes + } + #> + $dfp = Invoke-ArubaCPRestMethod -method "POST" -body $_dfp -uri $uri -connection $connection + $dfp + } + + End { + } +} function Get-ArubaCPDeviceFingerprint { From 85df7d14930cd6bed10873b004e3fc9b33703cf1 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Tue, 9 Mar 2021 21:38:19 +0100 Subject: [PATCH 04/15] Connection(Tests): Add Multi Connection for Device Fingerprint --- Tests/integration/Connection.Tests.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Tests/integration/Connection.Tests.ps1 b/Tests/integration/Connection.Tests.ps1 index adcb13e..8f95e9c 100644 --- a/Tests/integration/Connection.Tests.ps1 +++ b/Tests/integration/Connection.Tests.ps1 @@ -76,6 +76,10 @@ Describe "Connect to a ClearPass (using multi connection)" { It "Use Multi connection for call Get Service" -Skip:$VersionBefore680 { { Get-ArubaCPService -connection $cppm } | Should -Not -Throw } + It "Use Multi connection for call Device Fingerprint" -Skip:$VersionBefore680 { + $ip = (Get-ArubaCPServerConfiguration -connection $cppm).management_ip + { Get-ArubaCPDeviceFingerprint -ip_address $ip -connection $cppm } | Should -Not -Throw + } } It "Disconnect to a ClearPass (Multi connection)" { From d5a61ba4bce0692e581471e9947c6a72b77f7619 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Tue, 9 Mar 2021 22:04:57 +0100 Subject: [PATCH 05/15] DeviceFingerprint: Add IP(Address) parameter --- PowerArubaCP/Public/DeviceFingerprint.ps1 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/PowerArubaCP/Public/DeviceFingerprint.ps1 b/PowerArubaCP/Public/DeviceFingerprint.ps1 index 6555fdd..991fa72 100644 --- a/PowerArubaCP/Public/DeviceFingerprint.ps1 +++ b/PowerArubaCP/Public/DeviceFingerprint.ps1 @@ -36,6 +36,8 @@ function Add-ArubaCPDeviceFingerprint { [Parameter (Mandatory = $false)] [string]$hostname, [Parameter (Mandatory = $false)] + [ipaddress]$ip_address, + [Parameter (Mandatory = $false)] [string]$device_category, [Parameter (Mandatory = $false)] [string]$device_name, @@ -62,6 +64,10 @@ function Add-ArubaCPDeviceFingerprint { $_dfp | add-member -name "hostname" -membertype NoteProperty -Value $hostname } + if ( $PsBoundParameters.ContainsKey('ip_address') ) { + $_dfp | add-member -name "ip" -membertype NoteProperty -Value $ip_address.ToString() + } + $_device = new-Object -TypeName PSObject if ( $PsBoundParameters.ContainsKey('device_category') ) { $_device | add-member -name "category" -membertype NoteProperty -Value $device_category @@ -77,11 +83,6 @@ function Add-ArubaCPDeviceFingerprint { $_dfp | add-member -name "device" -membertype NoteProperty -Value $_device - <# - if ( $PsBoundParameters.ContainsKey('attributes') ) { - $_dfp | add-member -name "attributes" -membertype NoteProperty -Value $attributes - } - #> $dfp = Invoke-ArubaCPRestMethod -method "POST" -body $_dfp -uri $uri -connection $connection $dfp } From 67635068bf69a65b48be570db5954c6de0a864ff Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Tue, 9 Mar 2021 22:05:38 +0100 Subject: [PATCH 06/15] DeviceFingerprint: Fix typo on Get Example --- PowerArubaCP/Public/DeviceFingerprint.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerArubaCP/Public/DeviceFingerprint.ps1 b/PowerArubaCP/Public/DeviceFingerprint.ps1 index 991fa72..572f60e 100644 --- a/PowerArubaCP/Public/DeviceFingerprint.ps1 +++ b/PowerArubaCP/Public/DeviceFingerprint.ps1 @@ -101,7 +101,7 @@ function Get-ArubaCPDeviceFingerprint { Get Device Fingerprint (hostname, ip, device category/name/family) .EXAMPLE - Get-ArubaCPDeviceFingerprint -mac_adress 000102030405 + Get-ArubaCPDeviceFingerprint -mac_address 000102030405 Get Device FingerPrint about Endpoint 000102030405 Aruba on the ClearPass From d8523dbdf22931f0da964f032dfb0e3170c93096 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Tue, 9 Mar 2021 22:22:33 +0100 Subject: [PATCH 07/15] DeviceFingerprint: Update Add EXAMPLE --- PowerArubaCP/Public/DeviceFingerprint.ps1 | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/PowerArubaCP/Public/DeviceFingerprint.ps1 b/PowerArubaCP/Public/DeviceFingerprint.ps1 index 572f60e..1982c3e 100644 --- a/PowerArubaCP/Public/DeviceFingerprint.ps1 +++ b/PowerArubaCP/Public/DeviceFingerprint.ps1 @@ -8,26 +8,25 @@ function Add-ArubaCPDeviceFingerprint { <# .SYNOPSIS - Add an Endpoint on ClearPass + Add a Device Fingerprint on ClearPass .DESCRIPTION - Add an Endoint with mac address, description, status, attributes + Add an Device Fingerprint with mac address, hostname, ip (address) and device info (Category, Name, Familly) .EXAMPLE - Add-ArubaCPEndpoint -mac_address 000102030405 -description "Add by PowerArubaCP" -Status Known + Add-ArubaCPDeviceFingerprint -mac_address 000102030405 -hostname "My PowerArubaCP Device Fingerprint" - Add an Endpoint with MAC Address 000102030405 with Known Sattus and a description + Add a Device Fingerprint with MAC Address 000102030405 and a hostname .EXAMPLE - Add-ArubaCPEndpoint -mac_address 00:01:02:03:04:06 -status Unknown + Add-ArubaCPDeviceFingerprint -mac_address 000102030405 -ip_address 192.0.2.1 - Add an Endpoint with MAC Address 00:01:02:03:04:06 with Unknown Status + Add a Device Fingerprint with MAC Address 000102030405 and an IP Address .EXAMPLE - $attributes = @{"Disabled by"="PowerArubaCP"} - PS >Add-ArubaCPEndpoint -mac_address 000102-030407 -Status Disabled -attributes $attributes + Add-ArubaCPDeviceFingerprint -mac_address 000102030405 -device_category Server -device_family ClearPass -device_name ClearPass VM - Add an Endpoint with MAC Address 000102030405 with Disabled Status and attributes to Disabled by PowerArubaCP + Add a Device Fingerprint with MAC Address 000102030405 with device information (Category, Name, Family) #> Param( From 8dda9484e00f2c5f18710fd086213d704642e5cf Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Tue, 9 Mar 2021 22:37:08 +0100 Subject: [PATCH 08/15] DeviceFingerprint(Tests): Add Test for Get (by mac_address or ip_address) --- Tests/integration/DeviceFingerprint.Tests.ps1 | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 Tests/integration/DeviceFingerprint.Tests.ps1 diff --git a/Tests/integration/DeviceFingerprint.Tests.ps1 b/Tests/integration/DeviceFingerprint.Tests.ps1 new file mode 100644 index 0000000..7c1339f --- /dev/null +++ b/Tests/integration/DeviceFingerprint.Tests.ps1 @@ -0,0 +1,67 @@ +# +# Copyright 2021, Alexis La Goutte +# +# SPDX-License-Identifier: Apache-2.0 +# +. ../common.ps1 + +BeforeAll { + Connect-ArubaCP @invokeParams +} + +Describe "Get Device FingerPrint" { + + BeforeAll { + #Add 2 entries + Add-ArubaCPDeviceFingerPrint -mac_address 00-01-02-03-04-05 -ip_address 192.0.2.1 + Add-ArubaCPDeviceFingerPrint -mac_address 00-01-02-03-04-06 -ip_address 192.0.2.2 + #Need to wait the time of profiling... (2 seconds...) + Start-Sleep 2 + } + + It "Get Endpoint (with mac filter) Does not throw an error" { + { + Get-ArubaCPDeviceFingerPrint -mac_address 00-01-02-03-04-05 + } | Should -Not -Throw + } + + It "Search Device Fingerprint by mac (00-01-02-03-04-05)" { + $dfp = Get-ArubaCPDeviceFingerprint -mac_address 000102030405 + $dfp.updated_at | Should -Not -BeNullOrEmpty + $dfp.added_at | Should -Not -BeNullOrEmpty + $dfp.mac | Should -Be "000102030405" + $dfp.device_category | Should -Not -BeNullOrEmpty + $dfp.device_name | Should -Not -BeNullOrEmpty + $dfp.device_family | Should -Not -BeNullOrEmpty + } + + It "Search Device Fingerprint by Endpoint pipeline (00-01-02-03-04-06)" { + $dfp = Get-ArubaCPEndpoint -mac_address 000102030406 | Get-ArubaCPDeviceFingerprint + $dfp.updated_at | Should -Not -BeNullOrEmpty + $dfp.added_at | Should -Not -BeNullOrEmpty + $dfp.mac | Should -Be "000102030406" + $dfp.device_category | Should -Not -BeNullOrEmpty + $dfp.device_name | Should -Not -BeNullOrEmpty + $dfp.device_family | Should -Not -BeNullOrEmpty + } + + It "Search Device Fingerprint by ip_address (192.0.2.2)" { + $dfp = Get-ArubaCPDeviceFingerprint -ip_address 192.0.2.2 + $dfp.updated_at | Should -Not -BeNullOrEmpty + $dfp.added_at | Should -Not -BeNullOrEmpty + $dfp.ip | Should -Be "192.0.2.2" + $dfp.device_category | Should -Not -BeNullOrEmpty + $dfp.device_name | Should -Not -BeNullOrEmpty + $dfp.device_family | Should -Not -BeNullOrEmpty + } + + AfterAll { + #Remove 2 entries + Get-ArubaCPEndpoint -mac_address 00-01-02-03-04-05 | Remove-ArubaCPEndpoint -confirm:$false + Get-ArubaCPEndpoint -mac_address 00-01-02-03-04-06 | Remove-ArubaCPEndpoint -confirm:$false + } +} + +AfterAll { + Disconnect-ArubaCP -confirm:$false +} \ No newline at end of file From fc2178819f2d5a6c8e5a73c6367d79850a290c30 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Tue, 9 Mar 2021 22:38:17 +0100 Subject: [PATCH 09/15] DeviceFingerprint(Tests): Add Test for Add (by hostname, ip_address, device) Need to use different mac address and delay (2 secs) for profiling... --- Tests/integration/DeviceFingerprint.Tests.ps1 | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/Tests/integration/DeviceFingerprint.Tests.ps1 b/Tests/integration/DeviceFingerprint.Tests.ps1 index 7c1339f..1072ea2 100644 --- a/Tests/integration/DeviceFingerprint.Tests.ps1 +++ b/Tests/integration/DeviceFingerprint.Tests.ps1 @@ -62,6 +62,53 @@ Describe "Get Device FingerPrint" { } } +Describe "Add Device Fingerprint" { + + It "Add Device Fingerprint with hostname" { + Add-ArubaCPDeviceFingerprint -mac_address 00-01-02-03-04-07 -hostname pester_PowerArubaCP + Start-Sleep 2 + $dfp = Get-ArubaCPDeviceFingerprint -mac_address 00-01-02-03-04-07 + $dfp.hostname | Should -be "pester_PowerArubaCP" + $dfp.updated_at | Should -Not -BeNullOrEmpty + $dfp.added_at | Should -Not -BeNullOrEmpty + $dfp.mac | Should -Be "000102030407" + $dfp.device_category | Should -Not -BeNullOrEmpty + $dfp.device_name | Should -Not -BeNullOrEmpty + $dfp.device_family | Should -Not -BeNullOrEmpty + } + + It "Add Device Fingerprint with IP (Address)" { + Add-ArubaCPDeviceFingerprint -mac_address 00-01-02-03-04-08 -ip_address 192.0.2.1 + Start-Sleep 2 + $dfp = Get-ArubaCPDeviceFingerprint -mac_address 00-01-02-03-04-08 + $dfp.ip | Should -be "192.0.2.1" + $dfp.updated_at | Should -Not -BeNullOrEmpty + $dfp.added_at | Should -Not -BeNullOrEmpty + $dfp.mac | Should -Be "000102030408" + $dfp.device_category | Should -Not -BeNullOrEmpty + $dfp.device_name | Should -Not -BeNullOrEmpty + $dfp.device_family | Should -Not -BeNullOrEmpty + } + + It "Add Device Fingerprint with device information" { + Add-ArubaCPDeviceFingerprint -mac_address 00-01-02-03-04-09 -device_category Server -device_family ClearPass -device_name ClearPass VM + Start-Sleep 2 + $dfp = Get-ArubaCPDeviceFingerprint -mac_address 00-01-02-03-04-09 + $dfp.updated_at | Should -Not -BeNullOrEmpty + $dfp.added_at | Should -Not -BeNullOrEmpty + $dfp.mac | Should -Be "000102030409" + $dfp.device_category | Should -Be "Server" + $dfp.device_name | Should -Be "Clearpass" + $dfp.device_family | Should -Be "ClearPass" + } + + AfterAll { + Get-ArubaCPEndpoint -mac_address 00-01-02-03-04-07 | Remove-ArubaCPEndpoint -confirm:$false + Get-ArubaCPEndpoint -mac_address 00-01-02-03-04-08 | Remove-ArubaCPEndpoint -confirm:$false + Get-ArubaCPEndpoint -mac_address 00-01-02-03-04-09 | Remove-ArubaCPEndpoint -confirm:$false + } +} + AfterAll { Disconnect-ArubaCP -confirm:$false } \ No newline at end of file From dbe4abbc1310299732e00087a86021ba4697461d Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Wed, 24 Mar 2021 07:51:39 +0100 Subject: [PATCH 10/15] DeviceFingerprint(Tests): Add Skip before 6.9.0 (it is not supported before CPPM 6.9.0) --- Tests/common.ps1 | 1 + Tests/integration/DeviceFingerprint.Tests.ps1 | 42 +++++++++++-------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/Tests/common.ps1 b/Tests/common.ps1 index 8e53d7f..6a87bf9 100644 --- a/Tests/common.ps1 +++ b/Tests/common.ps1 @@ -29,5 +29,6 @@ Connect-ArubaCP @invokeParams -SkipCertificateCheck $script:VersionBefore680 = $DefaultArubaCPConnection.Version -lt [version]"6.8.0" $script:VersionBefore686 = $DefaultArubaCPConnection.Version -lt [version]"6.8.6" +$script:VersionBefore690 = $DefaultArubaCPConnection.Version -lt [version]"6.9.0" Disconnect-ArubaCP -confirm:$false \ No newline at end of file diff --git a/Tests/integration/DeviceFingerprint.Tests.ps1 b/Tests/integration/DeviceFingerprint.Tests.ps1 index 1072ea2..c70fb7d 100644 --- a/Tests/integration/DeviceFingerprint.Tests.ps1 +++ b/Tests/integration/DeviceFingerprint.Tests.ps1 @@ -12,20 +12,22 @@ BeforeAll { Describe "Get Device FingerPrint" { BeforeAll { - #Add 2 entries - Add-ArubaCPDeviceFingerPrint -mac_address 00-01-02-03-04-05 -ip_address 192.0.2.1 - Add-ArubaCPDeviceFingerPrint -mac_address 00-01-02-03-04-06 -ip_address 192.0.2.2 - #Need to wait the time of profiling... (2 seconds...) - Start-Sleep 2 + if ($VersionBefore690 -eq 0) { + #Add 2 entries + Add-ArubaCPDeviceFingerPrint -mac_address 00-01-02-03-04-05 -ip_address 192.0.2.1 + Add-ArubaCPDeviceFingerPrint -mac_address 00-01-02-03-04-06 -ip_address 192.0.2.2 + #Need to wait the time of profiling... (2 seconds...) + Start-Sleep 2 + } } - It "Get Endpoint (with mac filter) Does not throw an error" { + It "Get Endpoint (with mac filter) Does not throw an error" -Skip:$VersionBefore690 { { Get-ArubaCPDeviceFingerPrint -mac_address 00-01-02-03-04-05 } | Should -Not -Throw } - It "Search Device Fingerprint by mac (00-01-02-03-04-05)" { + It "Search Device Fingerprint by mac (00-01-02-03-04-05)" -Skip:$VersionBefore690 { $dfp = Get-ArubaCPDeviceFingerprint -mac_address 000102030405 $dfp.updated_at | Should -Not -BeNullOrEmpty $dfp.added_at | Should -Not -BeNullOrEmpty @@ -35,7 +37,7 @@ Describe "Get Device FingerPrint" { $dfp.device_family | Should -Not -BeNullOrEmpty } - It "Search Device Fingerprint by Endpoint pipeline (00-01-02-03-04-06)" { + It "Search Device Fingerprint by Endpoint pipeline (00-01-02-03-04-06)" -Skip:$VersionBefore690 { $dfp = Get-ArubaCPEndpoint -mac_address 000102030406 | Get-ArubaCPDeviceFingerprint $dfp.updated_at | Should -Not -BeNullOrEmpty $dfp.added_at | Should -Not -BeNullOrEmpty @@ -45,7 +47,7 @@ Describe "Get Device FingerPrint" { $dfp.device_family | Should -Not -BeNullOrEmpty } - It "Search Device Fingerprint by ip_address (192.0.2.2)" { + It "Search Device Fingerprint by ip_address (192.0.2.2)" -Skip:$VersionBefore690 { $dfp = Get-ArubaCPDeviceFingerprint -ip_address 192.0.2.2 $dfp.updated_at | Should -Not -BeNullOrEmpty $dfp.added_at | Should -Not -BeNullOrEmpty @@ -56,15 +58,17 @@ Describe "Get Device FingerPrint" { } AfterAll { - #Remove 2 entries - Get-ArubaCPEndpoint -mac_address 00-01-02-03-04-05 | Remove-ArubaCPEndpoint -confirm:$false - Get-ArubaCPEndpoint -mac_address 00-01-02-03-04-06 | Remove-ArubaCPEndpoint -confirm:$false + if ($VersionBefore690 -eq 0) { + #Remove 2 entries + Get-ArubaCPEndpoint -mac_address 00-01-02-03-04-05 | Remove-ArubaCPEndpoint -confirm:$false + Get-ArubaCPEndpoint -mac_address 00-01-02-03-04-06 | Remove-ArubaCPEndpoint -confirm:$false + } } } Describe "Add Device Fingerprint" { - It "Add Device Fingerprint with hostname" { + It "Add Device Fingerprint with hostname" -Skip:$VersionBefore690 { Add-ArubaCPDeviceFingerprint -mac_address 00-01-02-03-04-07 -hostname pester_PowerArubaCP Start-Sleep 2 $dfp = Get-ArubaCPDeviceFingerprint -mac_address 00-01-02-03-04-07 @@ -77,7 +81,7 @@ Describe "Add Device Fingerprint" { $dfp.device_family | Should -Not -BeNullOrEmpty } - It "Add Device Fingerprint with IP (Address)" { + It "Add Device Fingerprint with IP (Address)" -Skip:$VersionBefore690 { Add-ArubaCPDeviceFingerprint -mac_address 00-01-02-03-04-08 -ip_address 192.0.2.1 Start-Sleep 2 $dfp = Get-ArubaCPDeviceFingerprint -mac_address 00-01-02-03-04-08 @@ -90,7 +94,7 @@ Describe "Add Device Fingerprint" { $dfp.device_family | Should -Not -BeNullOrEmpty } - It "Add Device Fingerprint with device information" { + It "Add Device Fingerprint with device information" -Skip:$VersionBefore690 { Add-ArubaCPDeviceFingerprint -mac_address 00-01-02-03-04-09 -device_category Server -device_family ClearPass -device_name ClearPass VM Start-Sleep 2 $dfp = Get-ArubaCPDeviceFingerprint -mac_address 00-01-02-03-04-09 @@ -103,9 +107,11 @@ Describe "Add Device Fingerprint" { } AfterAll { - Get-ArubaCPEndpoint -mac_address 00-01-02-03-04-07 | Remove-ArubaCPEndpoint -confirm:$false - Get-ArubaCPEndpoint -mac_address 00-01-02-03-04-08 | Remove-ArubaCPEndpoint -confirm:$false - Get-ArubaCPEndpoint -mac_address 00-01-02-03-04-09 | Remove-ArubaCPEndpoint -confirm:$false + if ($VersionBefore690 -eq 0) { + Get-ArubaCPEndpoint -mac_address 00-01-02-03-04-07 | Remove-ArubaCPEndpoint -confirm:$false + Get-ArubaCPEndpoint -mac_address 00-01-02-03-04-08 | Remove-ArubaCPEndpoint -confirm:$false + Get-ArubaCPEndpoint -mac_address 00-01-02-03-04-09 | Remove-ArubaCPEndpoint -confirm:$false + } } } From 756672724e122020bdce21967e3b94317dab83d4 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Wed, 24 Mar 2021 08:24:14 +0100 Subject: [PATCH 11/15] DeviceFingerprint: Add throw when using with CPPM <= 6.9.0 --- PowerArubaCP/Public/DeviceFingerprint.ps1 | 4 ++++ Tests/integration/DeviceFingerprint.Tests.ps1 | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/PowerArubaCP/Public/DeviceFingerprint.ps1 b/PowerArubaCP/Public/DeviceFingerprint.ps1 index 1982c3e..afe596f 100644 --- a/PowerArubaCP/Public/DeviceFingerprint.ps1 +++ b/PowerArubaCP/Public/DeviceFingerprint.ps1 @@ -134,6 +134,10 @@ function Get-ArubaCPDeviceFingerprint { Process { + if ($connection.version -lt [version]"6.9.0") { + throw "Need ClearPass >= 6.9.0 for use this cmdlet" + } + $invokeParams = @{ } $uri = "api/device-profiler/device-fingerprint/" diff --git a/Tests/integration/DeviceFingerprint.Tests.ps1 b/Tests/integration/DeviceFingerprint.Tests.ps1 index c70fb7d..ee30553 100644 --- a/Tests/integration/DeviceFingerprint.Tests.ps1 +++ b/Tests/integration/DeviceFingerprint.Tests.ps1 @@ -57,6 +57,10 @@ Describe "Get Device FingerPrint" { $dfp.device_family | Should -Not -BeNullOrEmpty } + It "Get Device Fingerprint throw a error when use with CPPM <= 6.9.0" -Skip: ($VersionBefore690 -eq 0) { + { Get-ArubaCPDeviceFingerprint -ip_address 192.0.2.2 } | Should -Throw "Need ClearPass >= 6.9.0 for use this cmdlet" + } + AfterAll { if ($VersionBefore690 -eq 0) { #Remove 2 entries From 84681f8a67ee22a1bf8a2996788d7d0e463810da Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Wed, 24 Mar 2021 08:26:52 +0100 Subject: [PATCH 12/15] Connection(Tests): Fix version before for Device Fingerprint Multi connection test --- Tests/integration/Connection.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/integration/Connection.Tests.ps1 b/Tests/integration/Connection.Tests.ps1 index 8f95e9c..e2152c6 100644 --- a/Tests/integration/Connection.Tests.ps1 +++ b/Tests/integration/Connection.Tests.ps1 @@ -76,7 +76,7 @@ Describe "Connect to a ClearPass (using multi connection)" { It "Use Multi connection for call Get Service" -Skip:$VersionBefore680 { { Get-ArubaCPService -connection $cppm } | Should -Not -Throw } - It "Use Multi connection for call Device Fingerprint" -Skip:$VersionBefore680 { + It "Use Multi connection for call Device Fingerprint" -Skip:$VersionBefore690 { $ip = (Get-ArubaCPServerConfiguration -connection $cppm).management_ip { Get-ArubaCPDeviceFingerprint -ip_address $ip -connection $cppm } | Should -Not -Throw } From 65f16da0817ccbdd21a5b3547cbbf53c78a6f05c Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Tue, 6 Apr 2021 08:15:36 +0200 Subject: [PATCH 13/15] DeviceFingerprint(Tests): Fix extra space after Describe --- Tests/integration/DeviceFingerprint.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/integration/DeviceFingerprint.Tests.ps1 b/Tests/integration/DeviceFingerprint.Tests.ps1 index ee30553..b3272ba 100644 --- a/Tests/integration/DeviceFingerprint.Tests.ps1 +++ b/Tests/integration/DeviceFingerprint.Tests.ps1 @@ -9,7 +9,7 @@ BeforeAll { Connect-ArubaCP @invokeParams } -Describe "Get Device FingerPrint" { +Describe "Get Device FingerPrint" { BeforeAll { if ($VersionBefore690 -eq 0) { @@ -70,7 +70,7 @@ Describe "Get Device FingerPrint" { } } -Describe "Add Device Fingerprint" { +Describe "Add Device Fingerprint" { It "Add Device Fingerprint with hostname" -Skip:$VersionBefore690 { Add-ArubaCPDeviceFingerprint -mac_address 00-01-02-03-04-07 -hostname pester_PowerArubaCP From d30fc54a9e2a887c55363747a945dd47c16ea4a6 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Sun, 11 Apr 2021 21:09:42 +0200 Subject: [PATCH 14/15] DeviceFingerprint: fix typo an -> a familly -> family --- PowerArubaCP/Public/DeviceFingerprint.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerArubaCP/Public/DeviceFingerprint.ps1 b/PowerArubaCP/Public/DeviceFingerprint.ps1 index afe596f..416b4f5 100644 --- a/PowerArubaCP/Public/DeviceFingerprint.ps1 +++ b/PowerArubaCP/Public/DeviceFingerprint.ps1 @@ -11,7 +11,7 @@ function Add-ArubaCPDeviceFingerprint { Add a Device Fingerprint on ClearPass .DESCRIPTION - Add an Device Fingerprint with mac address, hostname, ip (address) and device info (Category, Name, Familly) + Add a Device Fingerprint with mac address, hostname, ip (address) and device info (Category, Name, Family) .EXAMPLE Add-ArubaCPDeviceFingerprint -mac_address 000102030405 -hostname "My PowerArubaCP Device Fingerprint" From a9133a543f360e041a5f6e3c048f65da50944ae9 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Sun, 18 Apr 2021 14:21:07 +0200 Subject: [PATCH 15/15] DeviceFingerprint: fix blank line --- PowerArubaCP/Public/DeviceFingerprint.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/PowerArubaCP/Public/DeviceFingerprint.ps1 b/PowerArubaCP/Public/DeviceFingerprint.ps1 index 416b4f5..80706c2 100644 --- a/PowerArubaCP/Public/DeviceFingerprint.ps1 +++ b/PowerArubaCP/Public/DeviceFingerprint.ps1 @@ -56,7 +56,6 @@ function Add-ArubaCPDeviceFingerprint { $_dfp = new-Object -TypeName PSObject - $_dfp | add-member -name "mac" -membertype NoteProperty -Value (Format-ArubaCPMacAddress $mac_address) if ( $PsBoundParameters.ContainsKey('hostname') ) { @@ -156,7 +155,6 @@ function Get-ArubaCPDeviceFingerprint { } $dfp = Invoke-ArubaCPRestMethod -method "GET" -uri $uri @invokeParams -connection $connection - $dfp }