0

我有 MVC 网站,我在其中从 Webhook Uri 调用了 Runbook,但现在我想将输入参数传递给 Runbook。以下代码是我编写的调用 runbook 并传递参数,但参数在 Webhookdata 中而不是作为输入。

using(var client = new HttpClient()) {
    client.BaseAddress = new Uri("https://s2events.azure-automation.net/");
    client.DefaultRequestHeaders.Accept.Clear();
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

    // HTTP POST
    var parameters = new InputParam() {
      subscriptionId = mSubscriptnId,
      resourceGrpName = vMachine.ResourceGroupName,
      vmssName = vMachine.Name,
      vmssInstanceId = vMachine.InstanceId,
      action = vmssInstanceAction,
      count = "5"
    };

    HttpResponseMessage response = client.PostAsJsonAsync(mWebhookUri, parameters).Result;

    if(response.IsSuccessStatusCode) {
      Console.WriteLine(response.Content);
    }
4

1 回答 1

0

我得到了答案。我们必须使用该 webhook-data 来获取输入参数。检查下面的代码以从 Runbook 脚本获取输入参数。

Param 
(    
    [object] $WebhookData,
)

# Get the data object from WebhookData.
$WebhookBody = (ConvertFrom-Json -InputObject $WebhookData.RequestBody)

$subscriptionId = $WebhookBody.subscriptionId
$resourceGrpName = $WebhookBody.resourceGrpName
$vmssName = $WebhookBody.vmssName
$vmssInstanceId = $WebhookBody.vmssInstanceId
$action = $WebhookBody.action
$count = $WebhookBody.count   
于 2018-02-23T06:55:14.170 回答