Powershell Runbook: Parse Webhook Trigger works in Test Pane, Doesn't work when triggered by Events
Powershell 7.2
HybridWorker
The runbook is configured to be triggered by webhook as a "pre-event" for Azure Update Manager.
When I test in the "test pane" with an example webhook from a failed job in the logs, the script runs correctly.
When it is triggered during the update process, the Webhookdata gives :
NotificationPayload = ConvertFrom-Json -InputObject $WebhookData.RequestBody
Cannot bind argument to parameter 'InputObject' because it is null.
I tried using snippets directly from Microsoft Learn documents, they didn't work either!
Things i've tried:
- Online i've found people saying there were issues with PWSH 7.1 and parsing, and tested using regex switches to "properly" escape characters. Would work in Test Pane, not when called.
- tried converting the whole webhook out from json, then trying to pull the individual values, same outcome.
- tried adjusting the syntax a number of ways i don't have all recorded here.
This has been haunting me for over a week now, does anyone have any insight on how to get this to work?
OH! also, if there's any tips on how to fix the error/output stream to not generate all those "[31;1m[0m[" and split the logs into 24 inddividual log entries, that would be really appreciated too.
Thank you!
##most current test
param
(
[Parameter(Mandatory=$false)]
[object] $WebhookData
)
write-debug "Script with New syntax: " 5>&1
$notificationPayload = ConvertFrom-Json -InputObject $WebhookData.RequestBody
write-debug "Notification Payload is : `r$notificationPayload `r `n" 5>&1
$maintenanceRunId = $notificationPayload[0].data.CorrelationId
write-debug "MaintenanceRunId is : `r$maintenanceRunId `r `n" 5>&1
$resourceSubscriptionIds = $notificationPayload[0].data.ResourceSubscriptionIds
write-debug "resourceSubscriptionIds is : `r$resourceSubscriptionIds `r `n" 5>&1
$eventType = $notificationPayload[0].eventType
write-debug "EventType is: `r$eventType `r`n" 5>&1
##Original version of my script, based on script from here:
##
param
(
[Parameter(Mandatory=$false)]
[object] $WebhookData
)
Connect-AzAccount -Identity
$notificationPayload = ConvertFrom-Json -InputObject $WebhookData.RequestBody
$eventType = $notificationPayload[0].eventType
$notificationPayload = ConvertFrom-Json -InputObject $WebhookData.RequestBody
$eventType = $notificationPayload[0].eventType