Skip to content

New AlertRule

CI edited this page Apr 24, 2020 · 1 revision

external help file: Pinja.Azure.Alerts-help.xml Module Name: Pinja.Azure.Alerts online version: schema: 2.0.0

New-AlertRule

SYNOPSIS

Create new alert rule

SYNTAX

New-AlertRule [-ResourceType] <String> [-Name] <String> [-Severity] <String> [-Criteria] <ScriptBlock>
 [[-Description] <String>] [[-AlertValidationSteps] <String[]>] [[-AlertFixSteps] <String[]>]
 [[-WindowSize] <TimeSpan>] [[-Frequency] <TimeSpan>] [[-InputObject] <PSObject[]>] [<CommonParameters>]

DESCRIPTION

Create new alert rule. Simplifies custom alert creation by giving defaults for non mandatory values and validations for allowed values.

EXAMPLES

EXAMPLE 1

New-AlertRule `
    -ResourceType 'Microsoft.Web/Sites' `
    -Name "my-alert-1" `
    -Severity Critical `
    -Criteria { New-AzMetricAlertRuleV2Criteria -MetricName 'Http5xx' -TimeAggregation Total -Operator GreaterThan -Threshold 5 } `
    -WindowSize (New-TimeSpan -Minutes 5) `
    -Frequency (New-TimeSpan -Minutes 5)

EXAMPLE 2

$alertsWithAdditional = Get-DefaultAlertRules |
    New-AlertRule `
        -ResourceType 'Microsoft.Web/Sites' `
        -Name "my-alert-1" `
        -Severity Critical `
        -Criteria { New-AzMetricAlertRuleV2Criteria -MetricName 'Http5xx' -TimeAggregation Total -Operator GreaterThan -Threshold 5 } `
        -WindowSize (New-TimeSpan -Minutes 5) `
        -Frequency (New-TimeSpan -Minutes 5)

PARAMETERS

-ResourceType

Type of resource alert is applied, for example 'Microsoft.Web/Sites'

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Name

Name of alert. This is shown on alert page and is used to check uniquenes. Alert with same name will be overwritten.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Severity

Severity of alert.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 3
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Criteria

Scriptblock that defines alert criteria object. See documentation of New-AzMetricAlertRuleV2Criteria. Scriptblock is used so you can use targeted resource from pipeline variable ($_) for creating criteria with specific names or parameters based on resource it is applied.

Type: ScriptBlock
Parameter Sets: (All)
Aliases:

Required: True
Position: 4
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Description

Description of alert what happened and possible short description what this means in system perspective.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 5
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-AlertValidationSteps

Additional information (runbook / validation part) how receiver of alert can check that is system working or not. Usually contains array of links for documents how to validate system is working properly or not.

Type: String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: 6
Default value: @()
Accept pipeline input: False
Accept wildcard characters: False

-AlertFixSteps

Additional information (runbook / fix part) how receiver can fix issue after its validated that it isn't working properly. Usually contains array of links for documents how to attempt fix specific problematic resource.

Type: String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: 7
Default value: @()
Accept pipeline input: False
Accept wildcard characters: False

-WindowSize

How wide window is used to calculate criteria.

Type: TimeSpan
Parameter Sets: (All)
Aliases:

Required: False
Position: 8
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Frequency

How ofter defined window for criteria is checked.

Type: TimeSpan
Parameter Sets: (All)
Aliases:

Required: False
Position: 9
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-InputObject

Supports adding new alert to existing alerts with pipeline syntax.

Type: PSObject[]
Parameter Sets: (All)
Aliases:

Required: False
Position: 10
Default value: None
Accept pipeline input: True (ByValue)
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

OUTPUTS

System.Management.Automation.PSObject[]

NOTES

RELATED LINKS