繁体   English   中英

如何使用 Terraform 为 Azure 资源创建警报

[英]How to create alerts for Azure resources using Terraform

我已经为 App Service、AppService Plan、Storage Account 和 Logic App 等 azure 资源准备了 Terraform 个脚本……。

我已经成功部署了上面的 Terraform 个脚本。 但我想使用 Terraform 配置上述资源的警报。

有什么方法可以在没有 ARM 模板部署的情况下使用 Terraform 创建警报?

当然有。 这是 Application Insights 的自定义日志搜索示例。 但是您可以轻松地为另一个来源修改它,例如 Azure Monitor

resource "azurerm_application_insights" "example" {
  name                = "${var.prefix}-appinsights"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  application_type    = "web"
  retention_in_days   = 30
}

resource "azurerm_monitor_action_group" "example" {
  name                = "CriticalAlertsAction"
  resource_group_name = azurerm_resource_group.example.name
  short_name          = "p0action"

  email_receiver {
    name                    = "sendtoadmin"
    email_address           = "admin@example.com"
    use_common_alert_schema = true
  }
}

resource "azurerm_monitor_scheduled_query_rules_alert" "example-alert1" {
  name                = "${var.prefix}-alertrule1"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name

  action {
    action_group = [
      azurerm_monitor_action_group.example.id
    ]
  }
  data_source_id = azurerm_application_insights.example.id
  description    = "Exception threshold reached"
  enabled        = true
  # Count all requests with server error result code grouped into 5-minute bins
  query       = <<-QUERY
  requests
    | where cloud_RoleName == "frontend" and name !contains "Health" and resultCode startswith "5" 
  QUERY
  severity    = 1
  frequency   = 5
  time_window = 5
  trigger {
    operator  = "GreaterThan"
    threshold = 10
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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