【问题标题】:Is there any terraform code or ARM Template code available for creating alerts in azure monitor which uses logic app as an action是否有任何 terraform 代码或 ARM 模板代码可用于在使用逻辑应用程序作为操作的 azure 监视器中创建警报
【发布时间】:2021-10-05 22:37:13
【问题描述】:
在我们的项目中,我们需要创建警报规则,当数据工厂中的管道失败时触发逻辑应用程序
我可以使用操作类型“逻辑应用”创建警报规则,这将触发逻辑应用。
现在我需要使用逻辑应用程序自动创建警报规则作为使用代码的操作,
是否有任何 Terraform 代码或 ARM 模板可用于使用逻辑应用操作创建警报规则。
【问题讨论】:
标签:
terraform
azure-logic-apps
arm-template
azure-monitoring
alerts
【解决方案1】:
我尝试使用以下 terraform 代码,并且能够创建使用逻辑应用作为操作的警报规则。
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "example" {
name = "" ##name of the resource group
location = "West Europe"
}
resource "azurerm_data_factory" "to_monitor" {
name = "" ## data factory Name
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
}
resource "azurerm_monitor_action_group" "main" {
name = "" ## Name of the action group
resource_group_name = azurerm_resource_group.example.name
short_name = "" ## Short Name for the action group
logic_app_receiver {
name = "" ##logic app action name
resource_id = "" ## resource id of the logic app
callback_url = "" ##call back url of the logic app
use_common_alert_schema = true
}
email_receiver {
name = "" ##name of the email reciepient
email_address = "" #mail address of the reciepient
use_common_alert_schema = true
}
}
resource "azurerm_monitor_metric_alert" "example" {
name = "" ## Name for the alert
resource_group_name = azurerm_resource_group.example.name
scopes = [azurerm_data_factory.to_monitor.id]
description = "Action will be triggered when Transactions count is greater than 0."
criteria {
metric_namespace = "Microsoft.Datafactory/factories"
metric_name = "PipelineFailedRuns"
aggregation = "Total"
operator = "GreaterThan"
threshold = 0
dimension {
name = "FailureType"
operator = "Include"
values = ["*"]
}
}
action {
action_group_id = azurerm_monitor_action_group.main.id
}
}
这是上述代码的输出供您参考