在监视 terraform (azure) 中的多个条件的警报中创建 2 个条件

create 2 criteria in an alert that monitors multiple criteria in terraform (azure)

我想添加另一个条件,但出现此错误 当警报规则包含多个条件时,维度的使用仅限于每个条件中每个维度一个值

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
        }

如果为一个条件设置了多个维度,则不能为警报规则设置 2 个条件,即不能将维度值用作 ["*"].

如果您想要在一个指标警报中使用多个条件,那么您将必须为一个条件提供一些维度值,并为其他条件提供相同的维度,或者您也不能对两者都使用维度块。

例如可以参考下面的代码:

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

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