Skip to content

azurermMonitorScheduledQueryRulesLog

Manages a LogToMetricAction Scheduled Query Rules resource within Azure Monitor.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
const azurermResourceGroupExample = new azurerm.resourceGroup.ResourceGroup(
  this,
  "example",
  {
    location: "West Europe",
    name: "monitoring-resources",
  }
);
const azurermLogAnalyticsWorkspaceExample =
  new azurerm.logAnalyticsWorkspace.LogAnalyticsWorkspace(this, "example_1", {
    location: azurermResourceGroupExample.location,
    name: "loganalytics",
    resource_group_name: azurermResourceGroupExample.name,
    retention_in_days: 30,
    sku: "PerGB2018",
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermLogAnalyticsWorkspaceExample.overrideLogicalId("example");
const azurermMonitorActionGroupExample =
  new azurerm.monitorActionGroup.MonitorActionGroup(this, "example_2", {
    name: "example-actiongroup",
    resource_group_name: azurermResourceGroupExample.name,
    short_name: "exampleact",
    webhook_receiver: [
      {
        name: "callmyapi",
        service_uri: "http://example.com/alert",
      },
    ],
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermMonitorActionGroupExample.overrideLogicalId("example");
const azurermMonitorMetricAlertExample =
  new azurerm.monitorMetricAlert.MonitorMetricAlert(this, "example_3", {
    action: [
      {
        action_group_id: azurermMonitorActionGroupExample.id,
      },
    ],
    criteria: [
      {
        aggregation: "Average",
        metric_name: "UsedCapacity",
        metric_namespace: "Microsoft.OperationalInsights/workspaces",
        operator: "LessThan",
        threshold: 10,
      },
    ],
    description:
      "Action will be triggered when Average_% Idle Time metric is less than 10.",
    frequency: "PT1M",
    name: "example-metricalert",
    resource_group_name: azurermResourceGroupExample.name,
    scopes: [azurermLogAnalyticsWorkspaceExample.id],
    window_size: "PT5M",
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermMonitorMetricAlertExample.overrideLogicalId("example");
const azurermMonitorScheduledQueryRulesLogExample =
  new azurerm.monitorScheduledQueryRulesLog.MonitorScheduledQueryRulesLog(
    this,
    "example_4",
    {
      criteria: [
        {
          dimension: [
            {
              name: "Computer",
              operator: "Include",
              values: ["targetVM"],
            },
          ],
          metric_name: "Average_% Idle Time",
        },
      ],
      data_source_id: azurermLogAnalyticsWorkspaceExample.id,
      description: "Scheduled query rule LogToMetric example",
      enabled: true,
      location: azurermResourceGroupExample.location,
      name: "example",
      resource_group_name: azurermResourceGroupExample.name,
      tags: {
        foo: "bar",
      },
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermMonitorScheduledQueryRulesLogExample.overrideLogicalId("example");

Argument Reference

The following arguments are supported:

  • name - (Required) The name of the scheduled query rule. Changing this forces a new resource to be created.
  • resourceGroupName - (Required) The name of the resource group in which to create the scheduled query rule instance. Changing this forces a new resource to be created.
  • location - (Required) Specifies the Azure Region where the resource should exist. Changing this forces a new resource to be created.
  • criteria - (Required) A criteria block as defined below.
  • dataSourceId - (Required) The resource URI over which log search query is to be run.
  • authorizedResourceIds - (Optional) A list of IDs of Resources referred into query.
  • description - (Optional) The description of the scheduled query rule.
  • enabled - (Optional) Whether this scheduled query rule is enabled. Default is true.
  • tags - (Optional) A mapping of tags to assign to the resource.

The criteria block supports the following:

  • dimension - (Required) A dimension block as defined below.
  • metricName - (Required) Name of the metric. Supported metrics are listed in the Azure Monitor Microsoft.OperationalInsights/workspaces metrics namespace.

The dimension block supports the following:

  • name - (Required) Name of the dimension.
  • operator - (Optional) Operator for dimension values, - 'Include'.
  • values - (Required) List of dimension values.

Attributes Reference

The following attributes are exported:

  • id - The ID of the scheduled query rule.

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

  • create - (Defaults to 30 minutes) Used when creating the Scheduled Query Rule Log.
  • update - (Defaults to 30 minutes) Used when updating the Scheduled Query Rule Log.
  • read - (Defaults to 5 minutes) Used when retrieving the Scheduled Query Rule Log.
  • delete - (Defaults to 30 minutes) Used when deleting the Scheduled Query Rule Log.

Import

Scheduled Query Rule Log can be imported using the resourceId, e.g.

terraform import azurerm_monitor_scheduled_query_rules_log.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Insights/scheduledQueryRules/myrulename