ノンプログラマーの超初心者です。
下のCodeをもとに
PowerShell
1( 2 [Parameter (Mandatory = $false)] 3 [object] $WebhookData 4) 5 6# If runbook was called from Webhook, WebhookData will not be null. 7if ($WebhookData) { 8 9 # Check header for message to validate request 10 if ($WebhookData.RequestHeader.message -eq 'StartedbyContoso') 11 { 12 Write-Output "Header has required information"} 13 else 14 { 15 Write-Output "Header missing required information"; 16 exit; 17 } 18 19 # Retrieve VMs from Webhook request body 20 $vms = (ConvertFrom-Json -InputObject $WebhookData.RequestBody) 21 22 # Authenticate to Azure by using the service principal and certificate. Then, set the subscription. 23 24 Write-Output "Authenticating to Azure with service principal and certificate" 25 $ConnectionAssetName = "AzureRunAsConnection" 26 Write-Output "Get connection asset: $ConnectionAssetName" 27 28 $Conn = Get-AutomationConnection -Name $ConnectionAssetName 29 if ($Conn -eq $null) 30 { 31 throw "Could not retrieve connection asset: $ConnectionAssetName. Check that this asset exists in the Automation account." 32 } 33 Write-Output "Authenticating to Azure with service principal." 34 Add-AzAccount -ServicePrincipal -Tenant $Conn.TenantID -ApplicationId $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint | Write-Output 35 36 # Start each virtual machine 37 foreach ($vm in $vms) 38 { 39 $vmName = $vm.Name 40 Write-Output "Starting $vmName" 41 Start-AzVM -Name $vm.Name -ResourceGroup $vm.ResourceGroup 42 } 43} 44else { 45 # Error 46 write-Error "This runbook is meant to be started from an Azure alert webhook only." 47}
下記のデータを受信したいです。
{
"id": "59f2fd8e26a42a029eb486a2",
"time": "2017-01-06T04:44:42.490Z",
"locationName": "Office",
"zoneName": "ZONE-1",
}
※Microsoftのドキュメントは下記を参照してます
https://docs.microsoft.com/ja-jp/azure/automation/automation-webhooks
あなたの回答
tips
プレビュー