16
16
17
17
<#
18
18
. Synopsis
19
- Create or update a Prometheus rule group definition.
19
+ create a Prometheus rule group definition.
20
20
. Description
21
- Create or update a Prometheus rule group definition.
21
+ create a Prometheus rule group definition.
22
22
. Example
23
23
$rule1 = New-AzPrometheusRuleObject -Record "job_type:billing_jobs_duration_seconds:99p5m"
24
24
$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
33
33
New-AzPrometheusRuleGroup -ResourceGroupName MyresourceGroup -RuleGroupName MyRuleGroup -Location eastus -Rule $rule1 -Scope $scope -Enabled
34
34
35
35
. Outputs
36
- Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Models.Api20230301. IPrometheusRuleGroupResource
36
+ Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Models.IPrometheusRuleGroupResource
37
37
. Notes
38
38
COMPLEX PARAMETER PROPERTIES
39
39
40
40
To create the parameters described below, construct a hash table containing the appropriate properties. For information on hash tables, run Get-Help about_Hash_Tables.
41
41
42
42
RULE <IPrometheusRule[]>: Defines the rules in the Prometheus rule group.
43
43
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.
45
45
[ActionGroupId <String>]: The resource id of the action group to use.
46
46
[ActionProperty <IPrometheusRuleGroupActionProperties>]: The properties of an action group object.
47
47
[(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.
60
60
https://learn.microsoft.com/powershell/module/az.alertsmanagement/new-azprometheusrulegroup
61
61
#>
62
62
function New-AzPrometheusRuleGroup {
63
- [OutputType ([Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Models.Api20230301. IPrometheusRuleGroupResource ])]
63
+ [OutputType ([Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Models.IPrometheusRuleGroupResource ])]
64
64
[CmdletBinding (DefaultParameterSetName = ' CreateExpanded' , PositionalBinding = $false , SupportsShouldProcess , ConfirmImpact = ' Medium' )]
65
65
param (
66
66
[Parameter (Mandatory )]
@@ -83,21 +83,20 @@ param(
83
83
# The ID of the target subscription.
84
84
${SubscriptionId} ,
85
85
86
- [Parameter (Mandatory )]
86
+ [Parameter (ParameterSetName = ' CreateExpanded ' , Mandatory )]
87
87
[Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Category (' Body' )]
88
88
[System.String ]
89
89
# The geo-location where the resource lives
90
90
${Location} ,
91
91
92
- [Parameter (Mandatory )]
92
+ [Parameter (ParameterSetName = ' CreateExpanded ' , Mandatory )]
93
93
[AllowEmptyCollection ()]
94
94
[Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Category (' Body' )]
95
- [Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Models.Api20230301. IPrometheusRule []]
95
+ [Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Models.IPrometheusRule []]
96
96
# Defines the rules in the Prometheus rule group.
97
- # To construct, see NOTES section for RULE properties and create a hash table.
98
97
${Rule} ,
99
98
100
- [Parameter (Mandatory )]
99
+ [Parameter (ParameterSetName = ' CreateExpanded ' , Mandatory )]
101
100
[AllowEmptyCollection ()]
102
101
[Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Category (' Body' )]
103
102
[System.String []]
@@ -106,38 +105,50 @@ param(
106
105
# This may change in future.
107
106
${Scope} ,
108
107
109
- [Parameter ()]
108
+ [Parameter (ParameterSetName = ' CreateExpanded ' )]
110
109
[Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Category (' Body' )]
111
110
[System.String ]
112
111
# Apply rule to data from a specific cluster.
113
112
${ClusterName} ,
114
113
115
- [Parameter ()]
114
+ [Parameter (ParameterSetName = ' CreateExpanded ' )]
116
115
[Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Category (' Body' )]
117
116
[System.String ]
118
117
# Rule group description.
119
118
${Description} ,
120
119
121
- [Parameter ()]
120
+ [Parameter (ParameterSetName = ' CreateExpanded ' )]
122
121
[Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Category (' Body' )]
123
122
[System.Management.Automation.SwitchParameter ]
124
123
# Enable/disable rule group.
125
124
${Enabled} ,
126
125
127
- [Parameter ()]
126
+ [Parameter (ParameterSetName = ' CreateExpanded ' )]
128
127
[Microsoft.Azure.PowerShell.Cmdlets.PrometheusRuleGroups.Category (' Body' )]
129
128
[System.TimeSpan ]
130
129
# The interval in which to run the Prometheus rule group represented in ISO 8601 duration format.
131
130
# Should be between 1 and 15 minutes
132
131
${Interval} ,
133
132
134
- [Parameter ()]
133
+ [Parameter (ParameterSetName = ' CreateExpanded ' )]
135
134
[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 ]))]
137
136
[System.Collections.Hashtable ]
138
137
# Resource tags.
139
138
${Tag} ,
140
139
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
+
141
152
[Parameter ()]
142
153
[Alias (' AzureRMContext' , ' AzureCredential' )]
143
154
[ValidateNotNull ()]
@@ -194,6 +205,15 @@ begin {
194
205
$PSBoundParameters [' OutBuffer' ] = 1
195
206
}
196
207
$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
+ }
197
217
198
218
if ($null -eq [Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet ]::PowerShellVersion) {
199
219
[Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet ]::PowerShellVersion = $PSVersionTable.PSVersion.ToString ()
@@ -214,10 +234,10 @@ begin {
214
234
215
235
$mapping = @ {
216
236
CreateExpanded = ' Az.PrometheusRuleGroups.private\New-AzPrometheusRuleGroup_CreateExpanded' ;
237
+ CreateViaJsonFilePath = ' Az.PrometheusRuleGroups.private\New-AzPrometheusRuleGroup_CreateViaJsonFilePath' ;
238
+ CreateViaJsonString = ' Az.PrometheusRuleGroups.private\New-AzPrometheusRuleGroup_CreateViaJsonString' ;
217
239
}
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' ) ) {
221
241
if ($testPlayback ) {
222
242
$PSBoundParameters [' SubscriptionId' ] = . (Join-Path $PSScriptRoot ' ..' ' utils' ' Get-SubscriptionIdTestSafe.ps1' )
223
243
} else {
@@ -231,6 +251,9 @@ begin {
231
251
[Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet ]::PromptedPreviewMessageCmdlets.Enqueue($MyInvocation.MyCommand.Name )
232
252
}
233
253
$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
+ }
234
257
$scriptCmd = {& $wrappedCmd @PSBoundParameters }
235
258
$steppablePipeline = $scriptCmd.GetSteppablePipeline ($MyInvocation.CommandOrigin )
236
259
$steppablePipeline.Begin ($PSCmdlet )
0 commit comments