@@ -24,7 +24,7 @@ The following logs are available in Azure:
24
24
| IKEDiagnosticLog | Logs IKE control messages and events on the gateway |
25
25
| P2SDiagnosticLog | Logs point-to-site control messages and events on the gateway |
26
26
27
- ## <a name =" setup " ></a >Set up alerts
27
+ ## <a name =" setup " ></a >Set up alerts in the Azure Portal
28
28
29
29
The following example steps will create an alert for a disconnection event that involves a site-to-site VPN tunnel:
30
30
@@ -94,6 +94,102 @@ The following example steps will create an alert for a disconnection event that
94
94
95
95

96
96
97
+ ## <a name="setuppowershell"></a>Set up alerts with Powershell
98
+
99
+ The following example steps will create an alert for a disconnection event that involves a site-to-site VPN tunnel.
100
+
101
+ 1. Create a Log Analytics workspace.
102
+
103
+ ```Powershell
104
+ $Location = 'westus2'
105
+ $ResourceGroupName = 'TestRG1'
106
+ $Sku = 'pergb2018'
107
+ $WorkspaceName = 'LogAnalyticsWS123'
108
+
109
+ New-AzOperationalInsightsWorkspace -Location $Location -Name $WorkspaceName -Sku $Sku -ResourceGroupName $ResourceGroupName
110
+ ```
111
+ 2 . Turn on diagnostics for the VPN gateway.
112
+
113
+ ``` Powershell
114
+ $ResourceGroupName = 'TestRG1'
115
+ $VpnGatewayName = 'VNet1GW'
116
+ $WorkspaceName = 'LogAnalyticsWS123'
117
+
118
+ $VpnGateway = Get-AzVirtualNetworkGateway -Name $VpnGatewayName -ResourceGroupName $ResourceGroupName
119
+ $Workspace = Get-AzOperationalInsightsWorkspace -Name $WorkspaceName -ResourceGroupName $ResourceGroupName
120
+
121
+ Set-AzDiagnosticSetting `
122
+ -Name 'VPN tunnel' `
123
+ -ResourceId $VpnGateway.Id `
124
+ -WorkspaceId $Workspace.ResourceId `
125
+ -Enabled $true `
126
+ -Category 'TunnelDiagnosticLog'
127
+ ```
128
+
129
+ 3 . Create an action group.
130
+
131
+ This will create an action group that will send an e-mail notification when an alert has been triggered.
132
+
133
+ ``` Powershell
134
+ $ActionGroupName = 'EmailAdmins' # Max. 60 characters long
135
+ $ActionGroupShortName = 'EmailAdmins' # Max. 12 characters long
136
+ $ActionGroupReceiverName = 'My receiver Name'
137
+ $EmailAddress = '[email protected] '
138
+ $ResourceGroupName = 'TestRG1'
139
+
140
+ $ActionGroupReceiver = New-AzActionGroupReceiver -Name $ActionGroupReceiverName -UseCommonAlertSchema -EmailReceiver -EmailAddress $EmailAddress
141
+
142
+ Set-AzActionGroup `
143
+ -ResourceGroupName $ResourceGroupName `
144
+ -Name $ActionGroupName `
145
+ -ShortName $ActionGroupShortName `
146
+ -Receiver @($ActionGroupReceiver)
147
+ ```
148
+
149
+ 4 . Create an alert rule based on a custom log search.
150
+
151
+ ``` Powershell
152
+ $ActionGroupName = 'EmailAdmins'
153
+ $EmailSubject = 'Redmond VPN tunnel is disconnected'
154
+ $Location = 'westus2'
155
+ $RemoteIp = '104.42.209.46'
156
+ $ResourceGroupName = 'TestRG1'
157
+ $VpnGatewayName = 'VNet1GW'
158
+ $WorkspaceName = 'LogAnalyticsWS123'
159
+
160
+ $VpnGateway = Get-AzVirtualNetworkGateway -Name $VpnGatewayName -ResourceGroupName $ResourceGroupName
161
+ $Workspace = Get-AzOperationalInsightsWorkspace -Name $WorkspaceName -ResourceGroupName $ResourceGroupName
162
+
163
+ $Query = @"
164
+ AzureDiagnostics |
165
+ where Category == "TunnelDiagnosticLog" |
166
+ where TimeGenerated > ago(5m) |
167
+ where _ResourceId == tolower("$($VpnGateway.id)") |
168
+ where remoteIP_s == "$($RemoteIp)" |
169
+ where status_s == "Disconnected" |
170
+ project TimeGenerated, OperationName, instance_s, Resource, ResourceGroup, _ResourceId |
171
+ sort by TimeGenerated asc
172
+ "@
173
+
174
+ $Source = New-AzScheduledQueryRuleSource -Query $Query -DataSourceId $Workspace.ResourceId
175
+ $Schedule = New-AzScheduledQueryRuleSchedule -FrequencyInMinutes 5 -TimeWindowInMinutes 5
176
+ $TriggerCondition = New-AzScheduledQueryRuleTriggerCondition -ThresholdOperator 'GreaterThan' -Threshold 0
177
+
178
+ $ActionGroup = Get-AzActionGroup -ResourceGroupName $ResourceGroupName -Name $ActionGroupName
179
+ $AznsActionGroup = New-AzScheduledQueryRuleAznsActionGroup -ActionGroup $ActionGroup.Id -EmailSubject $EmailSubject
180
+ $AlertingAction = New-AzScheduledQueryRuleAlertingAction -AznsAction $AznsActionGroup -Severity '1' -Trigger $TriggerCondition
181
+
182
+ New-AzScheduledQueryRule `
183
+ -ResourceGroupName $ResourceGroupName `
184
+ -Location $Location `
185
+ -Action $AlertingAction `
186
+ -Enabled $true `
187
+ -Description 'The tunnel between Azure and Redmond with IP address 104.42.209.46 is disconnected' `
188
+ -Schedule $Schedule `
189
+ -Source $Source `
190
+ -Name 'The Azure to Redmond tunnel is disconnected'
191
+ ```
192
+
97
193
## Next steps
98
194
99
195
To configure alerts on tunnel metrics, see [ Set up alerts on VPN Gateway metrics] ( vpn-gateway-howto-setup-alerts-virtual-network-gateway-metric.md ) .
0 commit comments