From 6054c7aae44ca9583854bb16a7028c183aa943b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Moreau?= Date: Fri, 13 Sep 2024 15:26:19 +0200 Subject: [PATCH 1/5] Add Get-FGTMonitorSystemInterfaceDHCPStatus --- .../monitor/system/interface/dhcp-status.ps1 | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 PowerFGT/Public/monitor/system/interface/dhcp-status.ps1 diff --git a/PowerFGT/Public/monitor/system/interface/dhcp-status.ps1 b/PowerFGT/Public/monitor/system/interface/dhcp-status.ps1 new file mode 100644 index 000000000..5fe3719d9 --- /dev/null +++ b/PowerFGT/Public/monitor/system/interface/dhcp-status.ps1 @@ -0,0 +1,41 @@ +# +# Copyright 2024, Cedric Moreau +# +# SPDX-License-Identifier: Apache-2.0 +# +function Get-FGTMonitorSystemInterfaceDHCPStatus { + + <# + .SYNOPSIS + Get Interface DHCP Status + + .DESCRIPTION + Get Client DHCP Status for an interface (Fortiguard, forticare....) + + .EXAMPLE + Get-FGTMonitorSystemInterfaceDHCPStatus + + Get License Status with status, version and last_update + + #> + + Param( + [Parameter (Mandatory = $true, Position = 1)] + [string]$interface, + [Parameter(Mandatory = $false)] + [psobject]$connection = $DefaultFGTConnection + ) + + Begin { + } + + Process { + + $uri = "api/v2/monitor/system/interface/dhcp-status?mkey=$($interface)" + $response = Invoke-FGTRestMethod -uri $uri -method 'GET' -connection $connection + $response.results + } + + End { + } +} From b1949e2f1b1e59b00f2c4527a046bf71a6348e3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Moreau?= Date: Mon, 16 Sep 2024 11:20:09 +0200 Subject: [PATCH 2/5] Wrtie exemples --- PowerFGT/Public/monitor/system/interface/dhcp-status.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PowerFGT/Public/monitor/system/interface/dhcp-status.ps1 b/PowerFGT/Public/monitor/system/interface/dhcp-status.ps1 index 5fe3719d9..3be83a51f 100644 --- a/PowerFGT/Public/monitor/system/interface/dhcp-status.ps1 +++ b/PowerFGT/Public/monitor/system/interface/dhcp-status.ps1 @@ -10,12 +10,12 @@ function Get-FGTMonitorSystemInterfaceDHCPStatus { Get Interface DHCP Status .DESCRIPTION - Get Client DHCP Status for an interface (Fortiguard, forticare....) + Get Client DHCP Status for an interface .EXAMPLE - Get-FGTMonitorSystemInterfaceDHCPStatus + Get-FGTMonitorSystemInterfaceDHCPStatus -interface wan - Get License Status with status, version and last_update + Get DHCP Client status for the specified interface wan #> From c0957376f5f41858e461fc8ce04756171166aba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Moreau?= Date: Mon, 16 Sep 2024 11:48:25 +0200 Subject: [PATCH 3/5] add vdom parameter --- PowerFGT/Public/monitor/system/interface/dhcp-status.ps1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/PowerFGT/Public/monitor/system/interface/dhcp-status.ps1 b/PowerFGT/Public/monitor/system/interface/dhcp-status.ps1 index 3be83a51f..8b893cca7 100644 --- a/PowerFGT/Public/monitor/system/interface/dhcp-status.ps1 +++ b/PowerFGT/Public/monitor/system/interface/dhcp-status.ps1 @@ -23,6 +23,8 @@ function Get-FGTMonitorSystemInterfaceDHCPStatus { [Parameter (Mandatory = $true, Position = 1)] [string]$interface, [Parameter(Mandatory = $false)] + [String[]]$vdom, + [Parameter(Mandatory = $false)] [psobject]$connection = $DefaultFGTConnection ) @@ -31,6 +33,10 @@ function Get-FGTMonitorSystemInterfaceDHCPStatus { Process { + if ( $PsBoundParameters.ContainsKey('vdom') ) { + $invokeParams.add( 'vdom', $vdom ) + } + $uri = "api/v2/monitor/system/interface/dhcp-status?mkey=$($interface)" $response = Invoke-FGTRestMethod -uri $uri -method 'GET' -connection $connection $response.results From 8a664ab88110de914d538f7069f22380923c39c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Moreau?= Date: Mon, 16 Sep 2024 11:53:43 +0200 Subject: [PATCH 4/5] add connectin.tests.ps1 --- Tests/integration/Connection.Tests.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Tests/integration/Connection.Tests.ps1 b/Tests/integration/Connection.Tests.ps1 index c2e7349be..6b172ebff 100644 --- a/Tests/integration/Connection.Tests.ps1 +++ b/Tests/integration/Connection.Tests.ps1 @@ -301,6 +301,9 @@ Describe "Connect to a FortiGate (using multi connection)" { It "Use Multi connection for call Get Monitor System HA Checksum (< 6.2.0 with no HA)" -skip:( -Not $VersionIs60WithNoHA) { { Get-FGTMonitorSystemHAChecksum -connection $fgt } | Should -Throw "You can't check HA Checksum with FortiOS < 6.2.0" } + It "Use Multi connection for call Get Monitor System Interface DHCP Status" { + { Get-FGTMonitorSystemInterfaceDHCPStatus -interface port1 -connection $fgt } | Should -Not -Throw + } It "Use Multi connection for call Get Monitor License Status" { { Get-FGTMonitorLicenseStatus -connection $fgt } | Should -Not -Throw } From 951b8a5933a48ffdfd7d371f201f62ca6ed9129e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Moreau?= Date: Mon, 16 Sep 2024 11:54:28 +0200 Subject: [PATCH 5/5] fix connectin.tests.ps1 --- 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 6b172ebff..d9d0572cb 100644 --- a/Tests/integration/Connection.Tests.ps1 +++ b/Tests/integration/Connection.Tests.ps1 @@ -302,7 +302,7 @@ Describe "Connect to a FortiGate (using multi connection)" { { Get-FGTMonitorSystemHAChecksum -connection $fgt } | Should -Throw "You can't check HA Checksum with FortiOS < 6.2.0" } It "Use Multi connection for call Get Monitor System Interface DHCP Status" { - { Get-FGTMonitorSystemInterfaceDHCPStatus -interface port1 -connection $fgt } | Should -Not -Throw + { Get-FGTMonitorSystemInterfaceDHCPStatus -interface $pester_port1 -connection $fgt } | Should -Not -Throw } It "Use Multi connection for call Get Monitor License Status" { { Get-FGTMonitorLicenseStatus -connection $fgt } | Should -Not -Throw