gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 06:17:44 26 4
gpt4 key购买 nike

我已经为应用程序服务、应用程序服务计划、存储帐户和逻辑应用程序等 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 = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1776737a7e7957726f767a677b723974787a" rel="noreferrer noopener nofollow">[email protected]</a>"
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
}
}

关于azure - 如何使用 Terraform 创建 Azure 资源警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65404091/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com