Share via


Create Alert Rule

 

The Create Alert Rule operation creates a new alert rule. For more information about alert rules and how you can use them, see Understanding Monitoring Alerts and Notifications in Azure.

You must create a GUID that is used as the identifier of the alert rule. To create a GUID, you can use the Create GUID command on the Tools menu in Visual Studio.

Request

The Create Alert Rule request may be specified as follows. Replace <subscription-id> with the subscription ID. Replace <rule-id> with the identifier of the alert rule.

Method

Request URI

PUT

https://management.core.windows.net/<subscription-id>/services/monitoring/alertrules/<rule-id>

You must make sure that the request that is made to the management service is secure. For additional details, see Authenticating Service Management Requests.

URI Parameters

None.

Request Headers

The following table describes the request headers.

Request Header

Description

Accept

Required. Set this header to application/json.

x-ms-version

Required. Specifies the version of the operation to use for this request. This header must be set to 2013-10-01 or higher. For more information about versioning headers, see Service Management Versioning.

Request Body

The format of the request body is as follows:

{
  "Rule": [
    {
      "Condition": {
        "odata.type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.ThresholdRuleCondition",
        "DataSource": {
          "odata.type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleMetricDataSource",
          "ResourceId": "<url-of-resource>",
          "MetricNamespace": "<namespace-of-metric>",
          "MetricName": "<name-of-metric>",
        },
        "Operator": "<operator-of-condition>",
        "Threshold": "<threshold-value>",
        "WindowSize": "<evaluation-time>",
      },
      "Actions": [
        {
          "odata.type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleEmailAction",
          "SendToServiceAdmin": "<send-to-admin>",
          "SendToServiceCoAdmins": "<send-to-co-admins>",
          "CustomEmails": [
            "<email-address>" 
          ] 
        }
      ],
      "Id": "<identifier-of-alert-rule>",
      "Name": "<name-of-alert-rule>",
      "Description": "<description-of-alert-rule",
      "IsEnabled": "<status-of-alert-rule>",
    } 
  ]
}

The following table describes the elements of the request body.

Element Name

Description

Rule

Required. Contains the elements that define an alert rule.

Condition

Required. Specifies the conditional parameters for an alert rule.

Actions

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

Id

Required. Specifies the GUID identifier for the alert rule.

Name

Required. Specifies the name of the alert rule. The name can contain only letters, numbers, commas, and periods. The name can be up to 32 characters long.

Description

Optional. Specifies the description of the alert rule. The description can contain only letters, numbers, commas, and periods. The description up to 128 characters long.

IsEnabled

Required. Indicates whether the alert rule is enabled.

Possible values are:

  • true

  • false

Condition

Specifies the conditional parameters for an alert rule.

Element Name

Description

DataSource

Required. Specifies information about the resource on which the alert is configured.

Operator

Required. Specifies the operator of the condition.

Possible values are:

  • GreaterThan

  • GreaterThanOrEqual

  • LessThan

  • LessThanOrEqual

Threshold

Required. Specifies the threshold value that triggers the alert. This must be a positive numeric value.

WindowSize

Required. Specifies the period of time that is used to monitor alert activity based on the threshold.

Possible values for Cloud Services and Virtual Machines when using host and guest level metrics are:

  • 5 mins

  • 10 mins

  • 15 mins

  • 30 mins

  • 45 mins

  • 60 mins

Possible values for all services when using availability metrics are:

  • 15 mins

  • 30 mins

  • 45 mins

  • 60 mins

For a description of host, guest, and availability level metrics, see the MetricName element.

Actions

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

Element Name

Description

SendToServiceAdmins

Indicates whether the administrators of the service should be notified when the alert is registered.

Possible values are:

  • true

  • false

SendToServiceCoAdmins

Indicates whether the co-administrators of the service should be notified when the alert is registered.

Possible values are:

  • true

  • false

CustomEmails

Required. Specifies a list of email addresses to use for notification of the registration of an alert.

DataSource

Specifies information about the resource on which the alert is configured.

Element Name

Description

ResourceId

Required. Specifies the relative URI of the resource to which the alert is associated.

Possible values are:

  • /hostedservices/<cloud-service-name>/deployments/<deployment-name>/roles/<role-name>

    Replace <cloud-service-name> with the name of the cloud service, <deployment-name> with the name of the deployment, <role-name> with the name of the role. You can find this information by using List Cloud Services and Get Deployment.

  • /webspaces/<webspace-name>/sites/<website-name>

    Replace <webspace-name> with the name of the webspace and <website-name> with the name of the website. For more information about finding the names of webspaces, see List Webspaces.

  • /mobileservices/<mobile-service-name>

    Replace <mobile-service-name> with the name of the mobile service.

MetricNamespace

Required for availability level metrics. Specifies the namespace of the metric. This value must be WindowsAzure.Availability.

MetricName

Required. Specifies the name of the metric that defines what the alert rule monitors.

You can specify the following host level metric names:

  • Percentage CPU

  • Disk Read Bytes/Sec

  • Disk Write Bytes/Sec

  • Network In

  • Network Out

You can specify a guest level metric name which is the name of a performance counter that is assigned to the role instance. For more information about performance counters, see Create and Use Performance Counters in an Azure Application.

You can also specify availability level metrics. You must use the Microsoft.WindowsAzure.Management.Monitoring.Metrics API to obtain the metric name when you use the Availability namespace.

Response

The response includes an HTTP status code, a set of response headers, and a response body.

Status Code

A successful operation returns status code 201 (Created). For information about status codes, see Service Management Status and Error Codes.

Response Headers

The response for this operation includes the following headers. The response may also include additional standard HTTP headers. All standard headers conform to the HTTP/1.1 protocol specification.

Response Header

Description

x-ms-request-id

A value that uniquely identifies a request made against the management service.

Response Body

None.

Remarks

You can also use the classic portal to set up alerts. For more information, see How to: Receive Alert Notifications and Manage Alert Rules in Azure.