Skip to content

Commit 48acd16

Browse files
authored
[Az.Network] Updated New-AzNetworkWatcherPacketCaptureV2 command and added a new sub command 'New-AzPacketCaptureSettingsConfig' for Network watcher Packet capture include ring buffer change. (#27880)
1 parent 0af8446 commit 48acd16

17 files changed

+8303
-21
lines changed

src/Accounts/Accounts/Utilities/CommandMappings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5158,6 +5158,7 @@
51585158
"New-AzP2sVpnGateway": {},
51595159
"New-AzPacketCaptureFilterConfig": {},
51605160
"New-AzPacketCaptureScopeConfig": {},
5161+
"New-AzPacketCaptureSettingsConfig": {},
51615162
"New-AzPrivateDnsZoneConfig": {},
51625163
"New-AzPrivateDnsZoneGroup": {},
51635164
"New-AzPrivateEndpoint": {},

src/Network/Network.Test/ScenarioTests/NetworkWatcherAPITests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,22 @@ public void TestPacketCaptureVMSS()
7373
TestRunner.RunTestScript("Test-PacketCaptureV2");
7474
}
7575

76+
[Fact]
77+
[Trait(Category.AcceptanceType, Category.CheckIn)]
78+
[Trait(Category.Owner, NrpTeamAlias.netanalyticsdev)]
79+
public void TestPacketCaptureVMWithRingBuffer()
80+
{
81+
TestRunner.RunTestScript("Test-PacketCaptureV2ForVMWithRingBuffer");
82+
}
83+
84+
[Fact]
85+
[Trait(Category.AcceptanceType, Category.CheckIn)]
86+
[Trait(Category.Owner, NrpTeamAlias.netanalyticsdev)]
87+
public void TestPacketCaptureVMSSWithRingBuffer()
88+
{
89+
TestRunner.RunTestScript("Test-PacketCaptureV2WithRingBuffer");
90+
}
91+
7692
[Fact]
7793
[Trait(Category.AcceptanceType, Category.LiveOnly)]
7894
[Trait(Category.Owner, NrpTeamAlias.netanalyticsdev)]

src/Network/Network.Test/ScenarioTests/NetworkWatcherAPITests.ps1

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,175 @@ function Test-PacketCaptureV2 {
674674
}
675675
}
676676

677+
<#
678+
.SYNOPSIS
679+
Test PacketCapture API for VM.
680+
#>
681+
function Test-PacketCaptureV2ForVMWithRingBuffer {
682+
# Setup
683+
$resourceGroupName = Get-NrpResourceGroupName
684+
$nwName = Get-NrpResourceName
685+
$location = Get-PilotLocation
686+
$resourceTypeParent = "Microsoft.Network/networkWatchers"
687+
$nwLocation = Get-ProviderLocation $resourceTypeParent
688+
$nwRgName = Get-NrpResourceGroupName
689+
$templateFile = (Resolve-Path ".\TestData\Deployment.json").Path
690+
$pcName1 = Get-NrpResourceName
691+
692+
try {
693+
. ".\AzureRM.Resources.ps1"
694+
695+
# Create Resource group
696+
New-AzResourceGroup -Name $resourceGroupName -Location "$location"
697+
698+
# Deploy resources
699+
Get-TestResourcesDeployment -rgn "$resourceGroupName"
700+
701+
# Create Resource group for Network Watcher
702+
New-AzResourceGroup -Name $nwRgName -Location "$location"
703+
704+
# Get Network Watcher
705+
$nw = Get-CreateTestNetworkWatcher -location $location -nwName $nwName -nwRgName $nwRgName
706+
707+
#Get Vm
708+
$vm = Get-AzVM -ResourceGroupName $resourceGroupName
709+
710+
#Install networkWatcherAgent on Vm
711+
Set-AzVMExtension -ResourceGroupName "$resourceGroupName" -Location "$location" -VMName $vm.Name -Name "AzureNetworkWatcherExtension" -Publisher "Microsoft.Azure.NetworkWatcher" -Type "NetworkWatcherAgentWindows" -TypeHandlerVersion "1.4"
712+
713+
# Create Capture settiings for packet capture, its only applicable if we are pass continuousCapture as true/false
714+
$c1 = New-AzPacketCaptureSettingsConfig -FileCount 2 -FileSizeInBytes 102400 -SessionTimeLimitInSeconds 60
715+
716+
#Create packet capture
717+
$job = New-AzNetworkWatcherPacketCaptureV2 -NetworkWatcher $nw -Name $pcName1 -TargetId $vm.Id -ContinuousCapture $true -CaptureSetting $c1 -LocalPath C:\captures\Capture.cap -AsJob
718+
$job | Wait-Job
719+
720+
#Get packet capture
721+
$job = Get-AzNetworkWatcherPacketCapture -NetworkWatcher $nw -PacketCaptureName $pcName1 -AsJob
722+
$job | Wait-Job
723+
$pc1 = $job | Receive-Job
724+
725+
Write-Output "pc1 Name: $($pc1.Name)"
726+
727+
#Verification
728+
Assert-AreEqual $pc1.Name $pcName1
729+
Assert-AreEqual "Succeeded" $pc1.ProvisioningState
730+
Assert-AreEqual 2 $c1.FileCount
731+
Assert-AreEqual 102400 $c1.FileSizeInBytes
732+
Assert-AreEqual 60 $c1.SessionTimeLimitInSeconds
733+
Assert-Null $pc1.TotalBytesPerSession
734+
Assert-Null $pc1.TimeLimitInSeconds
735+
736+
#Stop packet capture
737+
$job = Stop-AzNetworkWatcherPacketCapture -NetworkWatcher $nw -PacketCaptureName $pcName1 -AsJob
738+
$job | Wait-Job
739+
740+
#Get packet capture
741+
$pc1 = Get-AzNetworkWatcherPacketCapture -NetworkWatcher $nw -PacketCaptureName $pcName1
742+
743+
#Remove packet capture
744+
$job = Remove-AzNetworkWatcherPacketCapture -NetworkWatcher $nw -PacketCaptureName $pcName1 -AsJob
745+
$job | Wait-Job
746+
}
747+
finally {
748+
# Cleanup
749+
Clean-ResourceGroup $resourceGroupName
750+
#Clean-ResourceGroup $nwRgName
751+
}
752+
}
753+
754+
<#
755+
.SYNOPSIS
756+
Test PacketCapture API with ring buffer.
757+
#>
758+
function Test-PacketCaptureV2WithRingBuffer {
759+
# Setup
760+
$resourceGroupName = Get-NrpResourceGroupName
761+
$virtualMachineScaleSetName = Get-NrpResourceName
762+
$nwName = Get-NrpResourceName
763+
$location = Get-PilotLocation
764+
$resourceTypeParent = "Microsoft.Network/networkWatchers"
765+
$nwLocation = Get-ProviderLocation $resourceTypeParent
766+
$nwRgName = Get-NrpResourceGroupName
767+
$templateFileVMSS = (Resolve-Path ".\TestData\DeploymentVMSS.json").Path
768+
$pcName = Get-NrpResourceName
769+
$pcName3 = $pcName + "2"
770+
771+
try {
772+
. ".\AzureRM.Resources.ps1"
773+
774+
# Create Resource group
775+
New-AzResourceGroup -Name $resourceGroupName -Location "$location"
776+
777+
# Deploy resources
778+
Get-TestResourcesDeploymentVMSS -rgn "$resourceGroupName"
779+
780+
#Get public IP address
781+
$address = Get-AzPublicIpAddress -ResourceGroupName $resourceGroupName
782+
783+
# Create Resource group for Network Watcher
784+
New-AzResourceGroup -Name $nwRgName -Location "$location"
785+
786+
# Get Network Watcher
787+
$nw = Get-CreateTestNetworkWatcher -location $location -nwName $nwName -nwRgName $nwRgName
788+
789+
Wait-Seconds 600
790+
791+
#Get Vmss and Instances
792+
$vmss = Get-AzVmss -ResourceGroupName $resourceGroupName -VMScaleSetName $virtualMachineScaleSetName
793+
794+
#Install networkWatcherAgent on Vmss and Vmss Instances
795+
Add-AzVmssExtension -VirtualMachineScaleSet $vmss -Name "AzureNetworkWatcherExtension" -Publisher "Microsoft.Azure.NetworkWatcher" -Type "NetworkWatcherAgentWindows" -TypeHandlerVersion "1.4" -AutoUpgradeMinorVersion $True
796+
Update-AzVmss -ResourceGroupName "$resourceGroupName" -Name $virtualMachineScaleSetName -VirtualMachineScaleSet $vmss
797+
798+
# Updating all VMSS instances with NW agent
799+
$instances = Get-AzVMSSVM -ResourceGroupName "$resourceGroupName" -VMScaleSetName $vmss.Name
800+
foreach ($item in $instances) {
801+
Update-AzVmssInstance -ResourceGroupName "$resourceGroupName" -VMScaleSetName $vmss.Name -InstanceId $item.InstanceID
802+
}
803+
804+
# Create Capture settiings for packet capture, its only applicable if we are pass continuousCapture as true/false
805+
$c1 = New-AzPacketCaptureSettingsConfig -FileCount 2 -FileSizeInBytes 102400 -SessionTimeLimitInSeconds 60
806+
807+
#Create packet capture
808+
# with Continuous Capture, if you are using continuousCapture, change it to local Path instead FilePath
809+
$job3 = New-AzNetworkWatcherPacketCaptureV2 -NetworkWatcher $nw -Name $pcName3 -TargetId $vmss.Id -TargetType "azurevmss" -ContinuousCapture $false -CaptureSetting $c1 -LocalPath C:\captures\Capture.cap -AsJob
810+
$job3 | Wait-Job
811+
812+
Start-TestSleep -Seconds 2
813+
814+
#Get packet capture
815+
$job3 = Get-AzNetworkWatcherPacketCapture -NetworkWatcher $nw -PacketCaptureName $pcName3 -AsJob
816+
$job3 | Wait-Job
817+
$pc3 = $job3 | Receive-Job
818+
819+
#Write-Output ("PC3: '$pc3'")
820+
821+
#Verification
822+
Assert-AreEqual $pc3.Name $pcName3
823+
Assert-AreEqual "Succeeded" $pc3.ProvisioningState
824+
Assert-AreEqual 2 $c1.FileCount
825+
Assert-AreEqual 102400 $c1.FileSizeInBytes
826+
Assert-AreEqual 60 $c1.SessionTimeLimitInSeconds
827+
Assert-Null $pc3.TotalBytesPerSession
828+
Assert-Null $pc3.TimeLimitInSeconds
829+
Assert-AreEqual $pc3.TargetType AzureVMSS
830+
831+
#Stop packet capture
832+
$job3 = Stop-AzNetworkWatcherPacketCapture -NetworkWatcher $nw -PacketCaptureName $pcName3 -AsJob
833+
$job3 | Wait-Job
834+
835+
#Remove packet capture
836+
$job3 = Remove-AzNetworkWatcherPacketCapture -NetworkWatcher $nw -PacketCaptureName $pcName3 -AsJob
837+
$job3 | Wait-Job
838+
}
839+
finally {
840+
# Cleanup
841+
Clean-ResourceGroup $resourceGroupName
842+
#Clean-ResourceGroup $nwRgName
843+
}
844+
}
845+
677846
<#
678847
.SYNOPSIS
679848
Test Troubleshoot API.

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.NetworkWatcherAPITests/TestPacketCaptureVMSSWithRingBuffer.json

Lines changed: 4484 additions & 0 deletions
Large diffs are not rendered by default.

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.NetworkWatcherAPITests/TestPacketCaptureVMWithRingBuffer.json

Lines changed: 3167 additions & 0 deletions
Large diffs are not rendered by default.

src/Network/Network/Az.Network.psd1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate',
475475
'New-AzNetworkWatcherPacketCaptureV2',
476476
'New-AzNetworkWatcherProtocolConfiguration',
477477
'New-AzO365PolicyProperty', 'New-AzOffice365PolicyProperty',
478-
'New-AzP2sVpnGateway', 'New-AzPacketCaptureFilterConfig',
478+
'New-AzP2sVpnGateway', 'New-AzPacketCaptureFilterConfig',
479+
'New-AzPacketCaptureSettingsConfig',
479480
'New-AzPacketCaptureScopeConfig', 'New-AzPrivateDnsZoneConfig',
480481
'New-AzPrivateDnsZoneGroup', 'New-AzPrivateEndpoint',
481482
'New-AzPrivateEndpointIpConfiguration', 'New-AzPrivateLinkService',

src/Network/Network/ChangeLog.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
--->
2020

2121
## Upcoming Release
22+
* Added a new command which creates an object for CaptureSetting, and added properties 'FileCount', 'FileSizeInBytes', and 'SessionTimeLimitInSeconds', which helps to configure the capture setting for packet capture as well as support for it for the following cmdlets:
23+
- `New-AzPacketCaptureSettingsConfig`
24+
* Added properties 'ContinuousCapture', 'LocalPath', and 'CaptureSetting' reference in Packet capture V2 command, as well as support for it for the following cmdlets:
25+
- `New-AzNetworkWatcherPacketCaptureV2`
2226
* Onboarded Application Gateway WAF Exceptions cmdlet.
23-
- `New-AzApplicationGatewayFirewallPolicyException`
27+
- `New-AzApplicationGatewayFirewallPolicyException`
2428

2529
## Version 7.17.0
2630
* Added properties 'PublicIpAddressesV6', 'PublicIpPrefixesV6', and 'SourceVirtualNetwork' to NatGateway, as well as support for it for the following cmdlets:
@@ -1443,4 +1447,4 @@
14431447
- New-AzApplicationGatewaySslCertificate
14441448
- Set-AzApplicationGatewaySslCertificate
14451449
- New-AzApplicationGateway cmdlet updated with optional parameter -UserAssignedIdentityId, -UserAssignedIdentity
1446-
* Add MaxCapacity property in ApplicationGatewayAutoscaleConfiguration
1450+
* Add MaxCapacity property in ApplicationGatewayAutoscaleConfiguration

src/Network/Network/Models/PSGetPacketCaptureResult.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ public class PSGetPacketCaptureResult : PSChildResource
6060
[JsonProperty(Order = 1)]
6161
public List<PSPacketCaptureFilter> Filters { get; set; }
6262

63+
[JsonProperty(Order = 2)]
64+
public bool? ContinuousCapture { get; set; }
65+
66+
[JsonProperty(Order = 3)]
67+
public PSPacketCaptureSettings CaptureSettings { get; set; }
68+
6369
[JsonIgnore]
6470
public string FiltersText
6571
{
@@ -84,6 +90,12 @@ public string PacketCaptureErrorText
8490
get { return JsonConvert.SerializeObject(this.PacketCaptureError, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
8591
}
8692

93+
[JsonIgnore]
94+
public string CaptureSettingsText
95+
{
96+
get { return JsonConvert.SerializeObject(this.CaptureSettings, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
97+
}
98+
8799
public bool ShouldSerializePacketCaptureError()
88100
{
89101
return !string.IsNullOrEmpty(this.Name);

src/Network/Network/Models/PSPacketCaptureResult.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ public class PSPacketCaptureResult : PSChildResource
4646
[JsonProperty(Order = 1)]
4747
public List<PSPacketCaptureFilter> Filters { get; set; }
4848

49+
[JsonProperty(Order = 2)]
50+
public bool? ContinuousCapture { get; set; }
51+
52+
[JsonProperty(Order = 3)]
53+
public PSPacketCaptureSettings CaptureSettings { get; set; }
54+
4955
[JsonIgnore]
5056
public string FiltersText
5157
{
@@ -64,6 +70,12 @@ public string StorageLocationText
6470
get { return JsonConvert.SerializeObject(this.StorageLocation, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
6571
}
6672

73+
[JsonIgnore]
74+
public string CaptureSettingsText
75+
{
76+
get { return JsonConvert.SerializeObject(this.CaptureSettings, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
77+
}
78+
6779
public bool ShouldSerializeStorageLocation()
6880
{
6981
return !string.IsNullOrEmpty(this.Name);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.Azure.Commands.Network.Models
16+
{
17+
using Microsoft.WindowsAzure.Commands.Common.Attributes;
18+
using Newtonsoft.Json;
19+
20+
public class PSPacketCaptureSettings
21+
{
22+
/// <summary>
23+
/// Gets or sets number of file count.
24+
/// </summary>
25+
[JsonProperty(Order = 1)]
26+
[Ps1Xml(Target = ViewControl.Table)]
27+
public int? FileCount { get; set; }
28+
29+
/// <summary>
30+
/// Gets or sets number of bytes captured per packet.
31+
/// </summary>
32+
[JsonProperty(Order = 2)]
33+
[Ps1Xml(Target = ViewControl.Table)]
34+
public long? FileSizeInBytes { get; set; }
35+
36+
/// <summary>
37+
/// Gets or sets maximum duration of the capture session in seconds.
38+
/// </summary>
39+
[JsonProperty(Order = 3)]
40+
[Ps1Xml(Target = ViewControl.Table)]
41+
public int? SessionTimeLimitInSeconds { get; set; }
42+
}
43+
}

0 commit comments

Comments
 (0)