Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/ms.insights.scheduledqueryrules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ jobs:
- name: 'Using test file [${{ matrix.moduleTestFilePaths }}]'
uses: ./.github/actions/templates/validateModuleDeployment
with:
templateFilePath: '${{ env.modulePath }}/deploy.bicep'
parameterFilePath: '${{ env.modulePath }}/${{ matrix.moduleTestFilePaths }}'
templateFilePath: '${{ env.modulePath }}/${{ matrix.moduleTestFilePaths }}'
location: '${{ env.location }}'
resourceGroupName: '${{ env.resourceGroupName }}'
subscriptionId: '${{ secrets.ARM_SUBSCRIPTION_ID }}'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@description('Optional. The location to deploy to.')
param location string = resourceGroup().location

@description('Required. The name of the Managed Identity to create.')
param managedIdentityName string

@description('Required. The name of the Log Analytics Workspace to create.')
param logAnalyticsWorkspaceName string

resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' = {
name: managedIdentityName
location: location
}

resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2021-06-01' = {
name: logAnalyticsWorkspaceName
location: location
}

@description('The principal ID of the created Managed Identity.')
output managedIdentityPrincipalId string = managedIdentity.properties.principalId

@description('The resource ID of the created Log Analytics Workspace.')
output logAnalyticsWorkspaceResourceId string = logAnalyticsWorkspace.id
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
targetScope = 'subscription'

// ========== //
// Parameters //
// ========== //
@description('Optional. The name of the resource group to deploy for testing purposes.')
@maxLength(90)
param resourceGroupName string = 'ms.insights.scheduledqueryrules-${serviceShort}-rg'

@description('Optional. The location to deploy resources to.')
param location string = deployment().location

@description('Optional. A short identifier for the kind of deployment. Should be kept short to not run into resource-name length-constraints.')
param serviceShort string = 'isqrcom'

// =========== //
// Deployments //
// =========== //

// General resources
// =================
resource resourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' = {
name: resourceGroupName
location: location
}

module resourceGroupResources 'dependencies.bicep' = {
scope: resourceGroup
name: '${uniqueString(deployment().name, location)}-paramNested'
params: {
managedIdentityName: 'dep-<<namePrefix>>-msi-${serviceShort}'
logAnalyticsWorkspaceName: 'dep-<<namePrefix>>-law-${serviceShort}'
}
}

// ============== //
// Test Execution //
// ============== //

module testDeployment '../../deploy.bicep' = {
scope: resourceGroup
name: '${uniqueString(deployment().name)}-test-${serviceShort}'
params: {
name: '<<namePrefix>>${serviceShort}001'
alertDescription: 'My sample Alert'
autoMitigate: false
criterias: {
allOf: [
{
dimensions: [
{
name: 'Computer'
operator: 'Include'
values: [
'*'
]
}
{
name: 'InstanceName'
operator: 'Include'
values: [
'*'
]
}
]
metricMeasureColumn: 'AggregatedValue'
operator: 'GreaterThan'
query: 'Perf | where ObjectName == "LogicalDisk" | where CounterName == "% Free Space" | where InstanceName <> "HarddiskVolume1" and InstanceName <> "_Total" | summarize AggregatedValue = min(CounterValue) by Computer, InstanceName, bin(TimeGenerated,5m)'
threshold: 0
timeAggregation: 'Average'
}
]
}
evaluationFrequency: 'PT5M'
queryTimeRange: 'PT5M'
roleAssignments: [
{
principalIds: [
resourceGroupResources.outputs.managedIdentityPrincipalId
]
roleDefinitionIdOrName: 'Reader'
}
]
scopes: [
resourceGroupResources.outputs.logAnalyticsWorkspaceResourceId
]
suppressForMinutes: 'PT5M'
windowSize: 'PT5M'
}
}

This file was deleted.

7 changes: 3 additions & 4 deletions modules/Microsoft.Insights/scheduledQueryRules/deploy.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ param targetResourceTypes array = []
param roleAssignments array = []

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

@description('Optional. 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.')
@allowed([
Expand All @@ -54,8 +54,8 @@ param windowSize string = ''
@description('Optional. Actions to invoke when the alert fires.')
param actions array = []

@description('Optional. The rule criteria that defines the conditions of the scheduled query rule.')
param criterias object = {}
@description('Required. The rule criteria that defines the conditions of the scheduled query rule.')
param criterias object

@description('Optional. 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.')
param suppressForMinutes string = ''
Expand Down Expand Up @@ -90,7 +90,6 @@ resource queryRule 'Microsoft.Insights/scheduledQueryRules@2021-02-01-preview' =
}
autoMitigate: (kind == 'LogAlert') ? autoMitigate : null
criteria: criterias

description: alertDescription
displayName: name
enabled: enabled
Expand Down
58 changes: 29 additions & 29 deletions modules/Microsoft.Insights/scheduledQueryRules/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ This module deploys a scheduled query rule.

| Parameter Name | Type | Description |
| :-- | :-- | :-- |
| `criterias` | object | The rule criteria that defines the conditions of the scheduled query rule. |
| `name` | string | The name of the Alert. |
| `scopes` | array | The list of resource IDs that this scheduled query rule is scoped to. |

Expand All @@ -33,7 +34,6 @@ This module deploys a scheduled query rule.
| `actions` | array | `[]` | | Actions to invoke when the alert fires. |
| `alertDescription` | string | `''` | | The description of the scheduled query rule. |
| `autoMitigate` | bool | `True` | | The flag that indicates whether the alert should be automatically resolved or not. Relevant only for rules of the kind LogAlert. |
| `criterias` | object | `{object}` | | The rule criteria that defines the conditions of the scheduled query rule. |
| `enabled` | bool | `True` | | The flag which indicates whether this scheduled query rule is enabled. |
| `enableDefaultTelemetry` | bool | `True` | | Enable telemetry via the Customer Usage Attribution ID (GUID). |
| `evaluationFrequency` | string | `''` | | How often the scheduled query rule is evaluated represented in ISO 8601 duration format. Relevant and required only for rules of the kind LogAlert. |
Expand Down Expand Up @@ -169,21 +169,17 @@ The following module usage examples are retrieved from the content of the files

>**Note**: Each example lists all the required parameters first, followed by the rest - each in alphabetical order.

<h3>Example 1: Parameters</h3>
<h3>Example 1: Common</h3>

<details>

<summary>via Bicep module</summary>

```bicep
module scheduledQueryRules './Microsoft.Insights/scheduledQueryRules/deploy.bicep' = {
name: '${uniqueString(deployment().name)}-ScheduledQueryRules'
name: '${uniqueString(deployment().name)}-test-isqrcom'
params: {
// Required parameters
name: 'myAlert01'
// Non-required parameters
alertDescription: 'My sample Alert'
autoMitigate: false
criterias: {
allOf: [
{
Expand All @@ -205,25 +201,29 @@ module scheduledQueryRules './Microsoft.Insights/scheduledQueryRules/deploy.bice
]
metricMeasureColumn: 'AggregatedValue'
operator: 'GreaterThan'
query: 'Perf | where ObjectName == \'LogicalDisk\' | where CounterName == \'% Free Space\' | where InstanceName <> \'HarddiskVolume1\' and InstanceName <> \'_Total\' | summarize AggregatedValue = min(CounterValue) by Computer InstanceName bin(TimeGenerated5m)'
query: '<query>'
threshold: 0
timeAggregation: 'Average'
}
]
}
name: '<<namePrefix>>isqrcom001'
scopes: [
'<logAnalyticsWorkspaceResourceId>'
]
// Non-required parameters
alertDescription: 'My sample Alert'
autoMitigate: false
evaluationFrequency: 'PT5M'
queryTimeRange: 'PT5M'
roleAssignments: [
{
principalIds: [
'<<deploymentSpId>>'
'<managedIdentityPrincipalId>'
]
roleDefinitionIdOrName: 'Reader'
}
]
scopes: [
'/subscriptions/<<subscriptionId>>/resourcegroups/validation-rg/providers/microsoft.operationalinsights/workspaces/adp-<<namePrefix>>-az-law-x-001'
]
suppressForMinutes: 'PT5M'
windowSize: 'PT5M'
}
Expand All @@ -243,16 +243,6 @@ module scheduledQueryRules './Microsoft.Insights/scheduledQueryRules/deploy.bice
"contentVersion": "1.0.0.0",
"parameters": {
// Required parameters
"name": {
"value": "myAlert01"
},
// Non-required parameters
"alertDescription": {
"value": "My sample Alert"
},
"autoMitigate": {
"value": false
},
"criterias": {
"value": {
"allOf": [
Expand All @@ -275,13 +265,28 @@ module scheduledQueryRules './Microsoft.Insights/scheduledQueryRules/deploy.bice
],
"metricMeasureColumn": "AggregatedValue",
"operator": "GreaterThan",
"query": "Perf | where ObjectName == \"LogicalDisk\" | where CounterName == \"% Free Space\" | where InstanceName <> \"HarddiskVolume1\" and InstanceName <> \"_Total\" | summarize AggregatedValue = min(CounterValue) by Computer, InstanceName, bin(TimeGenerated,5m)",
"query": "<query>",
"threshold": 0,
"timeAggregation": "Average"
}
]
}
},
"name": {
"value": "<<namePrefix>>isqrcom001"
},
"scopes": {
"value": [
"<logAnalyticsWorkspaceResourceId>"
]
},
// Non-required parameters
"alertDescription": {
"value": "My sample Alert"
},
"autoMitigate": {
"value": false
},
"evaluationFrequency": {
"value": "PT5M"
},
Expand All @@ -292,17 +297,12 @@ module scheduledQueryRules './Microsoft.Insights/scheduledQueryRules/deploy.bice
"value": [
{
"principalIds": [
"<<deploymentSpId>>"
"<managedIdentityPrincipalId>"
],
"roleDefinitionIdOrName": "Reader"
}
]
},
"scopes": {
"value": [
"/subscriptions/<<subscriptionId>>/resourcegroups/validation-rg/providers/microsoft.operationalinsights/workspaces/adp-<<namePrefix>>-az-law-x-001"
]
},
"suppressForMinutes": {
"value": "PT5M"
},
Expand Down