Skip to content

Commit fd2d030

Browse files
Merge pull request #302602 from andreamichaelmsft/andrea-branch-2
[Azure Doc-a-thon] Update NSG manage logs page
2 parents aeee4b5 + 486b832 commit fd2d030

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

articles/virtual-network/virtual-network-nsg-manage-log.md

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ author: asudbring
77
manager: mtillman
88
ms.service: azure-virtual-network
99
ms.topic: how-to
10-
ms.date: 03/22/2023
10+
ms.date: 07/11/2025
1111
ms.author: allensu
1212
ms.custom: devx-track-azurecli
1313
ms.devlang: azurecli
@@ -20,12 +20,12 @@ A network security group (NSG) includes rules that allow or deny traffic to a vi
2020

2121
When you enable logging for an NSG, you can gather the following types of resource log information:
2222

23-
- **Event**: Entries are logged for which NSG rules are applied to virtual machines, based on a MAC address.
24-
- **Rule counter**: Contains entries for how many times each NSG rule is applied to allow or deny traffic. The status for these rules is collected every 300 seconds.
23+
- **Event**: Entries are logged for the NSG rules applied to virtual machines, based on a MAC address.
24+
- **Rule counter**: Tracks how many times each NSG rule is applied to allow or deny traffic. The status for these rules is collected every 300 seconds.
2525

26-
Resource logs are available only for NSGs deployed through the Azure Resource Manager deployment model. You can't enable resource logging for NSGs deployed through the classic deployment model. For more information, see [Understand deployment models](../azure-resource-manager/management/deployment-models.md).
26+
Resource logs are available only for NSGs deployed through the Azure Resource Manager (ARM) deployment model. You can't enable resource logging for NSGs deployed through the classic deployment model. For more information, see [Understand deployment models](../azure-resource-manager/management/deployment-models.md).
2727

28-
Resource logging is enabled separately for *each* NSG for which to collect diagnostic data. If you're interested in *activity*, or *operational*, logs instead, see [Overview of Azure platform logs](/azure/azure-monitor/essentials/platform-logs-overview). If you're interested in IP traffic flowing through NSGs, see [Flow logs for network security groups](../network-watcher/network-watcher-nsg-flow-logging-overview.md).
28+
Resource logging is enabled separately for *each* NSG from which you want to collect diagnostic data. If you're interested in *activity* or *operational* logs instead, see [Overview of Azure platform logs](/azure/azure-monitor/essentials/platform-logs-overview). If you're interested in IP traffic flowing through the virtual network, see [Virtual network flow logs](../network-watcher/vnet-flow-logs-overview.md).
2929

3030
## Enable logging
3131

@@ -36,7 +36,7 @@ You can use the [Azure portal](#azure-portal), [Azure PowerShell](#azure-powersh
3636
1. Sign in to the [Azure portal](https://portal.azure.com).
3737
1. In the search box at the top of the Azure portal, enter **network security groups**. Select **Network security groups** in the search results.
3838
1. Select the NSG for which you want to enable logging.
39-
1. Under **Monitoring**, select **Diagnostic settings**, and then select **Add diagnostic setting**.
39+
1. Under **Monitoring**, select **Diagnostic settings**, then select **Add diagnostic setting**.
4040

4141
:::image type="content" source="./media/virtual-network-nsg-manage-log/turn-on-diagnostics.png" alt-text="Screenshot that shows the diagnostic settings for an NSG with Add diagnostic setting highlighted." lightbox="./media/virtual-network-nsg-manage-log/turn-on-diagnostics.png":::
4242

@@ -83,7 +83,7 @@ $Oms=Get-AzOperationalInsightsWorkspace `
8383
-Name myWorkspace
8484
```
8585

86-
There are two categories of logging that you can enable. For more information, see [Log categories](#log-categories). Enable resource logging for the NSG with the [New-AzDiagnosticSetting](/powershell/module/az.monitor/new-azdiagnosticsetting) cmdlet. The following example logs both event and counter category data to the workspace for an NSG. It uses the IDs for the NSG and workspace that you got with the previous commands:
86+
There are two categories of logging that you can enable. For more information, see [Log categories](#log-categories). Enable resource logging for the NSG with the [New-AzDiagnosticSetting](/powershell/module/az.monitor/new-azdiagnosticsetting) cmdlet. The following example logs both event and rule counter category data to the workspace for an NSG. It uses the IDs for the NSG and workspace that you obtained with the previous command:
8787

8888
```azurepowershell-interactive
8989
New-AzDiagnosticSetting `
@@ -102,7 +102,7 @@ View and analyze logs. For more information, see [View and analyze logs](#view-a
102102

103103
You can run the commands in this section in [Cloud Shell](https://shell.azure.com/bash) or by running the Azure CLI from your computer. Cloud Shell is a free interactive shell. It has common Azure tools preinstalled and configured to use with your account.
104104

105-
If you run the CLI from your computer, you need version 2.0.38 or later. Run `az --version` on your computer to find the installed version. If you need to upgrade, see [Install the Azure CLI](/cli/azure/install-azure-cli). If you run the CLI locally, you also need to run `az login` to sign in to Azure with an account that has the [necessary permissions](virtual-network-network-interface.md#permissions).
105+
If you run the CLI from your computer, you need version 2.0.28 or later. Run `az --version` on your computer to find the installed version. If you need to upgrade, see [Install the Azure CLI](/cli/azure/install-azure-cli). If you run the CLI locally, you also need to run `az login` to sign in to Azure with an account that has the [necessary permissions](virtual-network-network-interface.md#permissions).
106106

107107
To enable resource logging, you need the ID of an existing NSG. If you don't have an existing NSG, create one by using [az network nsg create](/cli/azure/network/nsg#az-network-nsg-create).
108108

@@ -116,9 +116,9 @@ nsgId=$(az network nsg show \
116116
--output tsv)
117117
```
118118

119-
You can write resource logs to different destination types. For more information, see [Log destinations](#log-destinations). In this article, logs are sent to a Log Analytics workspace destination, as an example. For more information, see [Log categories](#log-categories).
119+
You can write resource logs to different destination types. For more information, see [Log destinations](#log-destinations). In this article, logs are sent to a Log Analytics workspace destination as an example. For more information, see [Log categories](#log-categories).
120120

121-
Enable resource logging for the NSG with [az monitor diagnostic-settings create](/cli/azure/monitor/diagnostic-settings#az-monitor-diagnostic-settings-create). The following example logs both event and counter category data to an existing workspace named `myWorkspace`, which exists in a resource group named `myWorkspaces`. It uses the ID of the NSG that you saved by using the previous command.
121+
Enable resource logging for the NSG with [az monitor diagnostic-settings create](/cli/azure/monitor/diagnostic-settings#az-monitor-diagnostic-settings-create). The following example logs both event and rule counter category data to an existing workspace named `myWorkspace`, which exists in a resource group named `myWorkspaces`. It uses the ID of the NSG you obtained with the previous command:
122122

123123
```azurecli-interactive
124124
az monitor diagnostic-settings create \
@@ -146,11 +146,14 @@ You can send diagnostics data to the following options:
146146

147147
## Log categories
148148

149-
JSON-formatted data is written for the following log categories: event and rule counter.
149+
JSON-formatted data is written for the following log categories:
150+
151+
- [Event](#event)
152+
- [Rule counter](#rule-counter)
150153

151154
### Event
152155

153-
The event log contains information about which NSG rules are applied to virtual machines, based on a MAC address. The following data is logged for each event. In the following example, the data is logged for a virtual machine with the IP address 192.168.1.4 and a MAC address of 00-0D-3A-92-6A-7C.
156+
The event log contains information of NSG rules applied to virtual machines, based on a MAC address. The following data is logged for each event. In the following example, the data is logged for a virtual machine with the IP address 192.168.1.4 and a MAC address of 00-0D-3A-92-6A-7C.
154157

155158
```json
156159
{
@@ -181,7 +184,7 @@ The event log contains information about which NSG rules are applied to virtual
181184

182185
### Rule counter
183186

184-
The rule counter log contains information about each rule applied to resources. The following example data is logged each time a rule is applied. In the following example, the data is logged for a virtual machine with the IP address 192.168.1.4 and a MAC address of 00-0D-3A-92-6A-7C.
187+
The rule counter log contains information of each NSG rule applied to resources. The following example data is logged each time a rule is applied. In the following example, the data is logged for a virtual machine with the IP address 192.168.1.4 and a MAC address of 00-0D-3A-92-6A-7C.
185188

186189
```json
187190
{
@@ -204,29 +207,30 @@ The rule counter log contains information about each rule applied to resources.
204207
```
205208

206209
> [!NOTE]
207-
> The source IP address for the communication isn't logged. You can enable [NSG flow logging](../network-watcher/network-watcher-nsg-flow-logging-portal.md) for an NSG, which logs all of the rule counter information and the source IP address that initiated the communication. NSG flow log data is written to an Azure Storage account. You can analyze the data with the [traffic analytics](../network-watcher/traffic-analytics.md) capability of Azure Network Watcher.
210+
> The source IP address for the communication isn't logged. You can enable [Virtual network flow logs](../network-watcher/vnet-flow-logs-overview.md) for the NSG's virtual network, which logs all of the IP traffic flowing through a virtual network. Virtual network flow log data is written to an Azure Storage account in the same subscription and region of the virtual network. You can analyze the data with the [traffic analytics](../network-watcher/traffic-analytics.md) capability of Azure Network Watcher.
208211
209212
## View and analyze logs
210213

211214
If you send diagnostics data to:
212215

213216
- **Azure Monitor logs**: You can use the [NSG analytics](/azure/azure-monitor/insights/azure-networking-analytics?toc=%2fazure%2fvirtual-network%2ftoc.json) solution for enhanced insights. The solution provides visualizations for NSG rules that allow or deny traffic, per MAC address, of the network interface in a virtual machine.
214-
- **Azure Storage account**: Data is written to a *PT1H.json* file. You can find the:
217+
- **Azure Storage account**: Data is written to a *PT1H.json* file. You can find the following logs:
218+
219+
- Event log found in the path: *insights-logs-networksecuritygroupevent/resourceId=/SUBSCRIPTIONS/[ID]/RESOURCEGROUPS/[RESOURCE-GROUP-NAME-FOR-NSG]/PROVIDERS/MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/[NSG NAME]/y=[YEAR]/m=[MONTH/d=[DAY]/h=[HOUR]/m=[MINUTE]*
215220

216-
- Event log that's in the following path: *insights-logs-networksecuritygroupevent/resourceId=/SUBSCRIPTIONS/[ID]/RESOURCEGROUPS/[RESOURCE-GROUP-NAME-FOR-NSG]/PROVIDERS/MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/[NSG NAME]/y=[YEAR]/m=[MONTH/d=[DAY]/h=[HOUR]/m=[MINUTE]*
217-
- Rule counter log that's in the following path: *insights-logs-networksecuritygrouprulecounter/resourceId=/SUBSCRIPTIONS/[ID]/RESOURCEGROUPS/[RESOURCE-GROUP-NAME-FOR-NSG]/PROVIDERS/MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/[NSG NAME]/y=[YEAR]/m=[MONTH/d=[DAY]/h=[HOUR]/m=[MINUTE]*
221+
- Rule counter log found in the path: *insights-logs-networksecuritygrouprulecounter/resourceId=/SUBSCRIPTIONS/[ID]/RESOURCEGROUPS/[RESOURCE-GROUP-NAME-FOR-NSG]/PROVIDERS/MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/[NSG NAME]/y=[YEAR]/m=[MONTH/d=[DAY]/h=[HOUR]/m=[MINUTE]*
218222

219223
To learn how to view resource log data, see [Azure platform logs overview](/azure/azure-monitor/essentials/platform-logs-overview).
220224

221225
## Related content
222226

223227
- For more information about activity logging, see [Overview of Azure platform logs](/azure/azure-monitor/essentials/platform-logs-overview).
224228

225-
Activity logging is enabled by default for NSGs created through either Azure deployment model. To determine which operations were completed on NSGs in the activity log, look for entries that contain the following resource types:
229+
Activity logging is enabled by default for NSGs created through either the ARM or classic deployment model. To determine which operations were completed on NSGs in the activity log, look for entries that contain the following resource types:
226230

227231
- `Microsoft.ClassicNetwork/networkSecurityGroups`
228232
- `Microsoft.ClassicNetwork/networkSecurityGroups/securityRules`
229233
- `Microsoft.Network/networkSecurityGroups`
230234
- `Microsoft.Network/networkSecurityGroups/securityRules`
231235

232-
- To learn how to log diagnostic information, see [Log network traffic to and from a virtual machine by using the Azure portal](../network-watcher/network-watcher-nsg-flow-logging-portal.md).
236+
- To learn how to log diagnostic information for traffic flowing through the virtual network that match NSG rules, see [how to manage virtual network flow logs](../network-watcher/vnet-flow-logs-manage.md).

0 commit comments

Comments
 (0)