2017-12-12 4 views
0

Azure AutomationアカウントにAzure Runbookがあります。これは、いくつかのパラメータを含むwebhookでトリガーしたいものです。Azure Automation Account:Webhookデータをランブックに渡すには?

ランブックは、私はそれを保存し、それを公表し、それのためのウェブフックを得た。この

workflow do-something 
{ 

    param 
    (
     [object]$WebhookData 
    ) 
    inlinescript { 

     if ($WebhookData -ne $null) { 
      $WebhookName = $WebhookData.WebhookName 
      $WebhookBody = $WebhookData.RequestBody 

      $webhookBodyObject = $WebhookBody | ConvertFrom-JSON 
      $customerEmail = $webhookBodyObject.customerEmail 
      $customerName = $webhookBodyObject.customerName 
      $dataLocation = $webhookBodyObject.dataLocation 

     } else { 
      "The WebhookData is totally and completely null" 
      exit (0) 
     } 
     $webhookjson = $WebhookData | ConvertTo-JSON 
     "The webhookdata is $webhookjson" 
     "The webhook name is $WebhookName" 
     "The customer email is $customerEmail" 
     "The body s $WebhookBody" 
    } 
} 

のように見えます。指示に従って、私はウェブフックをトリガするために少しPowerShellスクリプトを書きました:私は要求を呼び出し

#Not the real URI, but similar in structure 
$uri = "https://s10events.azure-automation.net/webhooks?token=Qt%xyxyxyxyxyxyxyxyxyxyxyxy%ababababab%3d" 
$headers = @{"From"="[email protected]";"Date"="05/28/2015 15:47:00"} 

$params = @{"customerName"="Jay Godse"; "customerEmail"="[email protected]"; "dataLocation"="Canada"} 
$body = ConvertTo-Json -InputObject $params 

#$response = Invoke-RestMethod -Method Post -Uri $uri -Headers $headers -Body $body 
$webresp = Invoke-WebRequest -Method Post -Uri $uri -Headers $headers -Body $body -Verbose 

、私は、要求が正常にキューに入ったことが示唆された202応答コードを得ました。

私はRunbookのJobsセクションに行き、ジョブの入力と出力を調べました。出力はこのように見えた

{"WebhookName":"test1","RequestBody":"{\r\n \"customerEmail\": \"[email protected]\",\r\n \"customerName\": \"Jay Godse\",\r\n \"dataLocation\": \"Canada\"\r\n}","RequestHeader":{"Connection":"Keep-Alive","Date":"Thu, 28 May 2015 19:47:00 GMT","From":"[email protected]","Host":"s10events.azure-automation.net","User-Agent":"Mozilla/5.0","x-ms-request-id":"d8995f98-1344-4822-af69-ababababababa"}} 

:入力はこのように見えた

The WebhookData is totally and completely null 

私は私のAzureのオートメーションランブックにウェブフックから成功したデータを渡すためにしなければならないのですか?私は実際に働いたウェブ上の例を見つけることができませんでした。

+1

'$ using:WebhookData'を' inlinescript {} 'ブロックの中で使ってみましょう。以下の説明を参照してください。https://technet.microsoft.com/en-us/library/jj574197(v=ws.11).aspx – n01d

+0

ありがとうございます@ no1d。 $使用方法:WebhookDataが機能しました。これを答えとして書くと、私はそれを受け入れます。 –

答えて

1

あなたはそのようなinlinescript {}ブロック内$using:スコープを使用する必要があります:https://technet.microsoft.com/en-us/library/jj574197(v=ws.11).aspx( "のInlineScriptの変数" セクション):

workflow do-something 
{ 

    param 
    (
     [object]$WebhookData 
    ) 
    inlinescript { 

     if ($using:WebhookData -ne $null) { 
      $WebhookName = $using:WebhookData.WebhookName 
      $WebhookBody = $using:WebhookData.RequestBody 

      $webhookBodyObject = $WebhookBody | ConvertFrom-JSON 
      $customerEmail = $webhookBodyObject.customerEmail 
      $customerName = $webhookBodyObject.customerName 
      $dataLocation = $webhookBodyObject.dataLocation 

     } else { 
      "The WebhookData is totally and completely null" 
      exit (0) 
     } 
     $webhookjson = $using:WebhookData | ConvertTo-JSON 
     "The webhookdata is $webhookjson" 
     "The webhook name is $WebhookName" 
     "The customer email is $customerEmail" 
     "The body s $WebhookBody" 
    } 
} 

は、ここでの説明を参照してください。

関連する問題