Alert Rules - Create Or Update

Creates or updates a classic metric alert rule.

PUT https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Insights/alertrules/{ruleName}?api-version=2016-03-01

URI Parameters

Name In Required Type Description
resourceGroupName
path True

string

The name of the resource group. The name is case insensitive.

ruleName
path True

string

The name of the rule.

subscriptionId
path True

string

The ID of the target subscription.

api-version
query True

string

The API version to use for this operation.

Request Body

Name Required Type Description
location True

string

Resource location

properties.condition True RuleCondition:

the condition that results in the alert rule being activated.

properties.isEnabled True

boolean

the flag that indicates whether the alert rule is enabled.

properties.name True

string

the name of the alert rule.

properties.action RuleAction:

action that is performed when the alert rule becomes active, and when an alert condition is resolved.

properties.actions RuleAction[]:

the array of actions that are performed when the alert rule becomes active, and when an alert condition is resolved.

properties.description

string

the description of the alert rule that will be included in the alert email.

properties.provisioningState

string

the provisioning state.

tags

object

Resource tags

Responses

Name Type Description
200 OK

AlertRuleResource

Successful request to update an alert rule

201 Created

AlertRuleResource

Created alert rule

Other Status Codes

ErrorResponse

Error response describing why the operation failed.

Security

azure_auth

Azure Active Directory OAuth2 Flow

Type: oauth2
Flow: implicit
Authorization URL: https://login.microsoftonline.com/common/oauth2/authorize

Scopes

Name Description
user_impersonation impersonate your user account

Examples

Create or update an alert rule

Sample request

PUT https://management.azure.com/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourcegroups/Rac46PostSwapRG/providers/Microsoft.Insights/alertrules/chiricutin?api-version=2016-03-01

{
  "location": "West US",
  "tags": {},
  "properties": {
    "name": "chiricutin",
    "description": "Pura Vida",
    "isEnabled": true,
    "condition": {
      "odata.type": "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition",
      "dataSource": {
        "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource",
        "resourceUri": "/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/Microsoft.Web/sites/leoalerttest",
        "metricName": "Requests"
      },
      "operator": "GreaterThan",
      "threshold": 3,
      "windowSize": "PT5M",
      "timeAggregation": "Total"
    },
    "actions": []
  }
}

Sample response

{
  "id": "/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/microsoft.insights/alertrules/chiricutin",
  "name": "chiricutin",
  "type": "Microsoft.Insights/alertRules",
  "location": "West US",
  "tags": {
    "$type": "Microsoft.WindowsAzure.Management.Common.Storage.CasePreservedDictionary, Microsoft.WindowsAzure.Management.Common.Storage",
    "hidden-link:/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/Microsoft.Web/sites/leoalerttest": "Resource"
  },
  "properties": {
    "name": "chiricutin",
    "description": "Pura Vida",
    "isEnabled": true,
    "condition": {
      "odata.type": "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition",
      "dataSource": {
        "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource",
        "resourceUri": "/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/Microsoft.Web/sites/leoalerttest",
        "metricName": "Requests"
      },
      "operator": "GreaterThan",
      "threshold": 3,
      "windowSize": "PT5M",
      "timeAggregation": "Total"
    },
    "lastUpdatedTime": "2016-11-23T21:23:52.0221265Z",
    "actions": []
  }
}
{
  "id": "/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/microsoft.insights/alertrules/chiricutin",
  "name": "chiricutin",
  "type": "Microsoft.Insights/alertRules",
  "location": "West US",
  "tags": {
    "$type": "Microsoft.WindowsAzure.Management.Common.Storage.CasePreservedDictionary, Microsoft.WindowsAzure.Management.Common.Storage",
    "hidden-link:/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/Microsoft.Web/sites/leoalerttest": "Resource"
  },
  "properties": {
    "name": "chiricutin",
    "description": "Pura Vida",
    "isEnabled": true,
    "condition": {
      "odata.type": "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition",
      "dataSource": {
        "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource",
        "resourceUri": "/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/Microsoft.Web/sites/leoalerttest",
        "metricName": "Requests"
      },
      "operator": "GreaterThan",
      "threshold": 3,
      "windowSize": "PT5M",
      "timeAggregation": "Total"
    },
    "lastUpdatedTime": "2016-11-23T21:23:52.0221265Z",
    "actions": []
  }
}

Definitions

Name Description
AlertRuleResource

The alert rule resource.

ConditionOperator

Operators allowed in the rule condition.

ErrorResponse

Describes the format of Error response.

LocationThresholdRuleCondition

A rule condition based on a certain number of locations failing.

ManagementEventAggregationCondition

How the data that is collected should be combined over time.

ManagementEventRuleCondition

A management event rule condition.

RuleEmailAction

Specifies the action to send email when the rule condition is evaluated. The discriminator is always RuleEmailAction in this case.

RuleManagementEventClaimsDataSource

The claims for a rule management event data source.

RuleManagementEventDataSource

A rule management event data source. The discriminator fields is always RuleManagementEventDataSource in this case.

RuleMetricDataSource

A rule metric data source. The discriminator value is always RuleMetricDataSource in this case.

RuleWebhookAction

Specifies the action to post to service when the rule condition is evaluated. The discriminator is always RuleWebhookAction in this case.

ThresholdRuleCondition

A rule condition based on a metric crossing a threshold.

TimeAggregationOperator

Aggregation operators allowed in a rule.

AlertRuleResource

The alert rule resource.

Name Type Description
id

string

Azure resource Id

location

string

Resource location

name

string

Azure resource name

properties.action RuleAction:

action that is performed when the alert rule becomes active, and when an alert condition is resolved.

properties.actions RuleAction[]:

the array of actions that are performed when the alert rule becomes active, and when an alert condition is resolved.

properties.condition RuleCondition:

the condition that results in the alert rule being activated.

properties.description

string

the description of the alert rule that will be included in the alert email.

properties.isEnabled

boolean

the flag that indicates whether the alert rule is enabled.

properties.lastUpdatedTime

string

Last time the rule was updated in ISO8601 format.

properties.name

string

the name of the alert rule.

properties.provisioningState

string

the provisioning state.

tags

object

Resource tags

type

string

Azure resource type

ConditionOperator

Operators allowed in the rule condition.

Name Type Description
GreaterThan

string

GreaterThanOrEqual

string

LessThan

string

LessThanOrEqual

string

ErrorResponse

Describes the format of Error response.

Name Type Description
code

string

Error code

message

string

Error message indicating why the operation failed.

LocationThresholdRuleCondition

A rule condition based on a certain number of locations failing.

Name Type Description
dataSource RuleDataSource:

the resource from which the rule collects its data. For this type dataSource will always be of type RuleMetricDataSource.

failedLocationCount

integer

the number of locations that must fail to activate the alert.

odata.type string:

Microsoft.Azure.Management.Insights.Models.LocationThresholdRuleCondition

specifies the type of condition. This can be one of three types: ManagementEventRuleCondition (occurrences of management events), LocationThresholdRuleCondition (based on the number of failures of a web test), and ThresholdRuleCondition (based on the threshold of a metric).

windowSize

string

the period of time (in ISO 8601 duration format) that is used to monitor alert activity based on the threshold. If specified then it must be between 5 minutes and 1 day.

ManagementEventAggregationCondition

How the data that is collected should be combined over time.

Name Type Description
operator

ConditionOperator

the condition operator.

threshold

number

The threshold value that activates the alert.

windowSize

string

the period of time (in ISO 8601 duration format) that is used to monitor alert activity based on the threshold. If specified then it must be between 5 minutes and 1 day.

ManagementEventRuleCondition

A management event rule condition.

Name Type Description
aggregation

ManagementEventAggregationCondition

How the data that is collected should be combined over time and when the alert is activated. Note that for management event alerts aggregation is optional – if it is not provided then any event will cause the alert to activate.

dataSource RuleDataSource:

the resource from which the rule collects its data. For this type dataSource will always be of type RuleMetricDataSource.

odata.type string:

Microsoft.Azure.Management.Insights.Models.ManagementEventRuleCondition

specifies the type of condition. This can be one of three types: ManagementEventRuleCondition (occurrences of management events), LocationThresholdRuleCondition (based on the number of failures of a web test), and ThresholdRuleCondition (based on the threshold of a metric).

RuleEmailAction

Specifies the action to send email when the rule condition is evaluated. The discriminator is always RuleEmailAction in this case.

Name Type Description
customEmails

string[]

the list of administrator's custom email addresses to notify of the activation of the alert.

odata.type string:

Microsoft.Azure.Management.Insights.Models.RuleEmailAction

specifies the type of the action. There are two types of actions: RuleEmailAction and RuleWebhookAction.

sendToServiceOwners

boolean

Whether the administrators (service and co-administrators) of the service should be notified when the alert is activated.

RuleManagementEventClaimsDataSource

The claims for a rule management event data source.

Name Type Description
emailAddress

string

the email address.

RuleManagementEventDataSource

A rule management event data source. The discriminator fields is always RuleManagementEventDataSource in this case.

Name Type Description
claims

RuleManagementEventClaimsDataSource

the claims.

eventName

string

the event name.

eventSource

string

the event source.

legacyResourceId

string

the legacy resource identifier of the resource the rule monitors. NOTE: this property cannot be updated for an existing rule.

level

string

the level.

metricNamespace

string

the namespace of the metric.

odata.type string:

Microsoft.Azure.Management.Insights.Models.RuleManagementEventDataSource

specifies the type of data source. There are two types of rule data sources: RuleMetricDataSource and RuleManagementEventDataSource

operationName

string

The name of the operation that should be checked for. If no name is provided, any operation will match.

resourceGroupName

string

the resource group name.

resourceLocation

string

the location of the resource.

resourceProviderName

string

the resource provider name.

resourceUri

string

the resource identifier of the resource the rule monitors. NOTE: this property cannot be updated for an existing rule.

status

string

The status of the operation that should be checked for. If no status is provided, any status will match.

subStatus

string

the substatus.

RuleMetricDataSource

A rule metric data source. The discriminator value is always RuleMetricDataSource in this case.

Name Type Description
legacyResourceId

string

the legacy resource identifier of the resource the rule monitors. NOTE: this property cannot be updated for an existing rule.

metricName

string

the name of the metric that defines what the rule monitors.

metricNamespace

string

the namespace of the metric.

odata.type string:

Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource

specifies the type of data source. There are two types of rule data sources: RuleMetricDataSource and RuleManagementEventDataSource

resourceLocation

string

the location of the resource.

resourceUri

string

the resource identifier of the resource the rule monitors. NOTE: this property cannot be updated for an existing rule.

RuleWebhookAction

Specifies the action to post to service when the rule condition is evaluated. The discriminator is always RuleWebhookAction in this case.

Name Type Description
odata.type string:

Microsoft.Azure.Management.Insights.Models.RuleWebhookAction

specifies the type of the action. There are two types of actions: RuleEmailAction and RuleWebhookAction.

properties

object

the dictionary of custom properties to include with the post operation. These data are appended to the webhook payload.

serviceUri

string

the service uri to Post the notification when the alert activates or resolves.

ThresholdRuleCondition

A rule condition based on a metric crossing a threshold.

Name Type Description
dataSource RuleDataSource:

the resource from which the rule collects its data. For this type dataSource will always be of type RuleMetricDataSource.

odata.type string:

Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition

specifies the type of condition. This can be one of three types: ManagementEventRuleCondition (occurrences of management events), LocationThresholdRuleCondition (based on the number of failures of a web test), and ThresholdRuleCondition (based on the threshold of a metric).

operator

ConditionOperator

the operator used to compare the data and the threshold.

threshold

number

the threshold value that activates the alert.

timeAggregation

TimeAggregationOperator

the time aggregation operator. How the data that are collected should be combined over time. The default value is the PrimaryAggregationType of the Metric.

windowSize

string

the period of time (in ISO 8601 duration format) that is used to monitor alert activity based on the threshold. If specified then it must be between 5 minutes and 1 day.

TimeAggregationOperator

Aggregation operators allowed in a rule.

Name Type Description
Average

string

Last

string

Maximum

string

Minimum

string

Total

string