【问题标题】:Azure Alert Creation Via terraform fails with error code 400通过 terraform 创建 Azure 警报失败,错误代码为 400
【发布时间】:2019-06-05 03:54:15
【问题描述】:

通过 terraform 在存储帐户上创建指标警报时,我收到错误 400

我已经浏览了文档并经过验证,我用于创建警报的名称是正确的

resource "azurerm_metric_alertrule" "test" {
name                = "alerttestacc"
resource_group_name = "${azurerm_resource_group.main.name}"
location            = "${azurerm_resource_group.main.location}"

description = "An alert rule to watch the metric Used capacity"

enabled = true

resource_id = "${azurerm_storage_account.to_monitor.id}"
metric_name = "UsedCapacity"
operator    = "GreaterThan"
threshold   = 20
aggregation = "Total"
period      = "PT5M"

email_action {
    send_to_service_owners = false

    custom_emails = [
    "xyz@gmail.com",
    ]
}

webhook_action {
    service_uri = "https://example.com/some-url"

    properties = {
        severity        = "incredible"
        acceptance_test = "true"
    }
}

预期:应创建警报

实际:

azurerm_metric_alertrule.test: Insights.AlertRulesClient#CreateOrUpdate:响应失败 请求:StatusCode=400 -- 原始错误:autorest/azure:服务 返回错误。状态=400 代码="UnsupportedMetric" 消息="的 不支持具有命名空间“”和名称“UsedCapacity”的度量标准 这个资源id

【问题讨论】:

  • 您为什么如此确定该指标存在?这对我来说肯定没有多大意义
  • Azure 文档说指标存在。 link
  • 查看link
  • 在第二个链接上有一个metric_name,其中给出了所有指标的链接。
  • 广泛列表link

标签: azure terraform azure-automation alerts terraform-provider-azure


【解决方案1】:

您可以使用 azurerm_monitor_metric_alert 而不是 azurerm_metric_alertrule 为存储帐户创建 UsedCapacity 指标警报。这可能是由于 Azure 监控中经典警报和新警报之间的不同体验。阅读警报overview

这个例子对我有用。

resource "azurerm_resource_group" "main" {
  name     = "example-resources"
  location = "West US"
}

resource "azurerm_storage_account" "to_monitor" {
  name                     = "examplestorageaccount123"
  resource_group_name      = "${azurerm_resource_group.main.name}"
  location                 = "${azurerm_resource_group.main.location}"
  account_tier             = "Standard"
  account_replication_type = "LRS"
}

resource "azurerm_monitor_action_group" "main" {
  name                = "example-actiongroup"
  resource_group_name = "${azurerm_resource_group.main.name}"
  short_name          = "exampleact"

  webhook_receiver {
    name        = "callmyapi"
    service_uri = "http://example.com/alert"
  }
}

resource "azurerm_monitor_metric_alert" "test" {
  name                = "example-metricalert"
  resource_group_name = "${azurerm_resource_group.main.name}"
  scopes              = ["${azurerm_storage_account.to_monitor.id}"]
  description         = "Action will be triggered when the Used capacity is Greater than 777 bytes."

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

  }

  action {
    action_group_id = "${azurerm_monitor_action_group.main.id}"
  }
}

【讨论】:

    猜你喜欢
    • 2021-06-09
    • 1970-01-01
    • 1970-01-01
    • 2018-09-27
    • 2021-03-31
    • 1970-01-01
    • 2021-05-09
    • 2019-12-22
    • 2021-01-15
    相关资源
    最近更新 更多