Resource Manager mallexempel för loggfrågor i Azure Monitor
Den här artikeln innehåller exempel på Azure Resource Manager-mallar för att skapa och konfigurera loggfrågor i Azure Monitor. Varje exempel innehåller en mallfil och en parameterfil med exempelvärden som ska tillhandahållas till mallen.
Anteckning
Se Azure Resource Manager-exempel för Azure Monitor för en lista över exempel som är tillgängliga och vägledning om hur du distribuerar dem i din Azure-prenumeration.
Mallreferenser
Enkel loggfråga
I följande exempel läggs en loggfråga till på en Log Analytics-arbetsyta.
Mallfil
@description('The name of the workspace.')
param workspaceName string
@description('The location of the resources.')
param location string = resourceGroup().location
resource workspace 'Microsoft.OperationalInsights/workspaces@2021-12-01-preview' = {
name: workspaceName
location: location
}
resource savedSearch 'Microsoft.OperationalInsights/workspaces/savedSearches@2020-08-01' = {
parent: workspace
name: 'VMSS query'
properties: {
etag: '*'
displayName: 'VMSS Instance Count'
category: 'VMSS'
query: 'Event | where Source == "ServiceFabricNodeBootstrapAgent" | summarize AggregatedValue = count() by Computer'
version: 1
}
}
Parameterfil
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workspaceName": {
"value": "MyWorkspace"
},
"location": {
"value": "eastus"
}
}
}
Loggfråga som en funktion
Följande exempel lägger till en loggfråga som en funktion på en Log Analytics-arbetsyta.
Mallfil
@description('The name of the workspace.')
param workspaceName string
@description('The location of the resources.')
param location string = resourceGroup().location
resource workspace 'Microsoft.OperationalInsights/workspaces@2021-12-01-preview' = {
name: workspaceName
location: location
}
resource savedSearch 'Microsoft.OperationalInsights/workspaces/savedSearches@2020-08-01' = {
parent: workspace
name: 'VMSS query'
properties: {
etag: '*'
displayName: 'VMSS Instance Count'
category: 'VMSS'
query: 'Event | where Source == "ServiceFabricNodeBootstrapAgent" | summarize AggregatedValue = count() by Computer'
version: 1
}
}
Parameterfil
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workspaceName": {
"value": "MyWorkspace"
},
"location": {
"value": "eastus"
}
}
}
Parametriserad funktion
Följande exempel lägger till en loggfråga som en funktion som använder en parameter till en Log Analytics-arbetsyta. En andra loggfråga ingår som använder den parametriserade funktionen.
Anteckning
Resursmallen är för närvarande den enda metoden som kan användas för parametriserade funktioner. Alla loggfrågor kan använda funktionen när den har installerats på arbetsytan.
Mallfil
param workspaceName string
param location string
resource workspace 'Microsoft.OperationalInsights/workspaces@2021-12-01-preview' = {
name: workspaceName
location: location
}
resource parameterizedFunctionSavedSearch 'Microsoft.OperationalInsights/workspaces/savedSearches@2020-08-01' = {
parent: workspace
name: 'Parameterized function'
properties: {
etag: '*'
displayName: 'Unavailable computers function'
category: 'Samples'
functionAlias: 'UnavailableComputers'
functionParameters: 'argSpan: timespan'
query: ' Heartbeat | summarize LastHeartbeat=max(TimeGenerated) by Computer| where LastHeartbeat < ago(argSpan)'
}
}
resource queryUsingFunctionSavedSearch 'Microsoft.OperationalInsights/workspaces/savedSearches@2020-08-01' = {
parent: workspace
name: 'Query using function'
properties: {
etag: '*'
displayName: 'Unavailable computers'
category: 'Samples'
query: 'UnavailableComputers(7days)'
}
}
Parameterfil
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workspaceName": {
"value": "MyWorkspace"
},
"location": {
"value": "eastus"
}
}
}