question

Timcspsps avatar image
0 Votes"
Timcspsps asked SwathiDhanwada-MSFT edited

Azure Update Management as Event Grid source

I would like assessments or updates done with Azure Update Management (Azure Automation) to be sent to a webhook. Now I've looked at Event Grid for this, but could not find a way to use AUM as a source for this.

How would I go about doing this? If not with Event Grid, is there some other Azure functionality I can use?

azure-automationazure-event-grid
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

SudiptaChakraborty-1767 avatar image
0 Votes"
SudiptaChakraborty-1767 answered

You can use Azure Automation Runbook and write a PowerShell script to send messages to Event Grid thereby making the Azure Automation Runbook as the source for Event Grid.

Create an Event Grid Topic:

  • Go to the appropriate resource group, and

  • Create a new resource

  • Pick Event Grid Topic, and click ‘Create’.

  • Specify the event topic name, subscription, resource group, location etc.

  • Take note of the “+ Event Subscription” and the Topic Endpoint.

  • The topic endpoint is important since this is where you can forward events to from your Azure Automation resources in order for event grid to pick them up. This URL takes a json payload.

  • After sending a couple of events, you can look at the ‘Published Events’ metric.

Sample Azure Automation PowerShell Script:

 Connect-AzAccount -Credential (get-credential)
 $body = @{
     id= 1
     eventType="recordInserted"
     subject="TestForAzureAutomationAsSource"
     eventTime= (get-date).ToUniversalTime()
     data= @{
         Name="Sudipta"
         Surname="Chakraborty"
         age="32"
     }
     dataVersion="1.0"
 }
 $body = "["+(ConvertTo-Json $body)+"]"
    
 $topicname="EventGridTopic01"
 try{
     $endpoint = (Get-AzEventGridTopic -ResourceGroupName AzureAutomation -Name $topicname).Endpoint
     $keys = Get-AzEventGridTopicKey -ResourceGroupName AzureAutomation -Name $topicname
     Invoke-WebRequest -Uri $endpoint -Method POST -Body $body -Headers @{"aeg-sas-key" = $keys.Key1}
 }
 catch{
     write-output $_
 }


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.