2017-12-12 23 views
0

Azure Automation 계정에 Azure Runbook이 있습니다. 일부 매개 변수가 포함 된 Webhook을 사용하여 트리거하고 싶습니다.Azure 자동화 계정 : Webhook 데이터를 런북에 전달하는 방법?

runbook 내가 다음 저장하고 게시 한 다음에 대한은 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" 
    } 
} 

것 같습니다. 지침에 따라, 나는이은 webhook을 실행하는 데 약간의 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 

내가 내 푸른 자동화 runbook에은 webhook에서 성공적으로 데이터를 전달하기 위해 어떻게해야합니까? 실제로 작동 한 웹상에서 예제를 찾을 수 없었습니다.

+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" 
    } 
} 

여기에 설명을 참조하십시오.