Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Remarks
For guidance on deploying monitoring solutions, see Create monitoring resources by using Bicep.
Bicep resource definition
The scheduledQueryRules resource type can be deployed with operations that target:
- Resource groups - See resource group deployment commands
For a list of changed properties in each API version, see change log.
Resource format
To create a Microsoft.Insights/scheduledQueryRules resource, add the following Bicep to your template.
resource symbolicname 'Microsoft.Insights/scheduledQueryRules@2018-04-16' = {
location: 'string'
name: 'string'
properties: {
action: {
odata.type: 'string'
// For remaining properties, see Action objects
}
autoMitigate: bool
description: 'string'
displayName: 'string'
enabled: 'string'
schedule: {
frequencyInMinutes: int
timeWindowInMinutes: int
}
source: {
authorizedResources: [
'string'
]
dataSourceId: 'string'
query: 'string'
queryType: 'string'
}
}
tags: {
{customized property}: 'string'
}
}
Action objects
Set the odata.type property to specify the type of object.
For Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.AlertingAction, use:
{
aznsAction: {
actionGroup: [
'string'
]
customWebhookPayload: 'string'
emailSubject: 'string'
}
odata.type: 'Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.AlertingAction'
severity: 'string'
throttlingInMin: int
trigger: {
metricTrigger: {
metricColumn: 'string'
metricTriggerType: 'string'
threshold: int
thresholdOperator: 'string'
}
threshold: int
thresholdOperator: 'string'
}
}
For Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.LogToMetricAction, use:
{
criteria: [
{
dimensions: [
{
name: 'string'
operator: 'string'
values: [
'string'
]
}
]
metricName: 'string'
}
]
odata.type: 'Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.LogToMetricAction'
}
Property Values
Microsoft.Insights/scheduledQueryRules
| Name | Description | Value |
|---|---|---|
| location | Resource location | string (required) |
| name | The resource name | string (required) |
| properties | The rule properties of the resource. | LogSearchRule (required) |
| tags | Resource tags | Dictionary of tag names and values. See Tags in templates |
Action
| Name | Description | Value |
|---|---|---|
| odata.type | Set to 'Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.AlertingAction' for type AlertingAction. Set to 'Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.LogToMetricAction' for type LogToMetricAction. | 'Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.AlertingAction' 'Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.LogToMetricAction' (required) |
AlertingAction
| Name | Description | Value |
|---|---|---|
| aznsAction | Azure action group reference. | AzNsActionGroup |
| odata.type | Specifies the action. Supported values - AlertingAction, LogToMetricAction | 'Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.AlertingAction' (required) |
| severity | Severity of the alert | '0' '1' '2' '3' '4' (required) |
| throttlingInMin | time (in minutes) for which Alerts should be throttled or suppressed. | int |
| trigger | The trigger condition that results in the alert rule being. | TriggerCondition (required) |
AzNsActionGroup
| Name | Description | Value |
|---|---|---|
| actionGroup | Azure Action Group reference. | string[] |
| customWebhookPayload | Custom payload to be sent for all webhook URI in Azure action group | string |
| emailSubject | Custom subject override for all email ids in Azure action group | string |
Criteria
| Name | Description | Value |
|---|---|---|
| dimensions | List of Dimensions for creating metric | Dimension[] |
| metricName | Name of the metric | string (required) |
Dimension
| Name | Description | Value |
|---|---|---|
| name | Name of the dimension | string (required) |
| operator | Operator for dimension values | 'Include' (required) |
| values | List of dimension values | string[] (required) |
LogMetricTrigger
| Name | Description | Value |
|---|---|---|
| metricColumn | Evaluation of metric on a particular column | string |
| metricTriggerType | Metric Trigger Type - 'Consecutive' or 'Total' | 'Consecutive' 'Total' |
| threshold | The threshold of the metric trigger. | int |
| thresholdOperator | Evaluation operation for Metric -'GreaterThan' or 'LessThan' or 'Equal'. | 'Equal' 'GreaterThan' 'GreaterThanOrEqual' 'LessThan' 'LessThanOrEqual' |
LogSearchRule
| Name | Description | Value |
|---|---|---|
| action | Action needs to be taken on rule execution. | Action (required) |
| autoMitigate | The flag that indicates whether the alert should be automatically resolved or not. The default is false. | bool |
| description | The description of the Log Search rule. | string |
| displayName | The display name of the alert rule | string |
| enabled | The flag which indicates whether the Log Search rule is enabled. Value should be true or false | 'false' 'true' |
| schedule | Schedule (Frequency, Time Window) for rule. Required for action type - AlertingAction | Schedule |
| source | Data Source against which rule will Query Data | Source (required) |
LogToMetricAction
| Name | Description | Value |
|---|---|---|
| criteria | Criteria of Metric | Criteria[] (required) |
| odata.type | Specifies the action. Supported values - AlertingAction, LogToMetricAction | 'Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.LogToMetricAction' (required) |
ResourceTags
| Name | Description | Value |
|---|
Schedule
| Name | Description | Value |
|---|---|---|
| frequencyInMinutes | frequency (in minutes) at which rule condition should be evaluated. | int (required) |
| timeWindowInMinutes | Time window for which data needs to be fetched for query (should be greater than or equal to frequencyInMinutes). | int (required) |
Source
| Name | Description | Value |
|---|---|---|
| authorizedResources | List of Resource referred into query | string[] |
| dataSourceId | The resource uri over which log search query is to be run. | string (required) |
| query | Log search query. Required for action type - AlertingAction | string |
| queryType | Set value to 'ResultCount' . | 'ResultCount' |
TriggerCondition
| Name | Description | Value |
|---|---|---|
| metricTrigger | Trigger condition for metric query rule | LogMetricTrigger |
| threshold | Result or count threshold based on which rule should be triggered. | int (required) |
| thresholdOperator | Evaluation operation for rule - 'GreaterThan' or 'LessThan. | 'Equal' 'GreaterThan' 'GreaterThanOrEqual' 'LessThan' 'LessThanOrEqual' (required) |
Usage Examples
Bicep Samples
A basic example of deploying AlertingAction Scheduled Query Rules resource within Azure Monitor.
param resourceName string = 'acctest0001'
param location string = 'westeurope'
resource component 'Microsoft.Insights/components@2020-02-02' = {
name: resourceName
location: location
kind: 'web'
properties: {
Application_Type: 'web'
DisableIpMasking: false
DisableLocalAuth: false
ForceCustomerStorageForProfiler: false
RetentionInDays: 90
SamplingPercentage: 100
publicNetworkAccessForIngestion: 'Enabled'
publicNetworkAccessForQuery: 'Enabled'
}
}
resource scheduledQueryRule 'Microsoft.Insights/scheduledQueryRules@2021-08-01' = {
name: resourceName
location: location
kind: 'LogAlert'
properties: {
autoMitigate: false
checkWorkspaceAlertsStorageConfigured: false
criteria: {
allOf: [
{
operator: 'Equal'
query: ''' requests
| summarize CountByCountry=count() by client_CountryOrRegion
'''
threshold: 5
timeAggregation: 'Count'
}
]
}
enabled: true
evaluationFrequency: 'PT5M'
scopes: [
component.id
]
severity: 3
skipQueryValidation: false
windowSize: 'PT5M'
}
}
Azure Verified Modules
The following Azure Verified Modules can be used to deploy this resource type.
| Module | Description |
|---|---|
| Scheduled Query Rule | AVM Resource Module for Scheduled Query Rule |
ARM template resource definition
The scheduledQueryRules resource type can be deployed with operations that target:
- Resource groups - See resource group deployment commands
For a list of changed properties in each API version, see change log.
Resource format
To create a Microsoft.Insights/scheduledQueryRules resource, add the following JSON to your template.
{
"type": "Microsoft.Insights/scheduledQueryRules",
"apiVersion": "2018-04-16",
"name": "string",
"location": "string",
"properties": {
"action": {
"odata.type": "string"
// For remaining properties, see Action objects
},
"autoMitigate": "bool",
"description": "string",
"displayName": "string",
"enabled": "string",
"schedule": {
"frequencyInMinutes": "int",
"timeWindowInMinutes": "int"
},
"source": {
"authorizedResources": [ "string" ],
"dataSourceId": "string",
"query": "string",
"queryType": "string"
}
},
"tags": {
"{customized property}": "string"
}
}
Action objects
Set the odata.type property to specify the type of object.
For Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.AlertingAction, use:
{
"aznsAction": {
"actionGroup": [ "string" ],
"customWebhookPayload": "string",
"emailSubject": "string"
},
"odata.type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.AlertingAction",
"severity": "string",
"throttlingInMin": "int",
"trigger": {
"metricTrigger": {
"metricColumn": "string",
"metricTriggerType": "string",
"threshold": "int",
"thresholdOperator": "string"
},
"threshold": "int",
"thresholdOperator": "string"
}
}
For Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.LogToMetricAction, use:
{
"criteria": [
{
"dimensions": [
{
"name": "string",
"operator": "string",
"values": [ "string" ]
}
],
"metricName": "string"
}
],
"odata.type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.LogToMetricAction"
}
Property Values
Microsoft.Insights/scheduledQueryRules
| Name | Description | Value |
|---|---|---|
| apiVersion | The api version | '2018-04-16' |
| location | Resource location | string (required) |
| name | The resource name | string (required) |
| properties | The rule properties of the resource. | LogSearchRule (required) |
| tags | Resource tags | Dictionary of tag names and values. See Tags in templates |
| type | The resource type | 'Microsoft.Insights/scheduledQueryRules' |
Action
| Name | Description | Value |
|---|---|---|
| odata.type | Set to 'Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.AlertingAction' for type AlertingAction. Set to 'Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.LogToMetricAction' for type LogToMetricAction. | 'Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.AlertingAction' 'Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.LogToMetricAction' (required) |
AlertingAction
| Name | Description | Value |
|---|---|---|
| aznsAction | Azure action group reference. | AzNsActionGroup |
| odata.type | Specifies the action. Supported values - AlertingAction, LogToMetricAction | 'Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.AlertingAction' (required) |
| severity | Severity of the alert | '0' '1' '2' '3' '4' (required) |
| throttlingInMin | time (in minutes) for which Alerts should be throttled or suppressed. | int |
| trigger | The trigger condition that results in the alert rule being. | TriggerCondition (required) |
AzNsActionGroup
| Name | Description | Value |
|---|---|---|
| actionGroup | Azure Action Group reference. | string[] |
| customWebhookPayload | Custom payload to be sent for all webhook URI in Azure action group | string |
| emailSubject | Custom subject override for all email ids in Azure action group | string |
Criteria
| Name | Description | Value |
|---|---|---|
| dimensions | List of Dimensions for creating metric | Dimension[] |
| metricName | Name of the metric | string (required) |
Dimension
| Name | Description | Value |
|---|---|---|
| name | Name of the dimension | string (required) |
| operator | Operator for dimension values | 'Include' (required) |
| values | List of dimension values | string[] (required) |
LogMetricTrigger
| Name | Description | Value |
|---|---|---|
| metricColumn | Evaluation of metric on a particular column | string |
| metricTriggerType | Metric Trigger Type - 'Consecutive' or 'Total' | 'Consecutive' 'Total' |
| threshold | The threshold of the metric trigger. | int |
| thresholdOperator | Evaluation operation for Metric -'GreaterThan' or 'LessThan' or 'Equal'. | 'Equal' 'GreaterThan' 'GreaterThanOrEqual' 'LessThan' 'LessThanOrEqual' |
LogSearchRule
| Name | Description | Value |
|---|---|---|
| action | Action needs to be taken on rule execution. | Action (required) |
| autoMitigate | The flag that indicates whether the alert should be automatically resolved or not. The default is false. | bool |
| description | The description of the Log Search rule. | string |
| displayName | The display name of the alert rule | string |
| enabled | The flag which indicates whether the Log Search rule is enabled. Value should be true or false | 'false' 'true' |
| schedule | Schedule (Frequency, Time Window) for rule. Required for action type - AlertingAction | Schedule |
| source | Data Source against which rule will Query Data | Source (required) |
LogToMetricAction
| Name | Description | Value |
|---|---|---|
| criteria | Criteria of Metric | Criteria[] (required) |
| odata.type | Specifies the action. Supported values - AlertingAction, LogToMetricAction | 'Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.LogToMetricAction' (required) |
ResourceTags
| Name | Description | Value |
|---|
Schedule
| Name | Description | Value |
|---|---|---|
| frequencyInMinutes | frequency (in minutes) at which rule condition should be evaluated. | int (required) |
| timeWindowInMinutes | Time window for which data needs to be fetched for query (should be greater than or equal to frequencyInMinutes). | int (required) |
Source
| Name | Description | Value |
|---|---|---|
| authorizedResources | List of Resource referred into query | string[] |
| dataSourceId | The resource uri over which log search query is to be run. | string (required) |
| query | Log search query. Required for action type - AlertingAction | string |
| queryType | Set value to 'ResultCount' . | 'ResultCount' |
TriggerCondition
| Name | Description | Value |
|---|---|---|
| metricTrigger | Trigger condition for metric query rule | LogMetricTrigger |
| threshold | Result or count threshold based on which rule should be triggered. | int (required) |
| thresholdOperator | Evaluation operation for rule - 'GreaterThan' or 'LessThan. | 'Equal' 'GreaterThan' 'GreaterThanOrEqual' 'LessThan' 'LessThanOrEqual' (required) |
Usage Examples
Azure Quickstart Templates
The following Azure Quickstart templates deploy this resource type.
| Template | Description |
|---|---|
| Create alert rule for azure business continuity items |
This templates creates an alert rule and user assigned MSI. It also assigns the MSI reader access to the subscription so that the alert rule has access to query the required protected items and latest recovery point details. |
Terraform (AzAPI provider) resource definition
The scheduledQueryRules resource type can be deployed with operations that target:
- Resource groups
For a list of changed properties in each API version, see change log.
Resource format
To create a Microsoft.Insights/scheduledQueryRules resource, add the following Terraform to your template.
resource "azapi_resource" "symbolicname" {
type = "Microsoft.Insights/scheduledQueryRules@2018-04-16"
name = "string"
parent_id = "string"
location = "string"
tags = {
{customized property} = "string"
}
body = {
properties = {
action = {
odata.type = "string"
// For remaining properties, see Action objects
}
autoMitigate = bool
description = "string"
displayName = "string"
enabled = "string"
schedule = {
frequencyInMinutes = int
timeWindowInMinutes = int
}
source = {
authorizedResources = [
"string"
]
dataSourceId = "string"
query = "string"
queryType = "string"
}
}
}
}
Action objects
Set the odata.type property to specify the type of object.
For Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.AlertingAction, use:
{
aznsAction = {
actionGroup = [
"string"
]
customWebhookPayload = "string"
emailSubject = "string"
}
odata.type = "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.AlertingAction"
severity = "string"
throttlingInMin = int
trigger = {
metricTrigger = {
metricColumn = "string"
metricTriggerType = "string"
threshold = int
thresholdOperator = "string"
}
threshold = int
thresholdOperator = "string"
}
}
For Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.LogToMetricAction, use:
{
criteria = [
{
dimensions = [
{
name = "string"
operator = "string"
values = [
"string"
]
}
]
metricName = "string"
}
]
odata.type = "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.LogToMetricAction"
}
Property Values
Microsoft.Insights/scheduledQueryRules
| Name | Description | Value |
|---|---|---|
| location | Resource location | string (required) |
| name | The resource name | string (required) |
| properties | The rule properties of the resource. | LogSearchRule (required) |
| tags | Resource tags | Dictionary of tag names and values. |
| type | The resource type | "Microsoft.Insights/scheduledQueryRules@2018-04-16" |
Action
| Name | Description | Value |
|---|---|---|
| odata.type | Set to 'Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.AlertingAction' for type AlertingAction. Set to 'Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.LogToMetricAction' for type LogToMetricAction. | 'Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.AlertingAction' 'Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.LogToMetricAction' (required) |
AlertingAction
| Name | Description | Value |
|---|---|---|
| aznsAction | Azure action group reference. | AzNsActionGroup |
| odata.type | Specifies the action. Supported values - AlertingAction, LogToMetricAction | 'Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.AlertingAction' (required) |
| severity | Severity of the alert | '0' '1' '2' '3' '4' (required) |
| throttlingInMin | time (in minutes) for which Alerts should be throttled or suppressed. | int |
| trigger | The trigger condition that results in the alert rule being. | TriggerCondition (required) |
AzNsActionGroup
| Name | Description | Value |
|---|---|---|
| actionGroup | Azure Action Group reference. | string[] |
| customWebhookPayload | Custom payload to be sent for all webhook URI in Azure action group | string |
| emailSubject | Custom subject override for all email ids in Azure action group | string |
Criteria
| Name | Description | Value |
|---|---|---|
| dimensions | List of Dimensions for creating metric | Dimension[] |
| metricName | Name of the metric | string (required) |
Dimension
| Name | Description | Value |
|---|---|---|
| name | Name of the dimension | string (required) |
| operator | Operator for dimension values | 'Include' (required) |
| values | List of dimension values | string[] (required) |
LogMetricTrigger
| Name | Description | Value |
|---|---|---|
| metricColumn | Evaluation of metric on a particular column | string |
| metricTriggerType | Metric Trigger Type - 'Consecutive' or 'Total' | 'Consecutive' 'Total' |
| threshold | The threshold of the metric trigger. | int |
| thresholdOperator | Evaluation operation for Metric -'GreaterThan' or 'LessThan' or 'Equal'. | 'Equal' 'GreaterThan' 'GreaterThanOrEqual' 'LessThan' 'LessThanOrEqual' |
LogSearchRule
| Name | Description | Value |
|---|---|---|
| action | Action needs to be taken on rule execution. | Action (required) |
| autoMitigate | The flag that indicates whether the alert should be automatically resolved or not. The default is false. | bool |
| description | The description of the Log Search rule. | string |
| displayName | The display name of the alert rule | string |
| enabled | The flag which indicates whether the Log Search rule is enabled. Value should be true or false | 'false' 'true' |
| schedule | Schedule (Frequency, Time Window) for rule. Required for action type - AlertingAction | Schedule |
| source | Data Source against which rule will Query Data | Source (required) |
LogToMetricAction
| Name | Description | Value |
|---|---|---|
| criteria | Criteria of Metric | Criteria[] (required) |
| odata.type | Specifies the action. Supported values - AlertingAction, LogToMetricAction | 'Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.LogToMetricAction' (required) |
ResourceTags
| Name | Description | Value |
|---|
Schedule
| Name | Description | Value |
|---|---|---|
| frequencyInMinutes | frequency (in minutes) at which rule condition should be evaluated. | int (required) |
| timeWindowInMinutes | Time window for which data needs to be fetched for query (should be greater than or equal to frequencyInMinutes). | int (required) |
Source
| Name | Description | Value |
|---|---|---|
| authorizedResources | List of Resource referred into query | string[] |
| dataSourceId | The resource uri over which log search query is to be run. | string (required) |
| query | Log search query. Required for action type - AlertingAction | string |
| queryType | Set value to 'ResultCount' . | 'ResultCount' |
TriggerCondition
| Name | Description | Value |
|---|---|---|
| metricTrigger | Trigger condition for metric query rule | LogMetricTrigger |
| threshold | Result or count threshold based on which rule should be triggered. | int (required) |
| thresholdOperator | Evaluation operation for rule - 'GreaterThan' or 'LessThan. | 'Equal' 'GreaterThan' 'GreaterThanOrEqual' 'LessThan' 'LessThanOrEqual' (required) |
Usage Examples
Terraform Samples
A basic example of deploying AlertingAction Scheduled Query Rules resource within Azure Monitor.
terraform {
required_providers {
azapi = {
source = "Azure/azapi"
}
}
}
provider "azapi" {
skip_provider_registration = false
}
variable "resource_name" {
type = string
default = "acctest0001"
}
variable "location" {
type = string
default = "westeurope"
}
resource "azapi_resource" "resourceGroup" {
type = "Microsoft.Resources/resourceGroups@2020-06-01"
name = var.resource_name
location = var.location
}
resource "azapi_resource" "component" {
type = "Microsoft.Insights/components@2020-02-02"
parent_id = azapi_resource.resourceGroup.id
name = var.resource_name
location = var.location
body = {
kind = "web"
properties = {
Application_Type = "web"
DisableIpMasking = false
DisableLocalAuth = false
ForceCustomerStorageForProfiler = false
RetentionInDays = 90
SamplingPercentage = 100
publicNetworkAccessForIngestion = "Enabled"
publicNetworkAccessForQuery = "Enabled"
}
}
schema_validation_enabled = false
response_export_values = ["*"]
}
resource "azapi_resource" "scheduledQueryRule" {
type = "Microsoft.Insights/scheduledQueryRules@2021-08-01"
parent_id = azapi_resource.resourceGroup.id
name = var.resource_name
location = var.location
body = {
kind = "LogAlert"
properties = {
autoMitigate = false
checkWorkspaceAlertsStorageConfigured = false
criteria = {
allOf = [
{
dimensions = null
operator = "Equal"
query = " requests\n| summarize CountByCountry=count() by client_CountryOrRegion\n"
threshold = 5
timeAggregation = "Count"
},
]
}
enabled = true
evaluationFrequency = "PT5M"
scopes = [
azapi_resource.component.id,
]
severity = 3
skipQueryValidation = false
targetResourceTypes = null
windowSize = "PT5M"
}
}
schema_validation_enabled = false
response_export_values = ["*"]
}
A basic example of deploying AlertingAction Scheduled Query Rules resource within Azure Monitor.
terraform {
required_providers {
azapi = {
source = "Azure/azapi"
}
}
}
provider "azapi" {
skip_provider_registration = false
}
variable "resource_name" {
type = string
default = "acctest0001"
}
variable "location" {
type = string
default = "westeurope"
}
resource "azapi_resource" "resourceGroup" {
type = "Microsoft.Resources/resourceGroups@2020-06-01"
name = var.resource_name
location = var.location
}
resource "azapi_resource" "component" {
type = "Microsoft.Insights/components@2020-02-02"
parent_id = azapi_resource.resourceGroup.id
name = var.resource_name
location = var.location
body = {
kind = "web"
properties = {
Application_Type = "web"
DisableIpMasking = false
DisableLocalAuth = false
ForceCustomerStorageForProfiler = false
RetentionInDays = 90
SamplingPercentage = 100
publicNetworkAccessForIngestion = "Enabled"
publicNetworkAccessForQuery = "Enabled"
}
}
schema_validation_enabled = false
response_export_values = ["*"]
}
resource "azapi_resource" "scheduledQueryRule" {
type = "Microsoft.Insights/scheduledQueryRules@2021-08-01"
parent_id = azapi_resource.resourceGroup.id
name = var.resource_name
location = var.location
body = {
kind = "LogAlert"
properties = {
autoMitigate = false
checkWorkspaceAlertsStorageConfigured = false
criteria = {
allOf = [
{
dimensions = null
operator = "Equal"
query = " requests\n| summarize CountByCountry=count() by client_CountryOrRegion\n"
threshold = 5
timeAggregation = "Count"
},
]
}
enabled = true
evaluationFrequency = "PT5M"
scopes = [
azapi_resource.component.id,
]
severity = 3
skipQueryValidation = false
targetResourceTypes = null
windowSize = "PT5M"
}
}
schema_validation_enabled = false
response_export_values = ["*"]
}