简体   繁体   中英

How to pass runbook parameters from mvc website c# code to azure portal

I have MVC website in which I have called Runbook from Webhook Uri but now I want to pass input parameters to runbook. Following code I wrote to call runbook and pass parameters but parameters are going in Webhookdata instead of going as inputs.

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);
    }

I got answer. We have to use that webhook-data to fetch out input parameters. Check code below to get input parameters from runbook script.

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   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM