Skip to content

Commit

Permalink
feat: add alert display rule and rule resolve configuration; update A…
Browse files Browse the repository at this point in the history
…PI to latest - `avm/res/insights/scheduled-query-rule` (Azure#2710)

Add optional parameters alert display rule and rule resolve
configuration. Updated API to the latest version.

<!--
Added ability to pass an alert display rule.
Updated the API version of the module to the latest version. 
Added ability to supply a rule resolve configuration.

-->
Fixes Azure#2560
Closes Azure#2560

## Pipeline Reference


[![avm.res.insights.scheduled-query-rule](https://github.com/emichellecarter/bicep-registry-modules/actions/workflows/avm.res.insights.scheduled-query-rule.yml/badge.svg)](https://github.com/emichellecarter/bicep-registry-modules/actions/workflows/avm.res.insights.scheduled-query-rule.yml)


## Type of Change

- [ ] Update to CI Environment or utilities (Non-module affecting
changes)
- [ ] Azure Verified Module updates:
- [ ] Bugfix containing backwards-compatible bug fixes, and I have NOT
bumped the MAJOR or MINOR version in `version.json`:
- [] Someone has opened a bug report issue, and I have included "Closes
#{bug_report_issue_number}" in the PR description.
- [ ] The bug was found by the module author, and no one has opened an
issue to report it yet.
- [X] Feature update backwards compatible feature updates, and I have
bumped the MINOR version in `version.json`.
- [ ] Breaking changes and I have bumped the MAJOR version in
`version.json`.
  - [X ] Update to documentation

## Checklist

- [X] I'm sure there are no other open Pull Requests for the same
update/change
- [X] I have run `Set-AVMModule` locally to generate the supporting
module files.
- [X ] My corresponding pipelines / checks run clean and green without
any errors or warnings

---------

Co-authored-by: Michelle Carter <[email protected]>
Co-authored-by: Alexander Sehr <[email protected]>
  • Loading branch information
3 people authored Aug 8, 2024
1 parent 391fdde commit d3b5f12
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 7 deletions.
32 changes: 31 additions & 1 deletion avm/res/insights/scheduled-query-rule/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This module deploys a Scheduled Query Rule.
| Resource Type | API Version |
| :-- | :-- |
| `Microsoft.Authorization/roleAssignments` | [2022-04-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Authorization/2022-04-01/roleAssignments) |
| `Microsoft.Insights/scheduledQueryRules` | [2021-02-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Insights/2021-02-01-preview/scheduledQueryRules) |
| `Microsoft.Insights/scheduledQueryRules` | [2023-03-15-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Insights/2023-03-15-preview/scheduledQueryRules) |

## Usage examples

Expand Down Expand Up @@ -197,6 +197,7 @@ module scheduledQueryRule 'br/public:avm/res/insights/scheduled-query-rule:<vers
]
// Non-required parameters
alertDescription: 'My sample Alert'
alertDisplayName: '<alertDisplayName>'
autoMitigate: false
evaluationFrequency: 'PT5M'
location: '<location>'
Expand All @@ -220,6 +221,10 @@ module scheduledQueryRule 'br/public:avm/res/insights/scheduled-query-rule:<vers
roleDefinitionIdOrName: '<roleDefinitionIdOrName>'
}
]
ruleResolveConfiguration: {
autoResolved: true
timeToResolve: 'PT5M'
}
suppressForMinutes: 'PT5M'
tags: {
Environment: 'Non-Prod'
Expand Down Expand Up @@ -285,6 +290,9 @@ module scheduledQueryRule 'br/public:avm/res/insights/scheduled-query-rule:<vers
"alertDescription": {
"value": "My sample Alert"
},
"alertDisplayName": {
"value": "<alertDisplayName>"
},
"autoMitigate": {
"value": false
},
Expand Down Expand Up @@ -318,6 +326,12 @@ module scheduledQueryRule 'br/public:avm/res/insights/scheduled-query-rule:<vers
}
]
},
"ruleResolveConfiguration": {
"value": {
"autoResolved": true,
"timeToResolve": "PT5M"
}
},
"suppressForMinutes": {
"value": "PT5M"
},
Expand Down Expand Up @@ -509,6 +523,7 @@ module scheduledQueryRule 'br/public:avm/res/insights/scheduled-query-rule:<vers
| :-- | :-- | :-- |
| [`actions`](#parameter-actions) | array | Actions to invoke when the alert fires. |
| [`alertDescription`](#parameter-alertdescription) | string | The description of the scheduled query rule. |
| [`alertDisplayName`](#parameter-alertdisplayname) | string | The display name of the scheduled query rule. |
| [`autoMitigate`](#parameter-automitigate) | bool | The flag that indicates whether the alert should be automatically resolved or not. Relevant only for rules of the kind LogAlert. |
| [`enabled`](#parameter-enabled) | bool | The flag which indicates whether this scheduled query rule is enabled. |
| [`enableTelemetry`](#parameter-enabletelemetry) | bool | Enable/Disable usage telemetry for module. |
Expand All @@ -517,6 +532,7 @@ module scheduledQueryRule 'br/public:avm/res/insights/scheduled-query-rule:<vers
| [`location`](#parameter-location) | string | Location for all resources. |
| [`queryTimeRange`](#parameter-querytimerange) | string | If specified (in ISO 8601 duration format) then overrides the query time range. Relevant only for rules of the kind LogAlert. |
| [`roleAssignments`](#parameter-roleassignments) | array | Array of role assignments to create. |
| [`ruleResolveConfiguration`](#parameter-ruleresolveconfiguration) | object | Defines the configuration for resolving fired alerts. Relevant only for rules of the kind LogAlert. |
| [`severity`](#parameter-severity) | int | Severity of the alert. Should be an integer between [0-4]. Value of 0 is severest. Relevant and required only for rules of the kind LogAlert. |
| [`skipQueryValidation`](#parameter-skipqueryvalidation) | bool | The flag which indicates whether the provided query should be validated or not. Relevant only for rules of the kind LogAlert. |
| [`suppressForMinutes`](#parameter-suppressforminutes) | string | Mute actions for the chosen period of time (in ISO 8601 duration format) after the alert is fired. If set, autoMitigate must be disabled.Relevant only for rules of the kind LogAlert. |
Expand Down Expand Up @@ -568,6 +584,13 @@ The description of the scheduled query rule.
- Type: string
- Default: `''`

### Parameter: `alertDisplayName`

The display name of the scheduled query rule.

- Required: No
- Type: string

### Parameter: `autoMitigate`

The flag that indicates whether the alert should be automatically resolved or not. Relevant only for rules of the kind LogAlert.
Expand Down Expand Up @@ -728,6 +751,13 @@ The principal type of the assigned principal ID.
]
```

### Parameter: `ruleResolveConfiguration`

Defines the configuration for resolving fired alerts. Relevant only for rules of the kind LogAlert.

- Required: No
- Type: object

### Parameter: `severity`

Severity of the alert. Should be an integer between [0-4]. Value of 0 is severest. Relevant and required only for rules of the kind LogAlert.
Expand Down
11 changes: 9 additions & 2 deletions avm/res/insights/scheduled-query-rule/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ param location string = resourceGroup().location
@description('Optional. The description of the scheduled query rule.')
param alertDescription string = ''

@description('Optional. The display name of the scheduled query rule.')
param alertDisplayName string?

@description('Optional. The flag which indicates whether this scheduled query rule is enabled.')
param enabled bool = true

Expand All @@ -36,6 +39,9 @@ param targetResourceTypes array = []
@description('Optional. Array of role assignments to create.')
param roleAssignments roleAssignmentType

@description('Optional. Defines the configuration for resolving fired alerts. Relevant only for rules of the kind LogAlert.')
param ruleResolveConfiguration object?

@description('Required. The list of resource IDs that this scheduled query rule is scoped to.')
param scopes array

Expand Down Expand Up @@ -114,7 +120,7 @@ resource avmTelemetry 'Microsoft.Resources/deployments@2024-03-01' = if (enableT
}
}

resource queryRule 'Microsoft.Insights/scheduledQueryRules@2021-02-01-preview' = {
resource queryRule 'Microsoft.Insights/scheduledQueryRules@2023-03-15-preview' = {
name: name
location: location
tags: tags
Expand All @@ -127,11 +133,12 @@ resource queryRule 'Microsoft.Insights/scheduledQueryRules@2021-02-01-preview' =
autoMitigate: (kind == 'LogAlert') ? autoMitigate : null
criteria: criterias
description: alertDescription
displayName: name
displayName: alertDisplayName ?? name
enabled: enabled
evaluationFrequency: (kind == 'LogAlert' && !empty(evaluationFrequency)) ? evaluationFrequency : null
muteActionsDuration: (kind == 'LogAlert' && !empty(suppressForMinutes)) ? suppressForMinutes : null
overrideQueryTimeRange: (kind == 'LogAlert' && !empty(queryTimeRange)) ? queryTimeRange : null
ruleResolveConfiguration: (kind == 'LogAlert' && !empty(ruleResolveConfiguration)) ? ruleResolveConfiguration : null
scopes: scopes
severity: (kind == 'LogAlert') ? severity : null
skipQueryValidation: (kind == 'LogAlert') ? skipQueryValidation : null
Expand Down
23 changes: 19 additions & 4 deletions avm/res/insights/scheduled-query-rule/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"_generator": {
"name": "bicep",
"version": "0.29.47.4906",
"templateHash": "12034267134047308763"
"templateHash": "17672964122833676180"
},
"name": "Scheduled Query Rules",
"description": "This module deploys a Scheduled Query Rule.",
Expand Down Expand Up @@ -108,6 +108,13 @@
"description": "Optional. The description of the scheduled query rule."
}
},
"alertDisplayName": {
"type": "string",
"nullable": true,
"metadata": {
"description": "Optional. The display name of the scheduled query rule."
}
},
"enabled": {
"type": "bool",
"defaultValue": true,
Expand Down Expand Up @@ -160,6 +167,13 @@
"description": "Optional. Array of role assignments to create."
}
},
"ruleResolveConfiguration": {
"type": "object",
"nullable": true,
"metadata": {
"description": "Optional. Defines the configuration for resolving fired alerts. Relevant only for rules of the kind LogAlert."
}
},
"scopes": {
"type": "array",
"metadata": {
Expand Down Expand Up @@ -268,7 +282,7 @@
},
"queryRule": {
"type": "Microsoft.Insights/scheduledQueryRules",
"apiVersion": "2021-02-01-preview",
"apiVersion": "2023-03-15-preview",
"name": "[parameters('name')]",
"location": "[parameters('location')]",
"tags": "[parameters('tags')]",
Expand All @@ -281,11 +295,12 @@
"autoMitigate": "[if(equals(parameters('kind'), 'LogAlert'), parameters('autoMitigate'), null())]",
"criteria": "[parameters('criterias')]",
"description": "[parameters('alertDescription')]",
"displayName": "[parameters('name')]",
"displayName": "[coalesce(parameters('alertDisplayName'), parameters('name'))]",
"enabled": "[parameters('enabled')]",
"evaluationFrequency": "[if(and(equals(parameters('kind'), 'LogAlert'), not(empty(parameters('evaluationFrequency')))), parameters('evaluationFrequency'), null())]",
"muteActionsDuration": "[if(and(equals(parameters('kind'), 'LogAlert'), not(empty(parameters('suppressForMinutes')))), parameters('suppressForMinutes'), null())]",
"overrideQueryTimeRange": "[if(and(equals(parameters('kind'), 'LogAlert'), not(empty(parameters('queryTimeRange')))), parameters('queryTimeRange'), null())]",
"ruleResolveConfiguration": "[if(and(equals(parameters('kind'), 'LogAlert'), not(empty(parameters('ruleResolveConfiguration')))), parameters('ruleResolveConfiguration'), null())]",
"scopes": "[parameters('scopes')]",
"severity": "[if(equals(parameters('kind'), 'LogAlert'), parameters('severity'), null())]",
"skipQueryValidation": "[if(equals(parameters('kind'), 'LogAlert'), parameters('skipQueryValidation'), null())]",
Expand Down Expand Up @@ -343,7 +358,7 @@
"metadata": {
"description": "The location the resource was deployed into."
},
"value": "[reference('queryRule', '2021-02-01-preview', 'full').location]"
"value": "[reference('queryRule', '2023-03-15-preview', 'full').location]"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ module testDeployment '../../../main.bicep' = [
principalType: 'ServicePrincipal'
}
]
alertDisplayName: '${uniqueString(deployment().name, resourceLocation)}-displayNameTest-${serviceShort}-${iteration}'
ruleResolveConfiguration: {
autoResolved: true
timeToResolve: 'PT5M'
}
scopes: [
nestedDependencies.outputs.logAnalyticsWorkspaceResourceId
]
Expand Down

0 comments on commit d3b5f12

Please sign in to comment.