Skip to content

Latest commit

 

History

History
200 lines (132 loc) · 13.7 KB

pre-post-events-common-scenarios.md

File metadata and controls

200 lines (132 loc) · 13.7 KB
title description ms.service ms.topic ms.date author ms.author
Common scenarios in pre and post events (preview) in your Azure Update Manager
An overview of common scenarios for pre and post events (preview), including viewing the list of different endpoints, successful delivery to an endpoint, checking the script in Webhooks using runbooks triggered from Event Grid.
azure-update-manager
conceptual
02/03/2024
SnehaSudhir
sudhirsneha

Pre and Post events (preview) frequently asked questions

Applies to: ✔️ Windows VMs ✔️ Linux VMs ✔️ On-premises environment ✔️ Azure Arc-enabled servers.

This article presents the frequently asked questions in the lifecycle of pre and post events (preview).

How to check the configuration of pre and post event on your schedule and its count?

  1. Sign in to the Azure portal and go to Azure Update Manager.
  2. Under Manage, select Machines, Maintenance Configurations.
  3. On the Maintenance Configuration page, select the configuration.
  4. Select Overview, and check Maintenance events.
    • If there are no pre and post events that are set up, select Configure to set up. :::image type="content" source="./media/pre-post-events-common-scenarios/configure-new-event.png" alt-text="Screenshot that shows how to configure new event." lightbox="./media/pre-post-events-common-scenarios/configure-new-event.png":::

    • If there are pre and post events associated to the configuration, you can see the count of pre and post events associated to the configuration in the Events page.

How to view the list of pre and post events set up on a maintenance configuration?

  1. Sign in to the Azure portal and go to Azure Update Manager.

  2. Under Manage, select Machines, Maintenance Configurations.

  3. On the Maintenance Configuration page, select the configuration.

  4. On the selected maintenance configuration page, under Settings, select Events to view the pre and post events that you have created.

    The grid at the bottom of the Events subscription tab displays the names of both the pre and post events along with the corresponding Event Types.

    :::image type="content" source="./media/pre-post-events-common-scenarios/view-pre-post-events.png" alt-text="Screenshot that shows how to view the list of pre and post events." lightbox="./media/pre-post-events-common-scenarios/view-pre-post-events.png":::

How to view the list of different endpoints setup for pre and post events on a maintenance configuration?

  1. Sign in to the Azure portal and go to Azure Update Manager.

  2. Under Manage, select Machines, Maintenance Configurations.

  3. On the Maintenance Configuration page, select the configuration.

  4. On the selected maintenance configuration page, under Settings, select Events to view the pre and post events that you have created.

    In the grid at the bottom of the Event Subscription tab, you can view the endpoint details.

    :::image type="content" source="./media/pre-post-events-common-scenarios/view-endpoint.png" alt-text="Screenshot that shows how to view endpoints." lightbox="./media/pre-post-events-common-scenarios/view-endpoint.png":::

How to check the successful delivery of a pre or post event to an endpoint from Event Grid?

  1. Sign in to the Azure portal and go to Azure Update Manager.
  2. Under Manage, select Machines, Maintenance Configurations.
  3. On the Maintenance Configuration page, select the configuration.
  4. On the selected maintenance configuration page, under Settings, select Events.
  5. In the Essentials section, view metrics to see the metrics for all the events that are part of the event subscription. In the grid, the count of the Published Events metric should match with the count of Matched Events metric. Both of these two values should also correspond with the Delivered Events count.
  6. To view the metrics specific to a pre or a post event, select the name of the event from the grid. Here, the count of Matched Events metric should match with the Delivered Events count.
  7. To view the time at which the event was triggered, hover over the line graph. Learn more.

How to check an unsuccessful delivery of a pre and post events to an endpoint from Event Grid?

  1. Sign in to the Azure portal and go to Azure Update Manager.
  2. Under Manage, select Machines, Maintenance Configurations.
  3. On the Maintenance Configuration page, select the configuration.
  4. On the selected maintenance configuration page, under Settings, select Events.
  5. In the Essentials section, view metrics to see the metrics for all the events that are part of the event subscription. Here, you find that the count of the metric Delivery Failed Events increase.
  6. You further setup, you can do either of the following:
    1. Create Azure Monitor Alerts on this failure count to get notified of it. Set alerts on Azure Event Grid metrics and activity logs. (OR)
    2. Enable Diagnostic logs by linking to Storage accounts or Log Analytics workspace. Enable diagnostic logs for Event Grid resources.

    [!NOTE] You can anytime set up logs and alerts for a successful deliveries.

How to check if the endpoint has been triggered in the pre or post task?

  • The VM start operation requires the Automation Managed Identity to have Microsoft.Compute/virtualMachines/start/action permissions over the VMs to get started, and this permission is included in the VM Contributor role.
  • Ensure to import the PowerShell package - ThreadJob with the Module version:2.0.3.
  1. Sign in to the Azure portal and go to Azure Automation account.

  2. In your Automation account, under Process Automation, select Runbooks.

  3. Select the pre or post script linked to your Webhook in Event Grid.

  4. In Overview, you can view the status of the Runbook job. The trigger time should be approximately 30 minutes prior to the schedule start time. Once the job is finished, you can come back to the same section to confirm if the status is Completed.

    :::image type="content" source="./media/pre-post-events-common-scenarios/trigger-endpoint.png" alt-text="Screenshot that shows how to view the status of the Runbook job." lightbox="./media/pre-post-events-common-scenarios/trigger-endpoint.png":::

    Upon completion, you can confirm whether the prepatch installation process has been completed as planned. For instance, ensure that the VM has been either powered on or off.

For more information on how to retrieve details from Automation account's activity log:


How to check if the script in Webhooks using Runbooks is triggered from Event Grid?

  1. Sign in to the Azure portal and go to Azure Automation account.

  2. In your Automation account, under Process Automation, select Runbooks.

  3. Select the pre or post script linked to your Webhook in Event Grid.

  4. In Overview, you can view the status of the Runbook job. Select the Input tab to view the latest run of the job.

    :::image type="content" source="./media/pre-post-events-common-scenarios/view-input-parameter.png" alt-text="Screenshot that shows how to view the latest run of the job." lightbox="./media/pre-post-events-common-scenarios/view-input-parameter.png":::

How to check the cancelation of a schedule?

  1. Sign in to the Azure portal and go to Azure Update Manager.
  2. Under Manage, select Machines, Maintenance Configurations.
  3. On the Maintenance Configuration page, select the configuration.
  4. On the selected maintenance configuration page, under Settings, select Activity Log to view the pre and post events that you have created.
    1. If the current maintenance schedule was canceled, the operation name would be Write apply updates to a resource.

      :::image type="content" source="./media/pre-post-events-common-scenarios/write-apply-updates.png" alt-text="Screenshot that shows how to view tif the current maintenance schedule has been canceled." lightbox="./media/pre-post-events-common-scenarios/write-apply-updates.png":::

    2. Select the activity to view the details that the activity performs.

  1. The cancellation flow is honored from T-40 when the premaintenance event is triggered until T-10. Learn more.

    To invoke the cancelation API:

    C:\ProgramData\chocolatey\bin\ARMClient.exe put https://management.azure.com/<your-c-id-obtained-from-above>?api-version=2023-09-01-preview "{\"Properties\":{\"Status\": \"Cancel\"}}" -Verbose
  2. Ensure to insert the correlation ID of your maintenance job to cancel it and you see the response on the CLI/API as follows:

    :::image type="content" source="./media/pre-post-events-common-scenarios/cancelation-response.png" alt-text="Screenshot that shows the response for cancelation of schedule." lightbox="./media/pre-post-events-common-scenarios/write-apply-updates.png":::


How to confirm if the cancelation is by user or system?

You can view the status of the maintenance job from the ARG query mentioned above to understand if you've canceled the job or the system. The error message confirms the status of the job.

The following query allows you to view the list of VMs for a given schedule or a maintenance configuration:

maintenanceresources  
| where type =~ "microsoft.maintenance/maintenanceconfigurations/applyupdates"  
| where properties.correlationId has "/subscriptions/<your-s-id> /resourcegroups/<your-rg-id> /providers/microsoft.maintenance/maintenanceconfigurations/<mc-name> /providers/microsoft.maintenance/applyupdates/"  
| order by name desc

:::image type="content" source="./media/pre-post-events-common-scenarios/cancelation-query.png" alt-text="Screenshot that shows the status of job that has been canceled by system or user." lightbox="./media/pre-post-events-common-scenarios/cancelation-query.png":::

How to check the status of the maintenance configuration?

  1. Sign in to the Azure portal and go to Azure Update Manager.
  2. Under Manage, select History.
  3. Select By Maintenance ID tab to view the jobs by maintenance configurations. For the respective maintenance run ID, you can view the status of the job.
  4. Select the Status to view the details of the job. :::image type="content" source="./media/pre-post-events-common-scenarios/status-maintenance-configuration.png" alt-text="Screenshot that shows detailed view of the job." lightbox="./media/pre-post-events-common-scenarios/status-maintenance-configuration.png":::
  1. Use the following Azure Resource Graph (ARG) query to view the status of the job in ARG.

     maintenanceresources  
     | where type =~ "microsoft.maintenance/maintenanceconfigurations/applyupdates"  
     | where properties.correlationId has "/subscriptions/<your-s-id> /resourcegroups/<your-rg-id> /providers/microsoft.maintenance/maintenanceconfigurations/<mc-name> /providers/microsoft.maintenance/applyupdates/"  
     | order by name desc	 
  2. Ensure to insert the subscription ID, resource group, and maintenance configuration name in the above query

:::image type="content" source="./media/pre-post-events-common-scenarios/view-job-status.png" alt-text="Screenshot that shows how to insert the resource group, maintenance configuration." lightbox="./media/pre-post-events-common-scenarios/view-job-status.png":::


Why the scheduled run was cancelled by the system?

The system cancels the scheduled run if one or more of the following conditions are not met:

  1. If the maintenance configuration has at least one pre event subscribed and the schedule time is changed within the 40-minute window before the scheduled start time.
  2. If the pre-event was created within the 40-minute window before the scheduled start time.

Why the post event was not sent by the system?

If the user modifies the schedule run time after the pre-event has been triggered, the post event will not be sent because the scheduled time has been replaced with a new one.

Note

Azure Event Grid adheres to an at-least-once delivery paradigm. This implies that, in exceptional circumstances, there is a chance of the event handler being invoked more than once for a given event. Customers are advised to ensure that their event handler actions are idempotent. In other words, if the event handler is executed multiple times, it should not have any adverse effects. Implementing idempotency ensures the robustness of your application in the face of potential duplicate event invocations.

Next steps