You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Use packet capture for proactive network monitoring with alerts and Azure Functions
16
+
# Monitor networks proactively with alerts and Azure Functions using Packet Capture
17
17
18
18
Network Watcher packet capture creates capture sessions to track traffic in and out of virtual machines. The capture file can have a filter that is defined to track only the traffic that you want to monitor. This data is stored in a storage blob or locally on the guest machine.
19
19
20
20
This capability can be started remotely from other automation scenarios such as Azure Functions. Packet capture gives you the capability to run proactive captures based on defined network anomalies. Other uses include gathering network statistics, getting information about network intrusions, debugging client-server communications, and more.
21
21
22
-
Resources that are deployed in Azure run 24 * 7. You and your staff can't actively monitor the status of all resources 24 * 7. For example, what happens if an issue occurs at 2 AM?
22
+
Resources that are deployed in Azure run 24 * 7. It is difficult to actively monitor the status of all resources 24 * 7. For example, what happens if an issue occurs at 2 AM?
23
23
24
-
By using Network Watcher, alerting and functions from within the Azure ecosystem, you can proactively respond with the data and tools to solve problems in your network.
24
+
By using Network Watcher alerting and functions from within the Azure ecosystem, you can proactively respond with the data and tools to solve problems in your network.
@@ -33,18 +33,18 @@ By using Network Watcher, alerting and functions from within the Azure ecosystem
33
33
34
34
## Scenario
35
35
36
-
In this example, your VM is utilizing more CPU percentage than usual and you want to be alerted. CPU percentage is used as an example here, but you can use any alert condition.
36
+
In this example, your VM has more outgoing traffic than usual and you want to be alerted. Similarly, you can create alerts for any condition.
37
37
38
-
When you're alerted, the packet-level data helps to understand why utilization has increased. You can take steps to return the virtual machine to regular utilization.
38
+
When an alert is triggered, the packet-level data helps to analyze why the outgoing traffic has increased. You can take steps to return the virtual machine to its original state.
39
39
40
40
This scenario assumes that you have an existing instance of Network Watcher and a resource group with a valid Virtual machine.
41
41
42
-
The following list is an overview of the workflow that takes place:
42
+
The following workflow that takes place when an alert is triggered:
43
43
44
44
1. An alert is triggered on your VM.
45
45
1. The alert calls your Azure function.
46
46
1. Your Azure function processes the alert and starts a Network Watcher packet capture session.
47
-
1. The packet capture runs on the VM and collects traffic.
47
+
1. The packet capture runs on the VM and collects data.
48
48
1. The packet capture file is uploaded to a storage account for review and diagnosis.
49
49
50
50
To automate this process, we create and connect an alert on our VM to trigger when the incident occurs. We also create a function to call Network Watcher.
@@ -56,7 +56,7 @@ This scenario does the following:
56
56
57
57
## Create an Azure function app
58
58
59
-
The first step is to create an Azure function to process the alert and create a packet capture.
59
+
To create an Azure function to process the alert and create a packet capture, follow these steps:
60
60
61
61
1. In the [Azure portal](https://portal.azure.com), search for *function app* in **All services** and select it.
62
62
@@ -66,18 +66,19 @@ The first step is to create an Azure function to process the alert and create a
66
66
67
67
:::image type="content" source="./media/network-watcher-alert-triggered-packet-capture/create-function-app.png" alt-text="Screenshot of the Create function app screen.":::
68
68
69
-
2. In the **Basics** tab, enter the following values and select **OK** to create the app:
69
+
2. In the **Basics** tab, enter the following values:
70
70
1. Under **Project Details**, select the **Subscription** for which you want to create the Function app and the **Resource Group** to contain the app.
71
71
2. Under **Instance details**, do the following:
72
72
1. Enter the name of the Function app. This name will be appended by *.azurewebsites.net*.
73
73
2. In **Publish**, select the mode of publishing, either *Code* or *Docker Container*.
74
74
3. Select a **Runtime stack**.
75
75
4. Select the version of the Runtime stack in **Version**.
76
76
5. Select the **Region** in which you want to create the function app.
77
+
3. Select **OK** to create the app.
77
78
3. Under **Operating System**, select the type of Operating system that you're currently using. Azure recommends the type of Operating system based on your runtime stack selection.
78
79
4. Under **Plan**, select the type of plan that you want to use for the function app. Choose from the following options:
79
-
- Consumption (Serverless) - For event-driven scaling for the lowest minimum cost
80
-
- Functions Premium - For enterprise-level, serverless applications with event-based scaling and network isolation
80
+
- Consumption (Serverless) - For event-driven scaling for the most minimum cost.
81
+
- Functions Premium - For enterprise-level, serverless applications with event-based scaling and network isolation.
81
82
- App Service Plan - For reusing compute from an existing app service plan.
82
83
3. Select **Review + create** to create the app.
83
84
@@ -100,10 +101,10 @@ The first step is to create an Azure function to process the alert and create a
100
101
101
102
### Authentication
102
103
103
-
To use the PowerShell cmdlets, you must authenticate. You configure authentication in the function app. To configure authentication, you must configure environment variables and upload an encrypted key file to the function app.
104
+
To use the PowerShell cmdlets, you must configure authentication in the function app. To configure authentication, you must configure environment variables and upload an encrypted key file to the function app.
104
105
105
106
> [!NOTE]
106
-
> This scenario provides just one example of how to implement authentication with Azure Functions. There are other ways to do this.
107
+
> This scenario provides only one example of how to implement authentication with Azure Functions. There are other ways to do the same action.
In the App Service Editor of the function app, create a folder called **keys** under **AlertPacketCapturePowerShell**. Upload the **PassEncryptKey.key** file that you created in the previous PowerShell sample.
130
-
131
-
:::image type="content" source="./media/network-watcher-alert-triggered-packet-capture/key-function.png" alt-text="Screenshot of the Encryption key.":::
132
-
133
130
### Retrieve values for environment variables
134
131
135
-
The final requirement is to set up the environment variables that are necessary to access the values for authentication. The following list shows the environment variables that are created:
132
+
Set up the environment variables that are necessary to access the values for authentication. The following list shows the environment variables that are created:
136
133
137
134
* AzureClientID
138
135
* AzureTenant
139
136
* AzureCredPassword
140
137
138
+
If you already have an Application ID, use the AzureClientID, AzureTenant, and AzureCredPassword of that application. If you don't have one, proceed to [store the environment variables](#store-the-environment-variables).
139
+
141
140
#### AzureClientID
142
141
143
142
The client ID is the Application ID of an application in the Azure Active Directory.
144
143
145
-
1. If you don't already have an application to use, run the following example to create an application.
144
+
1. If you don't already have an application to use, run the following cmdlet to create an application.
146
145
147
146
```powershell
148
147
$app = New-AzADApplication -DisplayName "ExampleAutomationAccount_MF" -HomePage "https://exampleapp.com" -IdentifierUris "https://exampleapp1.com/ExampleFunctionsAccount" -Password "<same password as defined earlier>"
To store the environment variables, follow these steps:
193
+
193
194
1. Go to the function app. Select **Configurations** > **Application settings**.
194
195
195
196
:::image type="content" source="./media/network-watcher-alert-triggered-packet-capture/application-insights.png" alt-text="Screenshot of the Application settings screen.":::
@@ -198,7 +199,7 @@ $Encryptedpassword
198
199
199
200
### Add PowerShell to the function
200
201
201
-
It's now time to make calls into Network Watcher from within the Azure function. Depending on the requirements, the implementation of this function can vary. However, the general flow of the code is as follows:
202
+
Now, make calls into Network Watcher from within the Azure function. Depending on the requirements, the implementation of this function can vary. However, the general flow of the code is as follows:
202
203
203
204
1. Process input parameters.
204
205
2. Query existing packet captures to verify limits and resolve name conflicts.
Alerts can be configured to notify individuals when a specific metric crosses a threshold that's assigned to it. In this example, the alert is on the CPU Percentage that is sent, but the alert can be triggered for many other metrics.
322
+
You can configure alerts to notify individuals when a specific metric crosses a threshold that's assigned to it. In this example, the alert is on the Network Out Total that is sent, but the alert can be triggered for many other metrics.
332
323
333
324
### Create the alert rule
334
325
335
326
Go to an existing virtual machine and [add an alert rule](../azure-monitor/alerts/alerts-classic-portal.md). Do the following in the **Create an Alert rule** screen.
336
327
337
-
1. In the **Select a signal** pane, search for the name of the signal and select it. In this example, Percentage CPU is the selected signal. It denotes the percentage of allocated compute units that are in use by the VM.
338
-
339
-
:::image type="content" source="./media/network-watcher-alert-triggered-packet-capture/action-group.png" alt-text="Screenshot of the Create action group screen.":::
328
+
1. In the **Select a signal** pane, search for the name of the signal and select it. In this example, Network Out Total is the selected signal. It denotes the The number of bytes out on all network interfaces by the Virtual Machine.
340
329
341
330
2. In the **Conditions** tab, set the following values and select **Next: Actions >**.
342
331
@@ -353,6 +342,7 @@ Go to an existing virtual machine and [add an alert rule](../azure-monitor/alert
353
342
4. In the **Create action group** screen, select the **Subscription**, **Resource group**, and **Region**. Also enter the Action group name and the display name and select **Next: Notifications >**.
354
343
5. In the screen that appears, select **Action type** as **Azure Function**.
355
344
6. In the Azure Function pane, select the **Subscription**, **Resource group**, **Function app**, and **Azure Function**.
345
+
:::image type="content" source="./media/network-watcher-alert-triggered-packet-capture/action-group.png" alt-text="Screenshot of the Create action group screen.":::
356
346
7. Select **No** in **Enable the common alert schema** slider and select **OK**.
0 commit comments