Azure Monitor Metric Alert
This page shows how to write Terraform and Azure Resource Manager for Monitor Metric Alert and write them securely.
azurerm_monitor_metric_alert (Terraform)
The Metric Alert in Monitor can be configured in Terraform with the resource name azurerm_monitor_metric_alert
. The following sections describe 7 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_monitor_metric_alert" "networkbitspersec" {
name = var.networkbitspersec
resource_group_name = var.resourcegroup
scopes = [azurerm_network_interface.to_monitor.id]
description = "Action will be triggered when Bits ingressing Azure per second is greater than XX."
resource "azurerm_monitor_metric_alert" "SynapsewpAlert" {
depends_on = [
azurerm_synapse_workspace.synapse_workspace,
azurerm_monitor_action_group.alert-action-group
]
name = var.Synapsewp_Alert_name
resource "azurerm_monitor_metric_alert" "StorageAccountAlert" {
depends_on = [
azurerm_storage_account.StorageAccount,
azurerm_monitor_action_group.alert-action-group
]
name = var.Storage_Account_Alert_name
resource "azurerm_monitor_metric_alert" "Azure-StorageTableServices-Transactions" {
name = "Azure-StorageTableServices-Transactions"
resource_group_name = var.resource_group_name
scopes = var.scopes
description = "Azure - Storage Table Services - Transactions{{name.name}} exceeds the previously estimated average.Please refer to the following reaction process:https://apptemetry/knowledgebase/Article.aspx?id=54321 Alerts generate an AIM ticket, viewable here (search via CI or Alert Name):https://apptemetry/AIM/alertsearch.aspx"
frequency = "PT5M"
resource "azurerm_monitor_metric_alert" "Azure-StorageTableServices-Transactions" {
name = "Azure-StorageTableServices-Transactions"
resource_group_name = var.resource_group_name
scopes = var.scopes
description = "Azure - Storage Table Services - Transactions{{name.name}} exceeds the previously estimated average.Please refer to the following reaction process:https://apptemetry/knowledgebase/Article.aspx?id=54321 Alerts generate an AIM ticket, viewable here (search via CI or Alert Name):https://apptemetry/AIM/alertsearch.aspx"
frequency = "PT5M"
resource "azurerm_monitor_metric_alert" "Azure-LogicApps-TriggersSucceeded" {
name = "Azure-LogicApps-TriggersSucceeded"
resource_group_name = var.resource_group_name
scopes = var.scopes
description = "Azure - Logic Apps - Triggers Succeeded{{name.name}} exceeds the previously estimated average.Please refer to the following reaction process:https://apptemetry/knowledgebase/Article.aspx?id=54321Alerts generate an AIM ticket, viewable here (search via CI or Alert Name):https://apptemetry/AIM/alertsearch.aspx"
frequency = "PT15M"
resource "azurerm_monitor_metric_alert" "Azure-LogicApps-TriggersSucceeded" {
name = "Azure-LogicApps-TriggersSucceeded"
resource_group_name = var.resource_group_name
scopes = var.scopes
description = "Azure - Logic Apps - Triggers Succeeded{{name.name}} exceeds the previously estimated average.Please refer to the following reaction process:https://apptemetry/knowledgebase/Article.aspx?id=54321Alerts generate an AIM ticket, viewable here (search via CI or Alert Name):https://apptemetry/AIM/alertsearch.aspx"
frequency = "PT15M"
Parameters
-
auto_mitigate
optional - bool -
description
optional - string -
enabled
optional - bool -
frequency
optional - string -
id
optional computed - string -
name
required - string -
resource_group_name
required - string -
scopes
required - set of string -
severity
optional - number -
tags
optional - map from string to string -
target_resource_location
optional computed - string
The location of the target resource. Required when using subscription, resource group scope or multiple scopes.
-
target_resource_type
optional computed - string
The resource type (e.g. Microsoft.Compute/virtualMachines) of the target resource. Required when using subscription, resource group scope or multiple scopes.
-
window_size
optional - string -
action
set block-
action_group_id
required - string -
webhook_properties
optional - map from string to string
-
-
application_insights_web_test_location_availability_criteria
list block-
component_id
required - string -
failed_location_count
required - number -
web_test_id
required - string
-
-
criteria
set block-
aggregation
required - string -
metric_name
required - string -
metric_namespace
required - string -
operator
required - string -
skip_metric_validation
optional - bool -
threshold
required - number -
dimension
list block
-
-
dynamic_criteria
set block-
aggregation
required - string -
alert_sensitivity
required - string -
evaluation_failure_count
optional - number -
evaluation_total_count
optional - number -
ignore_data_before
optional - string -
metric_name
required - string -
metric_namespace
required - string -
operator
required - string -
skip_metric_validation
optional - bool -
dimension
list block
-
-
timeouts
single block
Explanation in Terraform Registry
Manages a Metric Alert within Azure Monitor.
Tips: Best Practices for The Other Azure Monitor Resources
In addition to the azurerm_monitor_log_profile, Azure Monitor has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
azurerm_monitor_log_profile
Ensure to enable the activity retention log
It is better to enable the activity retention log to ensure that all the information required for an effective investigation is still available.
Microsoft.Insights/metricAlerts (Azure Resource Manager)
The metricAlerts in Microsoft.Insights can be configured in Azure Resource Manager with the resource name Microsoft.Insights/metricAlerts
. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
"type": "Microsoft.Insights/metricAlerts",
"name": "[variables('alerts').confNodeOffline.name]",
"apiVersion": "2018-03-01",
"location": "global",
"properties": {
"description": "A Confluence node has just became unhealthly/gone offline. ",
"type": "Microsoft.Insights/metricAlerts",
"name": "[variables('alerts').jiraNodeOffline.name]",
"apiVersion": "2018-03-01",
"location": "global",
"scale": null,
"properties": {
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appInsightName": {
"type": "Microsoft.Insights/metricAlerts",
"properties": {
"scopes": [
"[concat(parameters('servers_testtssql_externalid'), '/databases/sqldb2')]"
],
"severity": 3,
"type": "Microsoft.Insights/metricAlerts",
"apiVersion": "2018-03-01",
"name": "Critical Alerts - Static",
"location": "global",
"properties": {
"severity": 0,
"type": "Microsoft.Insights/metricAlerts",
"apiVersion": "2018-03-01",
"name": "[variables('alerts').sshLoadBalancerHealthCheckAlert.name]",
"location": "global",
"properties": {
"description": "[variables('alerts').sshLoadBalancerHealthCheckAlert.description]",
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"variables": {},
"parameters": {
"type": "Microsoft.Insights/metricAlerts",
"name": "[concat('Network_In_Alert','-',parameters('alertVMs')[copyIndex()])]",
"copy": {
"name": "iterator",
"count": "[length(parameters('alertVMs'))]"
},
"type": "Microsoft.Insights/metricAlerts",
"name": "[variables('alerts').crowdNodeOffline.name]",
"apiVersion": "2018-03-01",
"location": "global",
"properties": {
"description": "A Crowd node has just became unhealthly/gone offline. ",
"type": "Microsoft.Insights/metricAlerts",
"name": "[variables('alerts').confNodeOffline.name]",
"apiVersion": "2018-03-01",
"location": "global",
"properties": {
"description": "A Confluence node has just became unhealthly/gone offline. ",
Frequently asked questions
What is Azure Monitor Metric Alert?
Azure Monitor Metric Alert is a resource for Monitor of Microsoft Azure. Settings can be wrote in Terraform.
Where can I find the example code for the Azure Monitor Metric Alert?
For Terraform, the haroon-yunus/Metrics, chaitanya867/KPMG-a.txt and chaitanya867/KPMG-a.txt source code examples are useful. See the Terraform Example section for further details.
For Azure Resource Manager, the ebizzity/atlassian-azure, ebizzity/atlassian-azure and Azure/iotedge-lorawan-starterkit source code examples are useful. See the Azure Resource Manager Example section for further details.