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

main.tf#L25
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 {
azurerm_monitor_scheduled_query_rules_alert.tf#L24
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 {
AlertingAction%20Scheduled%20Query%20Rule.tf#L23
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 {
main.tf#L1
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 {
main.tf#L1
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 {
query-alerts.tf#L1
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 {
main.tf#L1
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 {
main.tf#L1
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 {
main.tf#L1
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 {
main.tf#L1
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 {

Review your Terraform file for Azure best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

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.

risk-label

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.

Review your Azure Monitor settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

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

azuredeploy.json#L17
      "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",
QueriesAlerts.json#L21
            "type":"Microsoft.Insights/scheduledQueryRules",
            "name":"Error and Critical Events",
            "apiVersion": "2018-04-16",
            "location": "[parameters('WorkspaceLocation')]",
            "properties":{
                "description": "Error and Critical Events",
arm-template.json#L48
      "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"
rule_template.json
{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "scheduledqueryrules_name": {
arm-mon-custom-alerts.json#L90
            "type": "Microsoft.Insights/scheduledQueryRules",
            "apiVersion": "2018-04-16",
            "location": "[resourceGroup().location]",
            "tags" : {
                "EnvironmentName": "[parameters('environmentName')]",
                "Branch":"[parameters('branch')]",
azure.com_monitor-scheduledQueryRule_API_2018-04-16.json#L181
                      "type": "Microsoft.Insights/scheduledQueryRules"
                    },
                    {
                      "id": "/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/microsoft.insights/scheduledQueryRules/logalertfoo",
                      "location": "West US",
                      "name": "logalertfoo",
alertsqlserversdatabases.json
{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "infrastructure": {
listScheduledQueryRules.json#L15
            "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": {
rule_template.json
{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "scheduledqueryrules_Metrics_name": {
listScheduledQueryRules.json#L15
            "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.