Share via


Beispiele für Resource Manager-Vorlagen für Protokollabfragen in Azure Monitor

Dieser Artikel enthält Beispiele für Azure Resource Manager-Vorlagen zum Erstellen und Konfigurieren von Protokollabfragen in Azure Monitor. Jedes Beispiel umfasst eine Vorlagendatei und eine Parameterdatei mit Beispielwerten für die Vorlage.

Hinweis

Eine Liste mit verfügbaren Beispielen und Anleitungen zu deren Bereitstellung in Ihrem Azure-Abonnement finden Sie unter Beispiele für Resource Manager-Vorlagen für Azure Monitor.

Vorlagenreferenzen

Einfache Protokollabfrage

Im folgenden Beispiel wird einem Log Analytics-Arbeitsbereich eine Protokollabfrage hinzugefügt.

Vorlagendatei

@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
  }
}

Parameterdatei

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "workspaceName": {
      "value": "MyWorkspace"
    },
    "location": {
      "value": "eastus"
    }
  }
}

Protokollabfrage als Funktion

Im folgenden Beispiel wird einem Log Analytics-Arbeitsbereich eine Protokollabfrage als Funktion hinzugefügt.

Vorlagendatei

@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
  }
}

Parameterdatei

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "workspaceName": {
      "value": "MyWorkspace"
    },
    "location": {
      "value": "eastus"
    }
  }
}

Parametrisierte Funktion

Im folgenden Beispiel wird einem Log Analytics-Arbeitsbereich eine Protokollabfrage als Funktion hinzugefügt, die einen Parameter verwendet. Es wird eine zweite Protokollabfrage eingebunden, in der die parametrisierte Funktion verwendet wird.

Hinweis

Die Ressourcenvorlage ist derzeit die einzige Methode, die für parametrisierte Funktionen verwendet werden kann. Sobald die Funktion im Arbeitsbereich installiert ist, kann sie von jeder Protokollabfrage verwendet werden.

Vorlagendatei

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)'
  }
}

Parameterdatei

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "workspaceName": {
      "value": "MyWorkspace"
    },
    "location": {
      "value": "eastus"
    }
  }
}

Nächste Schritte