1616
1717<#
1818. Synopsis
19- Create or update a Prometheus rule group definition.
19+ create a Prometheus rule group definition.
2020. Description
21- Create or update a Prometheus rule group definition.
21+ create a Prometheus rule group definition.
2222. Example
2323$rule1 = New-AzPrometheusRuleObject -Record "job_type:billing_jobs_duration_seconds:99p5m"
2424$scope = "/subscriptions/fffffffff-ffff-ffff-ffff-ffffffffffff/resourcegroups/MyresourceGroup/providers/microsoft.monitor/accounts/MyAccounts"
@@ -33,15 +33,15 @@ $scope = "/subscriptions/fffffffff-ffff-ffff-ffff-ffffffffffff/resourcegroups/My
3333New-AzPrometheusRuleGroup -ResourceGroupName MyresourceGroup -RuleGroupName MyRuleGroup -Location eastus -Rule $rule1 -Scope $scope -Enabled
3434
3535. Outputs
36- Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Models.Api20230301. IPrometheusRuleGroupResource
36+ Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Models.IPrometheusRuleGroupResource
3737. Notes
3838COMPLEX PARAMETER PROPERTIES
3939
4040To create the parameters described below, construct a hash table containing the appropriate properties. For information on hash tables, run Get-Help about_Hash_Tables.
4141
4242RULE <IPrometheusRule[]>: Defines the rules in the Prometheus rule group.
4343 Expression <String>: The PromQL expression to evaluate. https://prometheus.io/docs/prometheus/latest/querying/basics/. Evaluated periodically as given by 'interval', and the result recorded as a new set of time series with the metric name as given by 'record'.
44- [Action <IPrometheusRuleGroupAction[] >]: Actions that are performed when the alert rule becomes active, and when an alert condition is resolved.
44+ [Action <List< IPrometheusRuleGroupAction> >]: Actions that are performed when the alert rule becomes active, and when an alert condition is resolved.
4545 [ActionGroupId <String>]: The resource id of the action group to use.
4646 [ActionProperty <IPrometheusRuleGroupActionProperties>]: The properties of an action group object.
4747 [(Any) <String>]: This indicates any property can be added to this object.
@@ -60,7 +60,7 @@ RULE <IPrometheusRule[]>: Defines the rules in the Prometheus rule group.
6060https://learn.microsoft.com/powershell/module/az.alertsmanagement/new-azprometheusrulegroup
6161#>
6262function New-AzPrometheusRuleGroup {
63- [OutputType ([Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Models.Api20230301. IPrometheusRuleGroupResource ])]
63+ [OutputType ([Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Models.IPrometheusRuleGroupResource ])]
6464[CmdletBinding (DefaultParameterSetName = ' CreateExpanded' , PositionalBinding = $false , SupportsShouldProcess , ConfirmImpact = ' Medium' )]
6565param (
6666 [Parameter (Mandatory )]
@@ -83,21 +83,20 @@ param(
8383 # The ID of the target subscription.
8484 ${SubscriptionId} ,
8585
86- [Parameter (Mandatory )]
86+ [Parameter (ParameterSetName = ' CreateExpanded ' , Mandatory )]
8787 [Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Category (' Body' )]
8888 [System.String ]
8989 # The geo-location where the resource lives
9090 ${Location} ,
9191
92- [Parameter (Mandatory )]
92+ [Parameter (ParameterSetName = ' CreateExpanded ' , Mandatory )]
9393 [AllowEmptyCollection ()]
9494 [Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Category (' Body' )]
95- [Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Models.Api20230301. IPrometheusRule []]
95+ [Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Models.IPrometheusRule []]
9696 # Defines the rules in the Prometheus rule group.
97- # To construct, see NOTES section for RULE properties and create a hash table.
9897 ${Rule} ,
9998
100- [Parameter (Mandatory )]
99+ [Parameter (ParameterSetName = ' CreateExpanded ' , Mandatory )]
101100 [AllowEmptyCollection ()]
102101 [Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Category (' Body' )]
103102 [System.String []]
@@ -106,38 +105,50 @@ param(
106105 # This may change in future.
107106 ${Scope} ,
108107
109- [Parameter ()]
108+ [Parameter (ParameterSetName = ' CreateExpanded ' )]
110109 [Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Category (' Body' )]
111110 [System.String ]
112111 # Apply rule to data from a specific cluster.
113112 ${ClusterName} ,
114113
115- [Parameter ()]
114+ [Parameter (ParameterSetName = ' CreateExpanded ' )]
116115 [Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Category (' Body' )]
117116 [System.String ]
118117 # Rule group description.
119118 ${Description} ,
120119
121- [Parameter ()]
120+ [Parameter (ParameterSetName = ' CreateExpanded ' )]
122121 [Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Category (' Body' )]
123122 [System.Management.Automation.SwitchParameter ]
124123 # Enable/disable rule group.
125124 ${Enabled} ,
126125
127- [Parameter ()]
126+ [Parameter (ParameterSetName = ' CreateExpanded ' )]
128127 [Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Category (' Body' )]
129128 [System.TimeSpan ]
130129 # The interval in which to run the Prometheus rule group represented in ISO 8601 duration format.
131130 # Should be between 1 and 15 minutes
132131 ${Interval} ,
133132
134- [Parameter ()]
133+ [Parameter (ParameterSetName = ' CreateExpanded ' )]
135134 [Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Category (' Body' )]
136- [Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Runtime.Info (PossibleTypes= ([Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Models.Api30. ITrackedResourceTags ]))]
135+ [Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Runtime.Info (PossibleTypes= ([Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Models.ITrackedResourceTags ]))]
137136 [System.Collections.Hashtable ]
138137 # Resource tags.
139138 ${Tag} ,
140139
140+ [Parameter (ParameterSetName = ' CreateViaJsonFilePath' , Mandatory )]
141+ [Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Category (' Body' )]
142+ [System.String ]
143+ # Path of Json file supplied to the Create operation
144+ ${JsonFilePath} ,
145+
146+ [Parameter (ParameterSetName = ' CreateViaJsonString' , Mandatory )]
147+ [Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Category (' Body' )]
148+ [System.String ]
149+ # Json string supplied to the Create operation
150+ ${JsonString} ,
151+
141152 [Parameter ()]
142153 [Alias (' AzureRMContext' , ' AzureCredential' )]
143154 [ValidateNotNull ()]
@@ -194,6 +205,15 @@ begin {
194205 $PSBoundParameters [' OutBuffer' ] = 1
195206 }
196207 $parameterSet = $PSCmdlet.ParameterSetName
208+
209+ $testPlayback = $false
210+ $PSBoundParameters [' HttpPipelinePrepend' ] | Foreach-Object { if ($_ ) { $testPlayback = $testPlayback -or (' Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Runtime.PipelineMock' -eq $_.Target.GetType ().FullName -and ' Playback' -eq $_.Target.Mode ) } }
211+
212+ $context = Get-AzContext
213+ if (-not $context -and -not $testPlayback ) {
214+ Write-Error " No Azure login detected. Please run 'Connect-AzAccount' to log in."
215+ exit
216+ }
197217
198218 if ($null -eq [Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet ]::PowerShellVersion) {
199219 [Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet ]::PowerShellVersion = $PSVersionTable.PSVersion.ToString ()
@@ -214,10 +234,10 @@ begin {
214234
215235 $mapping = @ {
216236 CreateExpanded = ' Az.PrometheusRuleGroups.private\New-AzPrometheusRuleGroup_CreateExpanded' ;
237+ CreateViaJsonFilePath = ' Az.PrometheusRuleGroups.private\New-AzPrometheusRuleGroup_CreateViaJsonFilePath' ;
238+ CreateViaJsonString = ' Az.PrometheusRuleGroups.private\New-AzPrometheusRuleGroup_CreateViaJsonString' ;
217239 }
218- if ((' CreateExpanded' ) -contains $parameterSet -and -not $PSBoundParameters.ContainsKey (' SubscriptionId' )) {
219- $testPlayback = $false
220- $PSBoundParameters [' HttpPipelinePrepend' ] | Foreach-Object { if ($_ ) { $testPlayback = $testPlayback -or (' Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Runtime.PipelineMock' -eq $_.Target.GetType ().FullName -and ' Playback' -eq $_.Target.Mode ) } }
240+ if ((' CreateExpanded' , ' CreateViaJsonFilePath' , ' CreateViaJsonString' ) -contains $parameterSet -and -not $PSBoundParameters.ContainsKey (' SubscriptionId' ) ) {
221241 if ($testPlayback ) {
222242 $PSBoundParameters [' SubscriptionId' ] = . (Join-Path $PSScriptRoot ' ..' ' utils' ' Get-SubscriptionIdTestSafe.ps1' )
223243 } else {
@@ -231,6 +251,9 @@ begin {
231251 [Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet ]::PromptedPreviewMessageCmdlets.Enqueue($MyInvocation.MyCommand.Name )
232252 }
233253 $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand (($mapping [$parameterSet ]), [System.Management.Automation.CommandTypes ]::Cmdlet)
254+ if ($wrappedCmd -eq $null ) {
255+ $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand (($mapping [$parameterSet ]), [System.Management.Automation.CommandTypes ]::Function)
256+ }
234257 $scriptCmd = {& $wrappedCmd @PSBoundParameters }
235258 $steppablePipeline = $scriptCmd.GetSteppablePipeline ($MyInvocation.CommandOrigin )
236259 $steppablePipeline.Begin ($PSCmdlet )
0 commit comments