Skip to content

Commit ce0b798

Browse files
author
Jill Grant
authored
Merge pull request #287275 from blakedrumm/patch-2
Multiple changes 🦦
2 parents 4b6b159 + 5ac3e03 commit ce0b798

File tree

2 files changed

+33
-34
lines changed

2 files changed

+33
-34
lines changed

articles/update-manager/includes/pre-post-prerequisites.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
author: SnehaSudhir
33
ms.author: sudhirsneha
44
ms.topic: include
5-
ms.date: 12/07/2023
5+
ms.date: 09/24/2024
66
---
77

88

@@ -22,24 +22,24 @@ ms.date: 12/07/2023
2222
Use PowerShell cmdlet [New-AzRoleAssignment](/powershell/module/az.resources/new-azroleassignment) to assign a role to the system-assigned managed identity.
2323

2424
```powershell
25-
New-AzRoleAssignment `
26-
-ObjectId $SA_PrincipalId `
27-
-ResourceGroupName $resourceGroup `
28-
-RoleDefinitionName "Contributor"
25+
New-AzRoleAssignment `
26+
-ObjectId $SA_PrincipalId `
27+
-ResourceGroupName $resourceGroup `
28+
-RoleDefinitionName "Contributor"
2929
```
3030
3131
Assign a role to a user-assigned managed identity.
3232
3333
```powershell
34-
New-AzRoleAssignment `
35-
-ObjectId $UAMI.PrincipalId`
36-
-ResourceGroupName $resourceGroup `
37-
-RoleDefinitionName "Contributor"
34+
New-AzRoleAssignment `
35+
-ObjectId $UAMI.PrincipalId `
36+
-ResourceGroupName $resourceGroup `
37+
-RoleDefinitionName "Contributor"
3838
```
3939
For the system-assigned managed identity, show `ClientId` and record the value for later use.
4040
4141
```powershell
42-
$UAMI.ClientId
42+
$UAMI.ClientId
4343
```
4444
---
45-
3. Import the `Az.ResourceGraph` module, ensure the module is updated to ThreadJob with the module version 2.0.3.
45+
3. Import the `Az.ResourceGraph` module, ensure the module is updated to ThreadJob with the module version 2.0.3.

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

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
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
1313

1414
**Applies to:** :heavy_check_mark: Windows VMs :heavy_check_mark: Linux VMs :heavy_check_mark: On-premises environment :heavy_check_mark: Azure VMs :heavy_check_mark: Azure Arc-enabled servers.
1515

16-
Pre and post events, also known as pre/post-scripts, allow you to execute user-defined actions before and after the schedule patch installation. One of the most common scenarios is to start and stop a VM. With pre-events, you can run a prepatching script to start the VM before initiating the schedule patching process. Once the schedule patching is complete, and the server is rebooted, a post-patching script can be executed to safely shut down the VM.
16+
Pre and post events, also known as pre/post-scripts, allow you to execute user-defined actions before and after the schedule patch installation. One of the most common scenarios is to start and stop a Virtual Machine (VM). With pre-events, you can run a prepatching script to start the VM before initiating the schedule patching process. Once the schedule patching is complete, and the server is rebooted, a post-patching script can be executed to safely shut down the VM.
1717

1818
This tutorial explains how to create pre and post events to start and stop a VM in a schedule patch workflow using a webhook.
1919

@@ -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
)
@@ -111,7 +108,7 @@ In this tutorial, you learn how to:
111108
}
112109
```
113110
114-
1. To customize you can use either your existing scripts with the above modifications done or use the following scripts.
111+
1. To customize, you can use either your existing scripts with the above modifications done or use the following scripts.
115112
116113
117114
### Sample scripts
@@ -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)