我有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);
}
答案 0 :(得分: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