2

I want to add another criteria but I get this error When the alert rule contains multiple criteria, the use of dimensions is limited to one value per dimension within each criterion

resource "azurerm_monitor_metric_alert" "example" {
     name                = "example-metricalert"
     resource_group_name = azurerm_resource_group.main.name
     scopes              = [azurerm_storage_account.to_monitor.id]
     description         = "Action will be triggered when Transactions count is greater than 50."

    criteria {
       metric_namespace = "Microsoft.Storage/storageAccounts"
       metric_name      = "Transactions"
       aggregation      = "Total"
       operator         = "GreaterThan"
       threshold        = 50

    dimension {
      name     = "ApiName"
      operator = "Include"
      values   = ["*"]
      }
        }
  
    criteria {
       metric_namespace = "Microsoft.Storage/storageAccounts"
       metric_name      = "Transactions"
       aggregation      = "Total"
       operator         = "GreaterThan"
       threshold        = 50

    dimension {
      name     = "ApiName"
      operator = "Include"
      values   = ["*"]
    }
       }

      action {
         action_group_id = azurerm_monitor_action_group.main.id
        }
Ansuman Bal
  • 9,705
  • 2
  • 10
  • 27
Mr_Unchained
  • 45
  • 1
  • 8
  • Hello @Mr_Unchanied, AFAIK its not possible to create another conditon/criteria if there are multiple dimensions i.e. Dimensions value cannot be ["*"]. If you can give a specific API name there then you can create another criteria. Its the same from portal as well – Ansuman Bal Dec 01 '21 at 06:10

1 Answers1

1

You cannot set 2 conditions for a alert rule when you have set multiple dimensions for one condition i.e. you can't use Dimension Value as ["*"].

enter image description here

If you want multiple conditions in one Metric Alert then you will have to give some dimension value for one criteria and same dimension for other criteria as well or you can also not use dimension block for both .

For example, you can refer the below code:

resource "azurerm_monitor_metric_alert" "example" {
  name                = "example-metricalert"
  resource_group_name = azurerm_resource_group.main.name
  scopes              = [azurerm_storage_account.to_monitor.id]
  description         = "Action will be triggered when Transactions count is greater than 50."

  criteria {
    metric_namespace = "Microsoft.Storage/storageAccounts"
    metric_name      = "Transactions"
    aggregation      = "Total"
    operator         = "GreaterThan"
    threshold        = 50

    dimension {
      name     = "ApiName"
      operator = "Include"
      values   = ["GetBlobServiceProperties"]

    }
  }
criteria {
    metric_namespace = "Microsoft.Storage/storageAccounts"
    metric_name      = "SuccessE2ELatency"
    aggregation      = "Average"
    operator         = "GreaterThan"
    threshold        = 10
        dimension {
      name     = "ApiName"
      operator = "Include"
      values   = ["GetBlobServiceProperties"]

    }
  }


  action {
    action_group_id = azurerm_monitor_action_group.main.id
  }
}

enter image description here

OR

resource "azurerm_monitor_metric_alert" "example1" {
  name                = "example1-metricalert"
  resource_group_name = azurerm_resource_group.main.name
  scopes              = [azurerm_storage_account.to_monitor.id]
  description         = "Action will be triggered when Transactions count is greater than 50."

  criteria {
    metric_namespace = "Microsoft.Storage/storageAccounts"
    metric_name      = "Transactions"
    aggregation      = "Total"
    operator         = "GreaterThan"
    threshold        = 50
  }
criteria {
    metric_namespace = "Microsoft.Storage/storageAccounts"
    metric_name      = "SuccessE2ELatency"
    aggregation      = "Average"
    operator         = "GreaterThan"
    threshold        = 10
  }


  action {
    action_group_id = azurerm_monitor_action_group.main.id
  }
}

enter image description here

Ansuman Bal
  • 9,705
  • 2
  • 10
  • 27