Closed alexs77 closed 2 years ago
I am receiving the same error but with MySQL database resoruces:
Message="{\"code\":\"BadRequest\",\"message\":\"Detect invalid value: Microsoft.DBforMySQL/servers for query parameter: 'metricnamespace', the value must be: Microsoft.DBforMySQL/servers/databases if the query parameter is provided, you can also skip this optional query parameter.\"}
resource "azurerm_monitor_metric_alert" "db_cpu_anomaly" {
name = "${module.label_alert.id}-db-cpu"
enabled = true
resource_group_name = data.azurerm_resource_group.main.name
scopes = [azurerm_mysql_database.main.id]
description = "XXXX ${var.environment} database cpu usage exceeding the previously estimated average."
frequency = "PT15M"
severity = var.is_production ? local.severity_informational : local.severity_verbose
window_size = "PT15M"
dynamic_criteria {
metric_namespace = "Microsoft.DBforMySQL/servers"
metric_name = "cpu_percent"
aggregation = "Average"
operator = "GreaterOrLessThan"
alert_sensitivity = "Medium"
evaluation_total_count = 4
evaluation_failure_count = 4
}
action {
action_group_id = azurerm_monitor_action_group.main.id
}
}
The official Microsoft list of metric namespaces does not include Microsoft.DBforMySQL/servers/databases
@Ramblurr - that's how I do cpu_percent
alerting for MS SQL:
resource "azurerm_monitor_metric_alert" "db_cpu_yellow" {
name = "DB CPU Alert (Yellow)"
resource_group_name = data.azurerm_resource_group.this.name
description = "Action will be triggered when database CPU percentage is greater than or equal to ${var.db_cpu_yellow}, but less than ${var.db_cpu_red}."
scopes = [data.azurerm_mssql_database.this.id]
severity = 2
criteria {
metric_namespace = "Microsoft.Sql/servers/databases"
metric_name = "cpu_percent"
aggregation = "Average"
operator = "GreaterThanOrEqual"
threshold = var.db_cpu_yellow
}
criteria {
metric_namespace = "Microsoft.Sql/servers/databases"
metric_name = "cpu_percent"
aggregation = "Average"
operator = "LessThan"
threshold = var.db_cpu_red
}
action {
action_group_id = azurerm_monitor_action_group.yellow.id
webhook_properties = {}
}
}
Where did you find that Microsoft.DBforMySQL/servers
would be a legal value? To find legal values, I do:
# Namespace & Metric Name, see
$ az monitor metrics list-definitions --resource /subscriptions/$subscriptionId/resourceGroups/$rgName/providers/Microsoft.Sql/servers/$serverName/databases/$databaseName
I found the namespaces from this list https://docs.microsoft.com/en-us/azure/azure-monitor/essentials/metrics-supported#microsoftdbformysqlservers
My mistake - you're using MySQL. What I've sent is for MS SQL.
Yea, that page lists Microsoft.Sql/servers/databases
for MS SQL, and Microsoft.DBforMySQL/servers
for MySql..
Also az monitor metrics list-definitions
for my MySQL resource lists Microsoft.DBforMySQL/servers
Still an issue with hashicorp/azurerm v2.86.0.
Turns out that it was because of a wrong scope
. Changing to azurerm_servicebus_namespace
made it work.
Here's a fully working example:
provider "azurerm"{
features{}
}
data "azurerm_resource_group" "this" {
name = "myrg"
}
resource "azurerm_monitor_action_group" "example" {
name = "Error Alerts Action einahwa"
resource_group_name = data.azurerm_resource_group.this.name
short_name = "p4action"
email_receiver {
name = "sendtodevops"
email_address = "devops@contoso.com"
use_common_alert_schema = true
}
}
resource "azurerm_servicebus_namespace" "example" {
name = "servicebus-namespace-einahwa"
location = data.azurerm_resource_group.this.location
resource_group_name = data.azurerm_resource_group.this.name
sku = "Standard"
}
resource "azurerm_servicebus_queue" "example" {
name = "servicebus_queue_einahwa"
resource_group_name = data.azurerm_resource_group.this.name
namespace_name = azurerm_servicebus_namespace.example.name
enable_partitioning = true
}
resource "azurerm_monitor_metric_alert" "sb_dlq_example" {
scopes = [ azurerm_servicebus_namespace.example.id ]
name = "DLQ Alert einahwa"
resource_group_name = data.azurerm_resource_group.this.name
description = "DLQ Alert."
severity = 4
criteria {
metric_namespace = "Microsoft.ServiceBus/namespaces"
metric_name = "DeadletteredMessages"
aggregation = "Average"
operator = "GreaterThanOrEqual"
threshold = 5
}
action {
action_group_id = azurerm_monitor_action_group.example.id
}
}
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Community Note
Terraform (and AzureRM Provider) Version
Terraform v1.0.10
Output of
terraform init
:Affected Resource(s)
azurerm_monitor_metric_alert
Terraform Configuration Files
Debug Output
Expected Behaviour
Alert is created.
Actual Behaviour
See above.
Steps to Reproduce
terraform init
terraform apply
Important Factoids
Running in Azure DevOps Release Pipeline.
When I change
metric_namespace = "Microsoft.ServiceBus/namespaces"
tometric_namespace = "Microsoft.ServiceBus/namespaces/topics"
as indicated in the error message, I get this error message:Please note, that "
Microsoft.ServiceBus/namespaces/topics
" is missing in the list.I get the same errors when trying to use "
Microsoft.ServiceBus/namespaces/queues
; this is also not listed.References