Azure Monitor Scheduled Query Rules Alert
This page shows how to write Terraform and Azure Resource Manager for Monitor Scheduled Query Rules Alert and write them securely.
azurerm_monitor_scheduled_query_rules_alert (Terraform)
The Scheduled Query Rules Alert in Monitor can be configured in Terraform with the resource name azurerm_monitor_scheduled_query_rules_alert
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_monitor_scheduled_query_rules_alert" "example" {
name = format("%s-queryrule", var.prefix)
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
action {
resource "azurerm_monitor_scheduled_query_rules_alert" "example" {
name = format("%s-queryrule", var.prefix)
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
action {
resource "azurerm_monitor_scheduled_query_rules_alert" "example" {
name = format("%s-queryrule", var.prefix)
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
action {
resource "azurerm_monitor_scheduled_query_rules_alert" "FailedP2Sconnections" {
name = "Failed P2S connections"
location = var.location
resource_group_name = var.log_analytics_resource_group_name
action {
resource "azurerm_monitor_scheduled_query_rules_alert" "Azure-LogicApps-TriggersSucceeded" {
name = "Azure-LogicApps-TriggersSucceeded"
location = var.location
resource_group_name = var.log_analytics_resource_group_name
action {
resource "azurerm_monitor_scheduled_query_rules_alert" "example" {
name = "Rajesh-custom-query"
location = var.resource-group-location
resource_group_name = var.resource-group-name
action {
resource "azurerm_monitor_scheduled_query_rules_alert" "Azure-StorageTableServices-Transactions" {
name = "Azure-StorageTableServices-Transactions"
location = var.location
resource_group_name = var.log_analytics_resource_group_name
action {
resource "azurerm_monitor_scheduled_query_rules_alert" "AzureMySQLPaaSStorage" {
name = "Azure-MySQLPaaS-Storage"
location = var.location
resource_group_name = var.log_analytics_resource_group_name
action {
resource "azurerm_monitor_scheduled_query_rules_alert" "Azure-RedisCache-TotalKeys" {
name = "Azure-RedisCache-TotalKeys"
location = var.location
resource_group_name = var.log_analytics_resource_group_name
action {
resource "azurerm_monitor_scheduled_query_rules_alert" "Azure-MariaDBPaaS-Storage" {
name = "Azure-MariaDBPaaS-Storage"
location = var.location
resource_group_name = var.log_analytics_resource_group_name
action {
Parameters
-
authorized_resource_ids
optional - set of string -
data_source_id
required - string -
description
optional - string -
enabled
optional - bool -
frequency
required - number -
id
optional computed - string -
location
required - string -
name
required - string -
query
required - string -
query_type
optional - string -
resource_group_name
required - string -
severity
optional - number -
tags
optional - map from string to string -
throttling
optional - number -
time_window
required - number -
action
list block-
action_group
required - set of string -
custom_webhook_payload
optional computed - string -
email_subject
optional - string
-
-
timeouts
single block -
trigger
list block-
operator
required - string -
threshold
required - number -
metric_trigger
list block-
metric_column
required - string -
metric_trigger_type
required - string -
operator
required - string -
threshold
required - number
-
-
Explanation in Terraform Registry
Manages an AlertingAction Scheduled Query Rules resource 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/scheduledQueryRules (Azure Resource Manager)
The scheduledQueryRules in Microsoft.Insights can be configured in Azure Resource Manager with the resource name Microsoft.Insights/scheduledQueryRules
. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
"type": "Microsoft.Insights/scheduledQueryRules",
"apiVersion": "2018-04-16",
"location": "[parameters('location')]",
"name": "[ClientName]-AzureVM-CPU-Critical",
"properties": {
"description": "CPU is above 90% for listed VMs",
"type":"Microsoft.Insights/scheduledQueryRules",
"name":"Error and Critical Events",
"apiVersion": "2018-04-16",
"location": "[parameters('WorkspaceLocation')]",
"properties":{
"description": "Error and Critical Events",
"type": "Microsoft.Insights/scheduledQueryRules",
"name": "Exceptions",
"apiVersion": "2018-04-16",
"location": "[variables('northEuropeLocation')]",
"tags": {
"[concat('hidden-link:/subscriptions/a7b6f428-0ed2-4721-9548-d17c361d9b77/resourcegroups/', parameters('appName'), '/providers/microsoft.insights/components/', variables('insights'))]": "Resource"
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"scheduledqueryrules_name": {
"type": "Microsoft.Insights/scheduledQueryRules",
"apiVersion": "2018-04-16",
"location": "[resourceGroup().location]",
"tags" : {
"EnvironmentName": "[parameters('environmentName')]",
"Branch":"[parameters('branch')]",
"type": "Microsoft.Insights/scheduledQueryRules"
},
{
"id": "/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/microsoft.insights/scheduledQueryRules/logalertfoo",
"location": "West US",
"name": "logalertfoo",
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"infrastructure": {
"type": "Microsoft.Insights/scheduledQueryRules",
"location": "West US",
"tags": {
"hidden-link:/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/microsoft.insights/components/sampleAI": "Resource"
},
"properties": {
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"scheduledqueryrules_Metrics_name": {
"type": "Microsoft.Insights/scheduledQueryRules",
"location": "West US",
"tags": { },
"properties": {
"description": "log alert description",
"enabled": "false",
Frequently asked questions
What is Azure Monitor Scheduled Query Rules Alert?
Azure Monitor Scheduled Query Rules 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 Scheduled Query Rules Alert?
For Terraform, the AlanCLo/play_terraform, DanielPHobbs/DTEK-Terraform and DanielPHobbs/DTEK-Terraform source code examples are useful. See the Terraform Example section for further details.
For Azure Resource Manager, the swaranjalidhoble/1-ARM-Template-LogAnalytics-Query-Based-Alerts, DanielOrneling/BlogSamples and psfinaki/CheckYourCzech source code examples are useful. See the Azure Resource Manager Example section for further details.