Skip to content

Commit 9dd15f5

Browse files
Merge pull request #293915 from halkazwini/nw-vnetflow-cli
Add commands for SA or workspace that are in different RGs from the VNet
2 parents b023369 + e237b83 commit 9dd15f5

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

articles/network-watcher/vnet-flow-logs-cli.md

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ author: halkazwini
66
ms.author: halkazwini
77
ms.service: azure-network-watcher
88
ms.topic: how-to
9-
ms.date: 04/24/2024
9+
ms.date: 01/31/2025
1010
ms.custom: devx-track-azurecli
1111

1212
#CustomerIntent: As an Azure administrator, I want to log my virtual network IP traffic using Network Watcher virtual network flow logs so that I can analyze it later.
@@ -28,9 +28,11 @@ In this article, you learn how to create, change, enable, disable, or delete a v
2828

2929
- An Azure storage account. If you need to create a storage account, see [Create a storage account using the Azure CLI](../storage/common/storage-account-create.md?tabs=azure-cli).
3030

31-
- Bash environment in [Azure Cloud Shell](https://shell.azure.com) or the Azure CLI installed locally. To learn more about using Bash in Azure Cloud Shell, see [Azure Cloud Shell Quickstart - Bash](../cloud-shell/quickstart.md).
31+
- Azure Cloud Shell or Azure CLI.
3232

33-
- If you choose to install and use Azure CLI locally, this article requires the Azure CLI version 2.39.0 or later. Run `az --version` to find the installed version. If you need to install or upgrade, see [Install Azure CLI](/cli/azure/install-azure-cli). Run `az login` to sign in to Azure.
33+
The steps in this article run the Azure CLI commands interactively in [Azure Cloud Shell](/azure/cloud-shell/overview). To run the commands in the Cloud Shell, select **Open Cloud Shell** at the upper-right corner of a code block. Select **Copy** to copy the code, and paste it into Cloud Shell to run it. You can also run the Cloud Shell from within the Azure portal.
34+
35+
You can also [install Azure CLI locally](/cli/azure/install-azure-cli) to run the commands. This article requires the Azure CLI version 2.39.0 or later. Run [az --version](/cli/azure/reference-index#az-version) command to find the installed version. If you run Azure CLI locally, sign in to Azure using the [az login](/cli/azure/reference-index#az-login) command.
3436

3537
## Register insights provider
3638

@@ -47,7 +49,12 @@ Use [az network watcher flow-log create](/cli/azure/network/watcher/flow-log#az-
4749

4850
```azurecli-interactive
4951
# Create a VNet flow log.
50-
az network watcher flow-log create --location eastus --resource-group myResourceGroup --name myVNetFlowLog --vnet myVNet --storage-account myStorageAccount
52+
az network watcher flow-log create --location 'eastus' --resource-group 'myResourceGroup' --name 'myVNetFlowLog' --vnet myVNet --storage-account 'myStorageAccount'
53+
```
54+
55+
```azurecli-interactive
56+
# Create a VNet flow log (storage account is in a different resource group from the virtual network).
57+
az network watcher flow-log create --location 'eastus' --resource-group 'myResourceGroup' --name 'myVNetFlowLog' --vnet myVNet --storage-account '/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/myResourceGroup2/providers/Microsoft.Storage/storageAccounts/myStorageAccount'
5158
```
5259

5360
## Enable virtual network flow logs and traffic analytics
@@ -56,10 +63,18 @@ Use [az monitor log-analytics workspace create](/cli/azure/monitor/log-analytics
5663

5764
```azurecli-interactive
5865
# Create a traffic analytics workspace.
59-
az monitor log-analytics workspace create --name myWorkspace --resource-group myResourceGroup --location eastus
66+
az monitor log-analytics workspace create --name 'myWorkspace' --resource-group 'myResourceGroup' --location 'eastus'
6067
6168
# Create a VNet flow log.
62-
az network watcher flow-log create --location eastus --name myVNetFlowLog --resource-group myResourceGroup --vnet myVNet --storage-account myStorageAccount --workspace myWorkspace --interval 10 --traffic-analytics true
69+
az network watcher flow-log create --location 'eastus' --name 'myVNetFlowLog' --resource-group 'myResourceGroup' --vnet 'myVNet' --storage-account 'myStorageAccount' --workspace 'myWorkspace' --interval 10 --traffic-analytics true
70+
```
71+
72+
```azurecli-interactive
73+
# Create a traffic analytics workspace.
74+
az monitor log-analytics workspace create --name 'myWorkspace' --resource-group 'myResourceGroup' --location 'eastus'
75+
76+
# Create a VNet flow log (storage account and traffic analytics workspace are in different resource groups from the virtual network).
77+
az network watcher flow-log create --location 'eastus' --name 'myVNetFlowLog' --resource-group 'myResourceGroup' --vnet 'myVNet' --storage-account '/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/Storage/providers/Microsoft.Storage/storageAccounts/myStorageAccount' --workspace '/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/WorkspaceRG/providers/Microsoft.OperationalInsights/workspaces/myWorkspace' --interval 10 --traffic-analytics true
6378
```
6479

6580
## List all flow logs in a region
@@ -68,7 +83,7 @@ Use [az network watcher flow-log list](/cli/azure/network/watcher/flow-log#az-ne
6883

6984
```azurecli-interactive
7085
# Get all flow logs in East US region.
71-
az network watcher flow-log list --location eastus --out table
86+
az network watcher flow-log list --location 'eastus' --out table
7287
```
7388

7489
## View virtual network flow log resource
@@ -77,7 +92,7 @@ Use [az network watcher flow-log show](/cli/azure/network/watcher/flow-log#az-ne
7792

7893
```azurecli-interactive
7994
# Get the flow log details.
80-
az network watcher flow-log show --name myVNetFlowLog --resource-group NetworkWatcherRG --location eastus
95+
az network watcher flow-log show --name 'myVNetFlowLog' --resource-group 'NetworkWatcherRG' --location 'eastus'
8196
```
8297

8398
## Download a flow log
@@ -99,7 +114,7 @@ To disable traffic analytics on the flow log resource and continue to generate a
99114

100115
```azurecli-interactive
101116
# Update the VNet flow log.
102-
az network watcher flow-log update --location eastus --name myVNetFlowLog --resource-group myResourceGroup --vnet myVNet --storage-account myStorageAccount --traffic-analytics false
117+
az network watcher flow-log update --location 'eastus' --name 'myVNetFlowLog' --resource-group 'myResourceGroup' --vnet 'myVNet' --storage-account 'myStorageAccount' --traffic-analytics false
103118
```
104119

105120
## Delete a virtual network flow log resource
@@ -108,7 +123,7 @@ To delete a virtual network flow log resource, use [az network watcher flow-log
108123

109124
```azurecli-interactive
110125
# Delete the VNet flow log.
111-
az network watcher flow-log delete --name myVNetFlowLog --location eastus
126+
az network watcher flow-log delete --name 'myVNetFlowLog' --location 'eastus'
112127
```
113128

114129
## Next steps

0 commit comments

Comments
 (0)