Skip to content

[Az.Network] Added a new command 'New-AzPacketCaptureSettingsConfig' for Network watcher Packet capture include ring buffer change with new updates #27869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
eee908c
Added Packet capture ring buffer change and its supporting command fo…
v-sapanchal May 16, 2025
321d70c
Added in mapping and changed the sub command name according other con…
v-sapanchal May 20, 2025
bb792d4
Merge branch 'Azure:main' into spanchal/pcap_ring_buffer
v-sapanchal May 20, 2025
4cfe836
Added sub command in Az.Network
v-sapanchal May 20, 2025
fdcc423
Merge branch 'spanchal/pcap_ring_buffer' of https://github.com/v-sapa…
v-sapanchal May 20, 2025
dfb86ee
Added valaidation for ring buffer and same for sub command
v-sapanchal May 21, 2025
72dc642
added help for both the commands (partial)
v-sapanchal May 22, 2025
b1a755e
resolve the validation condition for FilePath and StorageId
v-sapanchal May 22, 2025
489cc88
resolve gaps in test cases
v-sapanchal May 26, 2025
e213c65
Merge branch 'Azure:main' into spanchal/pcap_ring_buffer
v-sapanchal May 26, 2025
f8d62fe
change in validation and added test case for VMSS with continuous cap…
v-sapanchal May 26, 2025
f51d8ba
Updated the change log
v-sapanchal May 26, 2025
28645c8
#27841 Add Bleu cloud to Enter-AzVM (#27842)
JanZruba May 27, 2025
32f977d
[PS] Migrate SelfHelp module to autorest v4 (#27839)
JoyerJin May 27, 2025
24103b2
Corrected docs invalid related links (#27832)
mikefrobbins May 27, 2025
828cf87
Corrected docs other-site-link-broken build warnings (#27810)
mikefrobbins May 27, 2025
1baf730
[skip ci] Archive 887ebd06968ffd83181d4f1d76e95add6b72f4ed (#27845)
azure-powershell-bot May 27, 2025
ffc8be3
[skip ci] Archive 77db2d518eec600b907288a9150c5e65dfe66a68 (#27847)
azure-powershell-bot May 27, 2025
e135705
Default VM size update breaking change message (#27763)
grizzlytheodore May 27, 2025
eaff03a
Add Code Owners to the Module Folders (#27848)
msJinLei May 27, 2025
bb79a43
[skip ci] Archive e1357051271e9357c4abebca22a258a30e789d70 (#27849)
azure-powershell-bot May 27, 2025
501d7eb
Update live test script for background jobs. (#27786)
vidai-msft May 27, 2025
4b1126c
[Eng] Fixed placeholder in new module psd1 (#27862)
VeryEarly May 28, 2025
b64e1fa
Added a new Test case instead of old one
v-sapanchal May 28, 2025
6eb150e
revert back the old test record
v-sapanchal May 28, 2025
d433608
Merge branch 'Azure:main' into spanchal/pcap_ring_buffer
v-sapanchal May 28, 2025
e5103ce
Merge branch 'Azure:main' into spanchal/pcap_ring_buffer
v-sapanchal May 29, 2025
b7a8a52
Resolve PR comments
v-sapanchal May 29, 2025
7270718
Merge branch 'spanchal/pcap_ring_buffer' of https://github.com/v-sapa…
v-sapanchal May 29, 2025
85295cb
Revert all changes related to old command, to avoid breaking change a…
v-sapanchal May 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Accounts/Accounts/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

## Upcoming Release
* Upgrade Azure.Core to 1.45.0
* Added definition of Bleu cloud so it can be used with commands like `Enter-AzVM`

## Version 5.0.1
* Force `Get-AzAccessToken` to always return SecureString as long as `AsSecureString` is set
Expand Down
1 change: 1 addition & 0 deletions src/Accounts/Accounts/Utilities/CommandMappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5142,6 +5142,7 @@
"New-AzP2sVpnGateway": {},
"New-AzPacketCaptureFilterConfig": {},
"New-AzPacketCaptureScopeConfig": {},
"New-AzPacketCaptureSettingsConfig": {},
"New-AzPrivateDnsZoneConfig": {},
"New-AzPrivateDnsZoneGroup": {},
"New-AzPrivateEndpoint": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class SshCredentialFactory : ISshCredentialFactory
{ "azurecloud", "https://pas.windows.net/CheckMyAccess/Linux/.default" },
{ "azurechinacloud", "https://pas.chinacloudapi.cn/CheckMyAccess/Linux/.default" },
{ "azureusgovernment", "https://pasff.usgovcloudapi.net/CheckMyAccess/Linux/.default" },
{ "bleu", "https://pas.identity.sovcloud-api.fr/CheckMyAccess/Linux/.default" },
};

private string CreateJwk(RSAParameters rsaKeyInfo, out string keyId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public void TestPacketCaptureVMSS()
TestRunner.RunTestScript("Test-PacketCaptureV2");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.netanalyticsdev)]
public void TestPacketCaptureVMSSWithRingBuffer()
{
TestRunner.RunTestScript("Test-PacketCaptureV2WithRingBuffer");
}

[Fact]
[Trait(Category.AcceptanceType, Category.LiveOnly)]
[Trait(Category.Owner, NrpTeamAlias.netanalyticsdev)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,100 @@ function Test-PacketCaptureV2 {
finally {
# Cleanup
Clean-ResourceGroup $resourceGroupName
Clean-ResourceGroup $nwRgName
#Clean-ResourceGroup $nwRgName
}
}

<#
.SYNOPSIS
Test PacketCapture API with ring buffer.
#>
function Test-PacketCaptureV2WithRingBuffer {
# Setup
$resourceGroupName = Get-NrpResourceGroupName
$virtualMachineScaleSetName = Get-NrpResourceName
$nwName = Get-NrpResourceName
$location = Get-PilotLocation
$resourceTypeParent = "Microsoft.Network/networkWatchers"
$nwLocation = Get-ProviderLocation $resourceTypeParent
$nwRgName = Get-NrpResourceGroupName
$templateFileVMSS = (Resolve-Path ".\TestData\DeploymentVMSS.json").Path
$pcName = Get-NrpResourceName
$pcName3 = $pcName + "2"

try {
. ".\AzureRM.Resources.ps1"

# Create Resource group
New-AzResourceGroup -Name $resourceGroupName -Location "$location"

# Deploy resources
Get-TestResourcesDeploymentVMSS -rgn "$resourceGroupName"

#Get public IP address
$address = Get-AzPublicIpAddress -ResourceGroupName $resourceGroupName

# Create Resource group for Network Watcher
New-AzResourceGroup -Name $nwRgName -Location "$location"

# Get Network Watcher
$nw = Get-CreateTestNetworkWatcher -location $location -nwName $nwName -nwRgName $nwRgName

Wait-Seconds 600

#Get Vmss and Instances
$vmss = Get-AzVmss -ResourceGroupName $resourceGroupName -VMScaleSetName $virtualMachineScaleSetName

#Install networkWatcherAgent on Vmss and Vmss Instances
Add-AzVmssExtension -VirtualMachineScaleSet $vmss -Name "AzureNetworkWatcherExtension" -Publisher "Microsoft.Azure.NetworkWatcher" -Type "NetworkWatcherAgentWindows" -TypeHandlerVersion "1.4" -AutoUpgradeMinorVersion $True
Update-AzVmss -ResourceGroupName "$resourceGroupName" -Name $virtualMachineScaleSetName -VirtualMachineScaleSet $vmss

# Updating all VMSS instances with NW agent
$instances = Get-AzVMSSVM -ResourceGroupName "$resourceGroupName" -VMScaleSetName $vmss.Name
foreach ($item in $instances) {
Update-AzVmssInstance -ResourceGroupName "$resourceGroupName" -VMScaleSetName $vmss.Name -InstanceId $item.InstanceID
}

# Create Capture settiings for packet capture, its only applicable if we are pass continuousCapture as true/false
$c1 = New-AzPacketCaptureSettingsConfig -FileCount 2 -FileSizeInBytes 102400 -SessionTimeLimitInSeconds 60

#$vmssid = $vmss.Id
#Write-Output ("VmssId: '$vmssid'")
#Write-Output ("pcname: '$pcName3' ")
#Write-Output ("C1: '$c1' ")

#Create packet capture
# with Continuous Capture, if you are using continuousCapture, change it to local Path instead FilePath
$job3 = New-AzNetworkWatcherPacketCaptureV2 -NetworkWatcher $nw -Name $pcName3 -TargetId $vmss.Id -TargetType "azurevmss" -ContinuousCapture $false -CaptureSettings $c1 -LocalPath C:\captures\Capture.cap -AsJob
$job3 | Wait-Job

Start-TestSleep -Seconds 2

#Get packet capture
$job3 = Get-AzNetworkWatcherPacketCapture -NetworkWatcher $nw -PacketCaptureName $pcName3 -AsJob
$job3 | Wait-Job
$pc3 = $job3 | Receive-Job

#Write-Output ("PC3: '$pc3'")

#Verification
Assert-AreEqual $pc3.Name $pcName3
Assert-AreEqual $pc3.StorageLocation.LocalPath C:\captures\Capture.cap
Assert-AreEqual "Succeeded" $pc3.ProvisioningState
Assert-AreEqual $pc3.TargetType AzureVMSS

#Stop packet capture
$job3 = Stop-AzNetworkWatcherPacketCapture -NetworkWatcher $nw -PacketCaptureName $pcName3 -AsJob
$job3 | Wait-Job

#Remove packet capture
$job3 = Remove-AzNetworkWatcherPacketCapture -NetworkWatcher $nw -PacketCaptureName $pcName3 -AsJob
$job3 | Wait-Job
}
finally {
# Cleanup
Clean-ResourceGroup $resourceGroupName
#Clean-ResourceGroup $nwRgName
}
}

Expand Down

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Network/Network/Az.Network.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate',
'New-AzNetworkWatcherProtocolConfiguration',
'New-AzO365PolicyProperty', 'New-AzOffice365PolicyProperty',
'New-AzP2sVpnGateway', 'New-AzPacketCaptureFilterConfig',
'New-AzPacketCaptureSettingsConfig',
'New-AzPacketCaptureScopeConfig', 'New-AzPrivateDnsZoneConfig',
'New-AzPrivateDnsZoneGroup', 'New-AzPrivateEndpoint',
'New-AzPrivateEndpointIpConfiguration', 'New-AzPrivateLinkService',
Expand Down
4 changes: 4 additions & 0 deletions src/Network/Network/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

## Upcoming Release

* Added properties 'ContinuousCapture', 'LocalPath', and 'CaptureSettings' to Packet capture V2 command along with update the old parameter as 'FilePath' as well as support for it for the following cmdlets:
- `New-AzPacketCaptureSettingsConfig`
- `New-AzNetworkWatcherPacketCaptureV2`

## Version 7.17.0
* Added properties 'PublicIpAddressesV6', 'PublicIpPrefixesV6', and 'SourceVirtualNetwork' to NatGateway, as well as support for it for the following cmdlets:
- `New-AzNatGateway`
Expand Down
46 changes: 46 additions & 0 deletions src/Network/Network/Models/PSPacketCaptureSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.Network.Models
{
using Microsoft.WindowsAzure.Commands.Common.Attributes;
using Newtonsoft.Json;

public class PSPacketCaptureSettings
{
/// <summary>
/// Gets or sets number of file count. Default value of count is 10 and maximum
/// number is 10000.
/// </summary>
[JsonProperty(Order = 1)]
[Ps1Xml(Target = ViewControl.Table)]
public int? FileCount { get; set; }

/// <summary>
/// Gets or sets number of bytes captured per packet. Default value in bytes
/// 104857600 (100MB) and maximum in bytes 4294967295 (4GB).
/// </summary>
[JsonProperty(Order = 2)]
[Ps1Xml(Target = ViewControl.Table)]
public long? FileSizeInBytes { get; set; }

/// <summary>
/// Gets or sets maximum duration of the capture session in seconds is 604800s
/// (7 days) for a file. Default value in second 86400s (1 day).
/// </summary>
[JsonProperty(Order = 3)]
[Ps1Xml(Target = ViewControl.Table)]
public int? SessionTimeLimitInSeconds { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,17 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using AutoMapper;
using Microsoft.Azure.Commands.Network.Models;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
using Microsoft.Azure.Management.Network;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Management.Automation;
using MNM = Microsoft.Azure.Management.Network.Models;

namespace Microsoft.Azure.Commands.Network
{
[Cmdlet("New", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "NetworkWatcherPacketCaptureV2", SupportsShouldProcess = true, DefaultParameterSetName = "SetByResource"),OutputType(typeof(PSPacketCaptureResult))]
[Cmdlet("New", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "NetworkWatcherPacketCaptureV2", SupportsShouldProcess = true, DefaultParameterSetName = "SetByResource"), OutputType(typeof(PSPacketCaptureResult))]
public class NewAzureNetworkWatcherPacketCaptureCommandV2 : PacketCaptureBaseCmdlet
{
[Parameter(
Expand Down Expand Up @@ -94,7 +91,7 @@ public class NewAzureNetworkWatcherPacketCaptureCommandV2 : PacketCaptureBaseCmd
[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Local file path.")]
HelpMessage = "Local File path.")]
[ValidateNotNullOrEmpty]
public string LocalFilePath { get; set; }

Expand Down Expand Up @@ -140,6 +137,25 @@ public class NewAzureNetworkWatcherPacketCaptureCommandV2 : PacketCaptureBaseCmd
[ValidateNotNull]
public PSPacketCaptureFilter[] Filter { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "This continuous capture is a nullable boolean, which can hold 'null', 'true' or 'false' value. If we do not pass this parameter, it would be consider as 'null', default value is 'null'.")]
public bool? ContinuousCapture { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "This path is valid if 'ContinuousCapture' is provided and required if no storage ID is provided, otherwise optional. Must include the name of the capture file (*.cap).")]
[ValidateNotNullOrEmpty]
public string LocalPath { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "Filters for packet capture session.")]
[ValidateNotNull]
public PSPacketCaptureSettings CaptureSettings { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
public SwitchParameter AsJob { get; set; }

Expand Down Expand Up @@ -172,6 +188,68 @@ public override void Execute()
name = this.NetworkWatcherName;
}

#region Capture Settings Validations
if (this.ContinuousCapture == null)
{
if (string.IsNullOrEmpty(this.LocalFilePath) && string.IsNullOrEmpty(this.StorageAccountId))
{
throw new ArgumentException("PacketCaptureIsMissingStorageIdAndLocalFilePath: StorageLocation must have either storage id or local file path specified.");
}
}
else
{
if (this.TotalBytesPerSession != null)
{
throw new ArgumentException("InvalidRequestPropertiesInPacketCaptureRequest: TotalBytesPerSession is not supported in packet capture request.");
}

if (this.TimeLimitInSecond != null)
{
throw new ArgumentException("InvalidRequestPropertiesInPacketCaptureRequest: TimeLimitInSecond is not supported in packet capture request.");
}

if (this.LocalFilePath != null)
{
throw new ArgumentException("PacketCaptureIsMissingStorageIdAndLocalPath: StorageLocation must have either storage id or local path specified.");
}

if (string.IsNullOrEmpty(this.LocalPath) && string.IsNullOrEmpty(this.StorageAccountId))
{
throw new ArgumentException("PacketCaptureIsMissingStorageIdAndLocalFilePath: StorageLocation must have either storage id or local file path specified.");
}

if (this.CaptureSettings == null)
{
this.CaptureSettings = new PSPacketCaptureSettings
{
FileCount = 10,
FileSizeInBytes = 104857600,
SessionTimeLimitInSeconds = 86400
};
}
else
{
this.CaptureSettings.FileCount = this.CaptureSettings.FileCount ?? 10;
this.CaptureSettings.FileSizeInBytes = this.CaptureSettings.FileSizeInBytes ?? 104857600;
this.CaptureSettings.SessionTimeLimitInSeconds = this.CaptureSettings.SessionTimeLimitInSeconds ?? 86400;

if (this.CaptureSettings.FileCount < 1 || this.CaptureSettings.FileCount > 10000)
{
throw new ArgumentException("FileCount must be between 1 and 10,000. Default is 10.");
}
if (this.CaptureSettings.FileSizeInBytes < 102400 || this.CaptureSettings.FileSizeInBytes > 4294967295)
{
throw new ArgumentException("FileSizeInBytes must be between 102400 byte and 4,294,967,295 bytes (4 GB). Default is 104,857,600 bytes (100 MB).");
}
if (this.CaptureSettings.SessionTimeLimitInSeconds < 1 || this.CaptureSettings.SessionTimeLimitInSeconds > 604800)
{
throw new ArgumentException("SessionTimeLimitInSeconds must be between 1 second and 604,800 seconds (7 days). Default is 86,400 seconds.");
}
}
}

#endregion

var present = this.IsPacketCapturePresent(resourceGroupName, name, this.Name);

if (!present)
Expand All @@ -185,13 +263,17 @@ public override void Execute()
WriteObject(packetCapture);
});
}
else
{
throw new ArgumentException($"PacketCaptureExistingAlready: Existing Packet capture can not be updated.");
}
}

private PSPacketCaptureResult CreatePacketCapture(string resourceGroupName, string networkWatcherName)
{
MNM.PacketCapture packetCaptureProperties = new MNM.PacketCapture();

if(this.BytesToCapturePerPacket != null)
if (this.BytesToCapturePerPacket != null)
{
packetCaptureProperties.BytesToCapturePerPacket = this.BytesToCapturePerPacket;
}
Expand All @@ -209,10 +291,25 @@ private PSPacketCaptureResult CreatePacketCapture(string resourceGroupName, stri
packetCaptureProperties.Target = this.TargetId;

packetCaptureProperties.StorageLocation = new MNM.PacketCaptureStorageLocation();
packetCaptureProperties.StorageLocation.FilePath = this.LocalFilePath;
packetCaptureProperties.ContinuousCapture = this.ContinuousCapture;

if (this.ContinuousCapture != null)
{
packetCaptureProperties.StorageLocation.LocalPath = this.LocalPath;
packetCaptureProperties.CaptureSettings = new MNM.PacketCaptureSettings()
{
FileCount = this.CaptureSettings.FileCount,
FileSizeInBytes = this.CaptureSettings.FileSizeInBytes,
SessionTimeLimitInSeconds = this.CaptureSettings.SessionTimeLimitInSeconds
};
}
else
{
packetCaptureProperties.StorageLocation.FilePath = this.LocalFilePath;
}

packetCaptureProperties.StorageLocation.StorageId = this.StorageAccountId;
packetCaptureProperties.StorageLocation.StoragePath = this.StoragePath;

packetCaptureProperties.TargetType = MNM.PacketCaptureTargetType.AzureVM;

if (!string.IsNullOrEmpty(this.TargetType))
Expand Down
Loading
Loading