locked
Bad request on calling web api for creating metric alert in ADF RRS feed

  • Question

  • Hi,

    I am trying to call Web API for creating metric alert programmatically for my data factory. Below is the url which I am hitting :

    PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/metricAlerts/{ruleName}?api-version=2018-03-01

    I modified the URL with parameters.

    and my code look like as below :

    HttpClient client = new HttpClient();
    client.DefaultRequestHeaders.Accept.Clear();
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(result.AccessTokenType, result.AccessToken);
    HttpResponseMessage responseMessage = client.PutAsJsonAsync(ALERT_API, content).Result;
    var responseObj = responseMessage.Content.ReadAsStringAsync().Result;


    and my configuration file as below :

    location = "global",
    tags = { },
    properties = new Properties()
    {
    description = "This is test Alert through Code",
    severity = 1,
    scopes = new string[] { "/subscriptions/{SubscriptionId}/resourceGroup/{resourceGroupName}/providers/Microsoft.Analytics/dataFactory/{datafactoryName}" },
    evaluationFrequency = "PT1M",
    windowSize = "PT15M",
    targetResourceType = "Microsoft.Analytics/dataFactory",
    targetResourceRegion = "West Us 2",
    criteria = new Criteria()
    {
    odatatype = "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria",
    allOf = new Allof[]
    {
    new Allof
    {
    criterionType= "Failed activity runs metrics",
    name = "TestAlert",
    metricNamespace = "Microsoft.Analytics/dataFactory",
    Operator = "GreaterOrLessThan",
    timeAggregation = "Average",
    dimensions = new Dimensions[]
    {
    new Dimensions
    {
    name = "ActivityType",
    _operator = "Include",
    values = new string[]
    {
    "Lookup"
    }
    }
    },
    alertSensitivity = "Medium",
    failingPeriods = new Failingperiods()
    {
    numberOfEvaluationPeriods = 4,
    minFailingPeriodsToAlert = 4
    }
    }
    }
    },
    autoMitigate = false,
    enabled = true,
    actions = new AlertsConfig.Action[]
    {
    new AlertsConfig.Action
    {
    }
    }
    }

    When I hit the API it sends back a Bad request and it throws an error :

    "The criteria is not found"

    Can you guys please help me to fix this issue? Or What am I doing wrong here.

    Thanks in advance

    Wednesday, May 8, 2019 6:16 AM

All replies

  • Hello Ramandeep , 

    The way we understand your question is around the API 

    https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/metricAlerts/{ruleName}?api-version=2018-03-01 . 

    If that's the case you need to ask this question in the Microsoft.Insights forum .


    Thanks Himanshu

    Thursday, May 9, 2019 10:20 PM