英文:
Terraform Azure Alert for 5xx except 503
问题
尝试创建一个在除了503之外的所有5xx状态代码上触发的警报。
这是我的警报:
locals {
xxx_alert_status_codes = [500, 501, 502, 504, 505, 506, 507, 508, 510, 511]
}
resource "azurerm_monitor_metric_alert" "xxx-d-ar-yyy-failed" {
provider = azurerm.dev
name = "yyy-exceptions-alert-dev"
resource_group_name = azurerm_resource_group.xxx-d-rg-yyy.name
scopes = [azurerm_linux_web_app.xxx-d-app-yyy]
description = "....."
severity = 1
dynamic "criteria" {
for_each = local.xxx_alert_status_codes
content {
metric_namespace = "Microsoft.Web/sites"
metric_name = "Http5xx"
dimension {
operator = "Include"
values = [{ HttpStatusCode = criteria.value }, { HttpMethod = "*" }]
name = "ALERT_HTTP${criteria.value}_ERROR"
}
aggregation = "Total"
operator = "GreaterThan"
threshold = 0
}
}
action {
action_group_id = azurerm_monitor_action_group.xxx-d-ag-yyy.id
}
}
错误是:属性 "values" 的值不合适:需要字符串。
我还尝试了以下维度块的方式:
dimension {
HttpStatusCode = criteria.value
HttpMethod = "*"
operator = "Include"
values = ["*"]
name = "ALERT_HTTP${criteria.value}_ERROR"
}
它产生了这个错误消息:不支持的参数 "HttpMethod"。
有没有人知道我应该怎么做?
我不想为每个状态代码创建单独的警报块。
这可能吗?
英文:
Trying to make an alert that is triggered for all 5xx status codes except 503.
This is my alert:
locals {
xxx_alert_status_codes = [500, 501, 502, 504, 505, 506, 507, 508, 510, 511]
}
resource "azurerm_monitor_metric_alert" "xxx-d-ar-yyy-failed" {
provider = azurerm.dev
name = "yyy-exceptions-alert-dev"
resource_group_name = azurerm_resource_group.xxx-d-rg-yyy.name
scopes = [ azurerm_linux_web_app.xxx-d-app-yyy ]
description = "....."
severity = 1
dynamic "criteria" {
for_each = local.yyy_alert_status_codes
content {
metric_namespace = "Microsoft.Web/sites"
metric_name = "Http5xx"
dimension {
operator = "Include"
values = [{HttpStatusCode = criteria.value},{HttpMethod="*"}]
name = "ALERT_HPPP${criteria.value}_ERROR"
}
aggregation = "Total"
operator = "GreaterThan"
threshold = 0
}
}
action {
action_group_id = azurerm_monitor_action_group.xxx-d-ag-yyy.id
}
}
The error is: Inappropriate value for attribute "values": element 0: string required.
I also tried the dimension block like this:
dimension {
HttpStatusCode = criteria.value
HttpMethod="*"
operator = "Include"
values = ["*"]
name = "ALERT_HPPP${criteria.value}_ERROR"
}
It yielded this error message: Unsupporter argument "HttpMethod".
Anyone have an idea of what I should do?
I do not want to make separate alert blocks for each status code.
Is it possible?
答案1
得分: 1
Your string error will go away if you fix your "values" row like this:
values = ["HttpStatusCode=\"${criteria.value}\",HttpMethod=\"*\""]
The issue was that you tried to use string interpolation incorrectly.
Please note that I'm not sure that this will enable you to deploy what you want because I'm suspecting other errors down the road. But regardless, this error will be resolved by the code I gave you: Inappropriate value for attribute "values": element 0: string required.
英文:
Your string error will go away if you fix your "values" row like this:
values = ["HttpStatusCode=\"${criteria.value}\",HttpMethod=\"*\""]
The issue was that you tried to use string interpolation incorrectly.
Please note that I'm not sure that this will enable you to deploy what you want, because I'm suspecting other errors down the road. But regardless, this error will be resolved by the code I gave you: Inappropriate value for attribute "values": element 0: string required.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论