From fa39b76c93f5132012206d75ba4774d77a1ac048 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Sun, 8 Dec 2024 21:04:35 +0100 Subject: [PATCH 1/4] Address(FQDN): add Get-FGTMonitorFirewallAddressFQDN for get status and number of addrs --- .../Public/monitor/firewall/address-fqdn.ps1 | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 PowerFGT/Public/monitor/firewall/address-fqdn.ps1 diff --git a/PowerFGT/Public/monitor/firewall/address-fqdn.ps1 b/PowerFGT/Public/monitor/firewall/address-fqdn.ps1 new file mode 100644 index 000000000..af9d3948a --- /dev/null +++ b/PowerFGT/Public/monitor/firewall/address-fqdn.ps1 @@ -0,0 +1,57 @@ +# +# Copyright 2022, Alexis La Goutte +# +# SPDX-License-Identifier: Apache-2.0 +# +function Get-FGTMonitorFirewallAddressFQDN { + + <# + .SYNOPSIS + Get Monitor Firewall Address FQDN + + .DESCRIPTION + Get Monitor Firewall Adresss FQDN (fqdn, addrs, addrs_count...) + + .EXAMPLE + Get-FGTMonitorFirewallAddressFQDN + + Get ALL Firewall Address FQDN + + .EXAMPLE + Get-FGTMonitorFirewallAddressFQDN -vdom vdomX + + Get Firewall Address FQDN of vdomX + + #> + + Param( + [Parameter (Mandatory = $false)] + [switch]$skip, + [Parameter(Mandatory = $false)] + [String[]]$vdom, + [Parameter(Mandatory = $false)] + [psobject]$connection = $DefaultFGTConnection + ) + + Begin { + } + + Process { + + $invokeParams = @{ } + if ( $PsBoundParameters.ContainsKey('skip') ) { + $invokeParams.add( 'skip', $skip ) + } + if ( $PsBoundParameters.ContainsKey('vdom') ) { + $invokeParams.add( 'vdom', $vdom ) + } + + $uri = 'api/v2/monitor/firewall/address-fqdns?' + + $response = Invoke-FGTRestMethod -uri $uri -method 'GET' -connection $connection @invokeParams + $response.results + } + + End { + } +} From 40ceba7206035c40755603868cfe7bc1f8313232 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Sun, 8 Dec 2024 21:11:38 +0100 Subject: [PATCH 2/4] Address(FQDN): add -fqdn parameter to monitor --- PowerFGT/Public/monitor/firewall/address-fqdn.ps1 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/PowerFGT/Public/monitor/firewall/address-fqdn.ps1 b/PowerFGT/Public/monitor/firewall/address-fqdn.ps1 index af9d3948a..33735e4d0 100644 --- a/PowerFGT/Public/monitor/firewall/address-fqdn.ps1 +++ b/PowerFGT/Public/monitor/firewall/address-fqdn.ps1 @@ -17,6 +17,11 @@ function Get-FGTMonitorFirewallAddressFQDN { Get ALL Firewall Address FQDN + .EXAMPLE + Get-FGTMonitorFirewallAddressFQDN -fqdn github.com + + Get Firewall Address FQDN of github.com + .EXAMPLE Get-FGTMonitorFirewallAddressFQDN -vdom vdomX @@ -25,6 +30,8 @@ function Get-FGTMonitorFirewallAddressFQDN { #> Param( + [Parameter (Mandatory = $false, Position = 1)] + [string]$fqdn, [Parameter (Mandatory = $false)] [switch]$skip, [Parameter(Mandatory = $false)] @@ -48,6 +55,10 @@ function Get-FGTMonitorFirewallAddressFQDN { $uri = 'api/v2/monitor/firewall/address-fqdns?' + if ($fqdn) { + $uri += "mkey=$($fqdn)" + } + $response = Invoke-FGTRestMethod -uri $uri -method 'GET' -connection $connection @invokeParams $response.results } From 28fe291d14cf48ddd4f406aa702056ebc0403d39 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Sun, 8 Dec 2024 21:13:12 +0100 Subject: [PATCH 3/4] READMe(.md): Add Get-FGTMonitorFirewallAddressFQDN --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 54f19c47d..10cb07215 100644 --- a/README.md +++ b/README.md @@ -1298,6 +1298,7 @@ You need to have VPN IPsec Interface Phase 1 created before It is possible to `monitor` FortiGate +* `Get-FGTMonitorFirewallAddressFQDN` List of FQDN address objects and the IPs they resolved to * `Get-FGTMonitorFirewallPolicy` List traffic statistics for firewall policies * `Get-FGTMonitorFirewallSession` List all active firewall sessions * `Get-FGTMonitorRouterIPv4` List all active IPv4 routing table entries From 039b15523daaefede20bc95e18b8f73d637700e6 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Sun, 8 Dec 2024 21:14:37 +0100 Subject: [PATCH 4/4] Address(FQDN): add Tests --- 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 a2ab67888..f8daaadb7 100644 --- a/Tests/integration/Connection.Tests.ps1 +++ b/Tests/integration/Connection.Tests.ps1 @@ -274,6 +274,9 @@ Describe "Connect to a FortiGate (using multi connection)" { It "Use Multi connection for call Get Webfilter Profile" { { Get-FGTWebfilterProfile -connection $fgt } | Should -Not -Throw } + It "Use Multi connection for call Get Monitor Firewall Address FQDN" { + { Get-FGTMonitorFirewallAddressFQDN -connection $fgt } | Should -Not -Throw + } It "Use Multi connection for call Get Monitor Firewall Policy" { { Get-FGTMonitorFirewallPolicy -connection $fgt } | Should -Not -Throw }