Add-AlertRule

Applies To: Azure PowerShell 1.0

Add-AlertRule

Adds or updates an alert rule for a metric, an event, or a webtest.

Syntax

Parameter Set: Parameters for AddAlert cmdlet for events
Add-AlertRule -EventName <String> -EventSource <String> -Level <String> -Location <String> -Name <String> -OperationName <String> -Operator <ConditionOperator> {GreaterThan | GreaterThanOrEqual | LessThan | LessThanOrEqual} -ResourceGroup <String> -ResourceId <String> -ResourceProvider <String> -RuleType <AlertRuleTypes> {Metric | Event | Webtest} -Status <String> -SubStatus <String> -Threshold <Double> [-CustomEmails <String[]> ] [-Description <String> ] [-DisableRule] [-EmailAddress <String> ] [-SendToServiceOwners] [-WindowSize <TimeSpan> ] [ <CommonParameters>]

Parameter Set: Parameters for AddAlert cmdlet for metrics
Add-AlertRule -Location <String> -MetricName <String> -Name <String> -Operator <ConditionOperator> {GreaterThan | GreaterThanOrEqual | LessThan | LessThanOrEqual} -ResourceGroup <String> -ResourceId <String> -RuleType <AlertRuleTypes> {Metric | Event | Webtest} -Threshold <Double> [-CustomEmails <String[]> ] [-Description <String> ] [-DisableRule] [-SendToServiceOwners] [-TimeAggregationOperator <TimeAggregationOperator]> ] [-WindowSize <TimeSpan> ] [ <CommonParameters>]

Parameter Set: Parameters for AddAlert cmdlet for webtests
Add-AlertRule -FailedLocationCount <Int32> -Location <String> -Name <String> -ResourceGroup <String> -RuleType <AlertRuleTypes> {Metric | Event | Webtest} [-CustomEmails <String[]> ] [-Description <String> ] [-DisableRule] [-SendToServiceOwners] [-WindowSize <TimeSpan> ] [ <CommonParameters>]

Detailed Description

The Add-AlertRule cmdlet adds or updates an alert rule for a metric, an event, or a web test. The rule is associated with a resource group and has a name.

Parameters

-CustomEmails<String[]>

Specifies comma-separated email addresses to send notifications when the rule runs.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-Description<String>

Specifies the description of the rule.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-DisableRule

Indicates that the rule is disabled. If not specified, the rule is enabled.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-EmailAddress<String>

Specifies an email address to use when reporting activation of a rule.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-EventName<String>

Specifies the name of the event that the rule is monitoring. Only used by rules that are specified for events.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-EventSource<String>

Specifies the source of the event that the rule is monitoring. Only used by rules that are specified for events.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-FailedLocationCount<Int32>

Specifies the number of locations that must fail in order to activate the alert.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-Level<String>

Specifies the level of the event that the rule is monitoring. Only used by rules that are specified for events.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-Location<String>

Specifies the location of the rule.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-MetricName<String>

Specifies the name of the metric that the rule is monitoring. Only used by rules that are specified for metrics.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-Name<String>

Specifies the name of the rule.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-OperationName<String>

Specifies the name of the operation.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-Operator<ConditionOperator>

Specifies the relational operator for the condition of the rule.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-ResourceGroup<String>

Specifies the name of the resource group for the rule.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-ResourceId<String>

Specifies the ID of the resource that the rule is monitoring.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-ResourceProvider<String>

Specifies the name of the provider of the resource.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-RuleType<AlertRuleTypes>

Specifies the type of the rule. The acceptable values for this parameter are:

-- Metric
-- Event
-- Webtest

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-SendToServiceOwners

Indicates that the rule sends a notification to the owners of the service when the rule runs.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-Status<String>

Specifies the status of the rule.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-SubStatus<String>

Specifies the substatus of the rule.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-Threshold<Double>

Specifies the threshold of the rule.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-TimeAggregationOperator<TimeAggregationOperator]>

Specifies the aggregation operator to apply to the time window when the rule is evaluated.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-WindowSize<TimeSpan>

Specifies the size of the time window for the rule to use to compute its data.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see    about_CommonParameters.

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

Outputs

The output type is the type of the objects that the cmdlet emits.

Examples

Example 1: Add an alert rule for a metric

This command creates an alert rule for a metric and associates it with a website.

PS C:\> Add-AlertRule -RuleType Metric -Name 'Contoso11' -Location 'East US' -ResourceGroup Default-Web-EastUS -Operator GreaterThan -Threshold 2 -WindowSize 00:05:00 -ResourceId '/subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/ResourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/ContosoWebsite' -MetricName 'Requests' -Description 'Contoso' -TimeAggregationOperator Total 

OUTPUT:
RequestId                              StatusCode
---------                              ----------
33574ccf-0b01-43b4-aa97-87e6bbcf1c11   Created

Example 2: Disable an alert rule

This command disables an alert rule. If the alert rule does not exist, the alert rule is created and then immediately disabled. If the alert rule already exists, the alert rule is disabled.

PS C:\> Add-AlertRule -RuleType Metric -Name 'Contoso22' -Location "East US" -ResourceGroup Default-Web-EastUS -Operator GreaterThan -Threshold 2 -WindowSize 00:05:00 -ResourceId '/subscriptions/b93fb07a-6f93-30be-bf3e-4f0deca15f4f/ResourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/ContosoWebsite' -MetricName 'Requests' -TimeAggregationOperator Total -CustomEmails 'DavidChew@Contoso.com' -SendToServiceOwners -DisableRule. 

OUTPUT:
RequestId                              StatusCode
---------                              ----------
96c489f1-8529-46e1-a76d-2c1463ca3116   OK

Example 3: Add an alert rule with email notifications

This command creates an alert rule, associates it with a website, and specifies email addresses to send notifications.

PS C:\> Add-AlertRule -Name 'Contoso22' -Location "East US" -ResourceGroup Default-Web-EastUS -Operator GreaterThan -Threshold 1 -ResourceId '/subscriptions/b93fb07a-6f93-30be-bf3e-4f0deca15f4f/ResourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/ContosoWebsite' -MetricName 'Requests' -TimeAggregationOperator Total -CustomEmails 'DavidChew@Contoso.com','PattiFuller@Contoso.com'

OUTPUT:
RequestId                              StatusCode
---------                              ----------
9a5bc388-c7ac-4dc6-aa70-f4bc29c2c712   OK

Get-AlertHistory

Get-AlertRule

Remove-AlertRule