Skip to content

Commit e012145

Browse files
authored
Multiple changes 🦦
1 parent 452f4c9 commit e012145

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

articles/update-manager/tutorial-webhooks-using-runbooks.md

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
title: Create pre and post events using a webhook with Automation runbooks.
33
description: In this tutorial, you learn how to create the pre and post events using webhook with Automation runbooks.
44
ms.service: azure-update-manager
5-
ms.date: 09/04/2024
5+
ms.date: 09/24/2024
66
ms.topic: tutorial
77
author: SnehaSudhirG
88
ms.author: sudhirsneha
9-
#Customer intent: As an IT admin, I want create pre and post events using a webhook with Automation runbooks.
9+
#Customer intent: As an IT admin, I want create pre and post events using a webhook with Automation runbooks.
1010
---
1111

1212
# Tutorial: Create pre and post events using a webhook with Automation
@@ -43,17 +43,15 @@ In this tutorial, you learn how to:
4343

4444
```powershell
4545
param
46-
4746
(
4847
[Parameter(Mandatory=$false)]
49-
5048
[object] $WebhookData
5149
5250
)
5351
$notificationPayload = ConvertFrom-Json -InputObject $WebhookData.RequestBody
5452
$eventType = $notificationPayload[0].eventType
5553
56-
if ($eventType -ne Microsoft.Maintenance.PreMaintenanceEvent -and $eventType –ne Microsoft.Maintenance.PostMaintenanceEvent ) {
54+
if ($eventType -ne "Microsoft.Maintenance.PreMaintenanceEvent" -and $eventType –ne "Microsoft.Maintenance.PostMaintenanceEvent" ) {
5755
Write-Output "Webhook not triggered as part of pre or post patching for maintenance run"
5856
return
5957
}
@@ -71,7 +69,6 @@ In this tutorial, you learn how to:
7169
```powershell
7270
param
7371
(
74-
7572
[Parameter(Mandatory=$false)]
7673
[object] $WebhookData
7774
)
@@ -124,7 +121,6 @@ param
124121
[Parameter(Mandatory=$false)]
125122
[object] $WebhookData
126123
)
127-
128124
Connect-AzAccount -Identity
129125
130126
# Install the Resource Graph module from PowerShell Gallery
@@ -133,9 +129,8 @@ Connect-AzAccount -Identity
133129
$notificationPayload = ConvertFrom-Json -InputObject $WebhookData.RequestBody
134130
$eventType = $notificationPayload[0].eventType
135131
136-
if ($eventType -ne “Microsoft.Maintenance.PreMaintenanceEvent”) {
137-
Write-Output "Webhook not triggered as part of pre-patching for
138-
maintenance run"
132+
if ($eventType -ne "Microsoft.Maintenance.PreMaintenanceEvent") {
133+
Write-Output "Webhook not triggered as part of pre-patching for maintenance run"
139134
return
140135
}
141136
@@ -219,20 +214,18 @@ foreach($id in $jobsList)
219214
```powershell
220215
param
221216
(
222-
223217
[Parameter(Mandatory=$false)]
224218
[object] $WebhookData
225219
)
226-
227220
Connect-AzAccount -Identity
228221
229222
# Install the Resource Graph module from PowerShell Gallery
230223
# Install-Module -Name Az.ResourceGraph
231224
$notificationPayload = ConvertFrom-Json -InputObject $WebhookData.RequestBody
232225
$eventType = $notificationPayload[0].eventType
233226
234-
if ($eventType -ne Microsoft.Maintenance.PostMaintenanceEvent) {
235-
Write-Output "Webhook not triggered as part of post-patching for maintenance run"
227+
if ($eventType -ne "Microsoft.Maintenance.PostMaintenanceEvent") {
228+
Write-Output "Webhook not triggered as part of post-patching for maintenance run"
236229
return
237230
}
238231
@@ -247,17 +240,11 @@ if ($resourceSubscriptionIds.Count -eq 0) {
247240
Start-Sleep -Seconds 30
248241
Write-Output "Querying ARG to get machine details [MaintenanceRunId=$maintenanceRunId][ResourceSubscriptionIdsCount=$($resourceSubscriptionIds.Count)]"
249242
$argQuery = @"
250-
251243
maintenanceresources
252-
253244
| where type =~ 'microsoft.maintenance/applyupdates'
254-
255245
| where properties.correlationId =~ '$($maintenanceRunId)'
256-
257246
| where id has '/providers/microsoft.compute/virtualmachines/'
258-
259247
| project id, resourceId = tostring(properties.resourceId)
260-
261248
| order by id asc
262249
"@
263250
@@ -321,8 +308,20 @@ foreach($id in $jobsList)
321308

322309
#### [Cancel a schedule](#tab/script-cancel)
323310
```powershell
311+
param
312+
(
313+
[Parameter(Mandatory=$false)]
314+
[object] $WebhookData
315+
)
316+
Connect-AzAccount -Identity
317+
318+
# Install the Resource Graph module from PowerShell Gallery
319+
# Install-Module -Name Az.ResourceGraph
320+
$notificationPayload = ConvertFrom-Json -InputObject $WebhookData.RequestBody
321+
$maintenanceRunId = $notificationPayload[0].data.CorrelationId
322+
324323
Invoke-AzRestMethod `
325-
-Path "<Correlation ID from EventGrid Payload>?api-version=2023-09-01-preview" `
324+
-Path "$maintenanceRunId`?api-version=2023-09-01-preview" `
326325
-Payload
327326
'{
328327
"properties": {

0 commit comments

Comments
 (0)