Skip to content

Commit 38a8c26

Browse files
authored
Merge pull request Azure#9935 from shpimpal/shpimpal-SQRCmdlets
SQR Cmdlets improvements
2 parents dc79350 + 8857e72 commit 38a8c26

10 files changed

+92
-65
lines changed

src/Monitor/Monitor/ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Improvements in Scheduled Query Rule cmdlets (SQR)
22+
- Cmdlets will accept `Location` paramater in both formats, either the location (e.g. eastus) or the location display name (e.g. East US)
23+
- Illustrated `Enabled` parameter in help files properly
24+
- Added examples for `ActionGroup` optional parameter
25+
- Overall improved help files
2126
* Fix bug in determining scope type for `Set-AzActionRule`
2227

2328
## Version 1.2.2

src/Monitor/Monitor/ScheduledQueryRules/NewScheduledQueryRuleCommand.cs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,35 +97,48 @@ public class NewScheduledQueryRuleCommand : ManagementCmdletBase
9797
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
9898
public SwitchParameter AsJob { get; set; }
9999
#endregion
100+
100101
protected override void ProcessRecordInternal()
101102
{
102103
try
103104
{
104105
// Convert Tag parameter from Hashtable to Dictionary<string, string>
105106
Dictionary<string, string> tags = TagsConversionHelper.CreateTagDictionary(Tag, true);
106107

107-
var alertingAction = new AlertingAction(severity: Action.Severity, aznsAction: Action.AznsAction, trigger: Action.Trigger, throttlingInMin: Action.ThrottlingInMin);
108+
var alertingAction = new AlertingAction(severity: Action.Severity, aznsAction: Action.AznsAction,
109+
trigger: Action.Trigger, throttlingInMin: Action.ThrottlingInMin);
108110

109-
var parameters = new LogSearchRuleResource(location: Location, source: Source, schedule: Schedule,
110-
action:alertingAction, tags: tags, description: Description, enabled: Enabled? "true" : "false");
111+
var parameters = new LogSearchRuleResource(location: NormalizeLocation(Location), source: Source,
112+
schedule: Schedule,
113+
action: alertingAction, tags: tags, description: Description, enabled: Enabled ? "true" : "false");
111114

112115
parameters.Validate();
113116
if (this.ShouldProcess(this.Name,
114117
string.Format("Creating Log Alert Rule '{0}' in resource group {0}", this.Name,
115-
this.ResourceGroupName)))
118+
this.ResourceGroupName)))
116119
{
117120

118121
var result = this.MonitorManagementClient.ScheduledQueryRules
119-
.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName: ResourceGroupName, ruleName: Name,
120-
parameters: parameters).Result;
122+
.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName: ResourceGroupName, ruleName: Name,
123+
parameters: parameters).Result;
121124

122125
WriteObject(new PSScheduledQueryRuleResource(result.Body));
123126
}
124127
}
125128
catch (Exception ex)
126129
{
127130
throw new Exception("Error occurred while creating Log Alert rule", ex);
128-
}
131+
}
132+
133+
}
134+
135+
private string NormalizeLocation(string location)
136+
{
137+
// lowercase and remove whitespace
138+
// e.g. "South Central US" => "southcentralus"
139+
return location == null
140+
? null
141+
: location.Replace(" ", "").ToLower();
129142
}
130143
}
131144
}

src/Monitor/Monitor/ScheduledQueryRules/SetScheduledQueryRuleCommand.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,20 @@ protected override void ProcessRecordInternal()
187187
}
188188
}
189189

190+
private string NormalizeLocation(string location)
191+
{
192+
// lowercase and remove whitespace
193+
// e.g. "South Central US" => "southcentralus"
194+
return location == null
195+
? null
196+
: location.Replace(" ", "").ToLower();
197+
}
198+
190199
private ScheduledQueryRuleResource UpdateScheduledQueryRuleResource(ScheduledQueryRuleResource requestBody)
191200
{
192201
if (this.MyInvocation.BoundParameters.ContainsKey("Location") || this.Location != null)
193202
{
194-
requestBody.Location = this.Location;
203+
requestBody.Location = NormalizeLocation(this.Location);
195204
}
196205

197206
if (this.MyInvocation.BoundParameters.ContainsKey("Action") || this.Action != null)

src/Monitor/Monitor/help/Get-AzScheduledQueryRule.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,38 +36,38 @@ Gets Scheduled Query Resources
3636

3737
### Example 1 - List by subscription or resource group
3838
```powershell
39-
PS C:\> Get-AzScheduledQueryRule -ResourceGroupName "shrutika-rg"
39+
PS C:\> Get-AzScheduledQueryRule -ResourceGroupName "MyResourceGroup"
4040
41-
Description : desc 1
41+
Description : description 1
4242
Enabled : true
4343
LastUpdatedTime : 19-Apr-19 12:29:39 PM
4444
ProvisioningState : Succeeded
4545
Source : Microsoft.Azure.Management.Monitor.Models.Source
4646
Schedule : Microsoft.Azure.Management.Monitor.Models.Schedule
4747
Action : Microsoft.Azure.Management.Monitor.Models.AlertingAction
48-
Id : /subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/shrutika-rg/providers/microsoft.insights/scheduledqueryrules/LogAlertRulePSTest1
49-
Name : LogAlertRulePSTest1
48+
Id : /subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/MyResourceGroup/providers/microsoft.insights/scheduledqueryrules/LogAlertRule1
49+
Name : LogAlertRule1
5050
Type : microsoft.insights/scheduledqueryrules
5151
Location : centralindia
52-
Tags : {[hidden-link:/subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/shrutika-rg/providers/Microsoft.OperationalInsights/workspaces/shrutika-ws, Resource]}
52+
Tags : {[hidden-link:/subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/MyResourceGroup/providers/Microsoft.OperationalInsights/workspaces/MyWorkspace, Resource]}
5353
54-
Description : desc 2
54+
Description : description 2
5555
Enabled : true
5656
LastUpdatedTime : 15-Apr-19 6:57:00 PM
5757
ProvisioningState : Succeeded
5858
Source : Microsoft.Azure.Management.Monitor.Models.Source
59-
Schedule :
59+
Schedule : Microsoft.Azure.Management.Monitor.Models.Schedule
6060
Action : Microsoft.Azure.Management.Monitor.Models.Action
61-
Id : /subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/shrutika-rg/providers/microsoft.insights/scheduledqueryrules/LogAlertRulePSTest1
62-
Name : LogAlertRulePSTest2
61+
Id : /subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/MyResourceGroup/providers/microsoft.insights/scheduledqueryrules/LogAlertRule2
62+
Name : LogAlertRule2
6363
Type : microsoft.insights/scheduledqueryrules
6464
Location : centralindia
65-
Tags : {[hidden-link:/subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/shrutika-rg/providers/Microsoft.OperationalInsights/workspaces/shrutika-ws, Resource]}
65+
Tags : {[hidden-link:/subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/MyResourceGroup/providers/Microsoft.OperationalInsights/workspaces/MyWorkspace, Resource]}
6666
```
6767

6868
### Example 2 - Get by rule name
6969
```powershell
70-
PS C:\> Get-AzScheduledQueryRule -ResourceGroupName "shrutika-rg" -Name "LogAlertRulePSTest1"
70+
PS C:\> Get-AzScheduledQueryRule -ResourceGroupName "MyResourceGroup" -Name "LogAlertRule1"
7171
7272
Description : desc 1
7373
Enabled : true
@@ -76,16 +76,16 @@ ProvisioningState : Succeeded
7676
Source : Microsoft.Azure.Management.Monitor.Models.Source
7777
Schedule : Microsoft.Azure.Management.Monitor.Models.Schedule
7878
Action : Microsoft.Azure.Management.Monitor.Models.AlertingAction
79-
Id : /subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/shrutika-rg/providers/microsoft.insights/scheduledqueryrules/LogAlertRulePSTest1
80-
Name : LogAlertRulePSTest1
79+
Id : /subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/MyResourceGroup/providers/microsoft.insights/scheduledqueryrules/LogAlertRule1
80+
Name : LogAlertRule1
8181
Type : microsoft.insights/scheduledqueryrules
8282
Location : centralindia
83-
Tags : {[hidden-link:/subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/shrutika-rg/providers/Microsoft.OperationalInsights/workspaces/shrutika-ws, Resource]}
83+
Tags : {[hidden-link:/subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/MyResourceGroup/providers/Microsoft.OperationalInsights/workspaces/MyWorkspace, Resource]}
8484
```
8585

8686
### Example 3 - Get by resource Id
8787
```powershell
88-
PS C:\> Get-AzScheduledQueryRule -ResourceId "/subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/shrutika-rg/providers/microsoft.insights/scheduledqueryrules/LogAlertRulePSTest1"
88+
PS C:\> Get-AzScheduledQueryRule -ResourceId "/subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/MyResourceGroup/providers/microsoft.insights/scheduledqueryrules/LogAlertRule1"
8989
9090
Description : desc 1
9191
Enabled : true
@@ -94,11 +94,11 @@ ProvisioningState : Succeeded
9494
Source : Microsoft.Azure.Management.Monitor.Models.Source
9595
Schedule : Microsoft.Azure.Management.Monitor.Models.Schedule
9696
Action : Microsoft.Azure.Management.Monitor.Models.AlertingAction
97-
Id : /subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/shrutika-rg/providers/microsoft.insights/scheduledqueryrules/LogAlertRulePSTest1
98-
Name : LogAlertRulePSTest1
97+
Id : /subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/MyResourceGroup/providers/microsoft.insights/scheduledqueryrules/LogAlertRule1
98+
Name : LogAlertRule1
9999
Type : microsoft.insights/scheduledqueryrules
100100
Location : centralindia
101-
Tags : {[hidden-link:/subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/shrutika-rg/providers/Microsoft.OperationalInsights/workspaces/shrutika-ws, Resource]}
101+
Tags : {[hidden-link:/subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/MyResourceGroup/providers/Microsoft.OperationalInsights/workspaces/MyWorkspace, Resource]}
102102
```
103103

104104
## PARAMETERS

src/Monitor/Monitor/help/New-AzScheduledQueryRule.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Creates a Log Alert Rule (Scheduled Query Rule type)
2626

2727
### Example 1
2828
```powershell
29-
PS C:\> New-AzScheduledQueryRule -Location "West Europe" -Action $alertingAction -Enabled "true" -Description "log alert foo" -Schedule $schedule -Source $source -Name "logalertfoo"
29+
PS C:\> New-AzScheduledQueryRule -Location "West Europe" -Action $alertingAction -Enabled $true -Description "log alert foo" -Schedule $schedule -Source $source -Name "LogAlertRule1"
3030
```
3131

3232
## PARAMETERS
@@ -92,7 +92,7 @@ Accept wildcard characters: False
9292
```
9393
9494
### -Enabled
95-
The azure alert state - valid values - true, false
95+
The azure alert state - valid values - $true, $false
9696
9797
```yaml
9898
Type: System.Boolean

src/Monitor/Monitor/help/New-AzScheduledQueryRuleAznsActionGroup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ This object is to be passed to the command that creates Log Alert Rule.
2525

2626
### Example 1
2727
```powershell
28-
PS C:\> $aznsActionGroup = New-AzScheduledQueryRuleAznsActionGroup -ActionGroup [] -EmailSubject "Email subject" -CustomWebhookPayload "{}"
28+
PS C:\> $aznsActionGroup = New-AzScheduledQueryRuleAznsActionGroup -ActionGroup @("/subscriptions/ad825170-845c-47db-8f00-11978947b089/resourcegroups/MyResourceGroup/providers/microsoft.insights/actiongroups/MyActionGroup") -EmailSubject "Email subject" -CustomWebhookPayload "{}"
2929
```
3030

3131
## PARAMETERS

src/Monitor/Monitor/help/New-AzScheduledQueryRuleSource.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ This object is to be passed to the command that creates Log Alert Rule
2525

2626
### Example 1
2727
```powershell
28-
PS C:\> $source = New-AzScheduledQueryRuleSource -Query "Heartbeat | summarize AggregatedValue = count() by bin(TimeGenerated, 5m)"
29-
-DataSourceId "/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/Microsoft.OperationalInsights/workspaces/sampleWorkspace"
28+
PS C:\> $source = New-AzScheduledQueryRuleSource -Query "Heartbeat | summarize AggregatedValue = count() by bin(TimeGenerated, 5m)"
29+
-DataSourceId "/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/MyResourceGroup/providers/Microsoft.OperationalInsights/workspaces/MyWorkspace"
3030
-QueryType "ResultCount"
3131
```
3232

src/Monitor/Monitor/help/Remove-AzScheduledQueryRule.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Removes a Log Alert Rule
3737

3838
### Example 1 - Remove by rule name
3939
```powershell
40-
PS C:\> Remove-AzScheduledQueryRule -ResourceGroupName "Rac46PostSwapRG" -Name "logalertfoo"
40+
PS C:\> Remove-AzScheduledQueryRule -ResourceGroupName "MyResourceGroup" -Name "LogAlertRule1"
4141
```
4242

4343
### Example 2 - Remove by input object
@@ -47,7 +47,7 @@ PS C:\> Remove-AzScheduledQueryRule -InputObject $PSScheduledQueryRuleResource
4747

4848
### Example 3 - Remove by resource Id
4949
```powershell
50-
PS C:\> Remove-AzScheduledQueryRule -ResourceId "/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/microsoft.insights/scheduledQueryRules/logalertfoo"
50+
PS C:\> Remove-AzScheduledQueryRule -ResourceId "/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/MyResourceGroup/providers/microsoft.insights/scheduledQueryRules/LogAlertRule1"
5151
```
5252

5353
## PARAMETERS

src/Monitor/Monitor/help/Set-AzScheduledQueryRule.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,56 +43,56 @@ Updates a Log Alert Rule by PUT semantics
4343

4444
### Example 1 - Set by rule name
4545
```powershell
46-
PS C:\> Set-AzScheduledQueryRule -ResourceGroupName "shrutika-rg" -Name "LogAlertRulePSTest1" -Enabled 1 -Location "centralindia" -Action $alertingAction -Description "log alert example" -Schedule $schedule -Source $source
46+
PS C:\> Set-AzScheduledQueryRule -ResourceGroupName "MyResourceGroup" -Name "LogAlertRule1" -Enabled $true -Location "centralindia" -Action $alertingAction -Description "log alert description" -Schedule $schedule -Source $source
4747
48-
Description : log alert example
48+
Description : log alert description
4949
Enabled : true
5050
LastUpdatedTime : 19-Apr-19 12:45:04 PM
5151
ProvisioningState : Succeeded
5252
Source : Microsoft.Azure.Management.Monitor.Models.Source
5353
Schedule : Microsoft.Azure.Management.Monitor.Models.Schedule
5454
Action : Microsoft.Azure.Management.Monitor.Models.AlertingAction
55-
Id : /subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/shrutika-rg/providers/microsoft.insights/scheduledqueryrules/LogAlertRulePSTest1
56-
Name : LogAlertRulePSTest1
55+
Id : /subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/MyResourceGroup/providers/microsoft.insights/scheduledqueryrules/LogAlertRule1
56+
Name : LogAlertRule1
5757
Type : microsoft.insights/scheduledqueryrules
5858
Location : centralindia
59-
Tags : {[hidden-link:/subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/shrutika-rg/providers/Microsoft.OperationalInsights/workspaces/shrutika-ws, Resource]}
59+
Tags : {[hidden-link:/subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/MyResourceGroup/providers/Microsoft.OperationalInsights/workspaces/MyWorkspace, Resource]}
6060
```
6161

6262
### Example 2 - Set by Input Object
6363
```powershell
64-
PS C:\> Set-AzScheduledQueryRule -InputObject $sqr -Description "change desc"
64+
PS C:\> Set-AzScheduledQueryRule -InputObject $sqr -Description "changed description"
6565
66-
Description : change desc
66+
Description : changed description
6767
Enabled : true
6868
LastUpdatedTime : 19-Apr-19 12:46:38 PM
6969
ProvisioningState : Succeeded
7070
Source : Microsoft.Azure.Management.Monitor.Models.Source
7171
Schedule : Microsoft.Azure.Management.Monitor.Models.Schedule
7272
Action : Microsoft.Azure.Management.Monitor.Models.AlertingAction
73-
Id : /subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/shrutika-rg/providers/microsoft.insights/scheduledqueryrules/LogAlertRulePSTest1
74-
Name : LogAlertRulePSTest1
73+
Id : /subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/MyResourceGroup/providers/microsoft.insights/scheduledqueryrules/LogAlertRule1
74+
Name : LogAlertRule1
7575
Type : microsoft.insights/scheduledqueryrules
7676
Location : centralindia
77-
Tags : {[hidden-link:/subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/shrutika-rg/providers/Microsoft.OperationalInsights/workspaces/shrutika-ws, Resource]}
77+
Tags : {[hidden-link:/subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/MyResourceGroup/providers/Microsoft.OperationalInsights/workspaces/MyWorkspace, Resource]}
7878
```
7979

8080
### Example 3 - Set by resource Id
8181
```powershell
82-
PS C:\> Set-AzScheduledQueryRule -ResourceId "/subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/shrutika-rg/providers/microsoft.insights/scheduledqueryrules/LogAlertRulePSTest1" -Enabled 1 -Location "centralindia" -Action $alertingAction -Description "change desc again" -Schedule $schedule -Source $source
82+
PS C:\> Set-AzScheduledQueryRule -ResourceId "/subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/MyResourceGroup/providers/microsoft.insights/scheduledqueryrules/LogAlertRule1" -Enabled $true -Location "centralindia" -Action $alertingAction -Description "change description again" -Schedule $schedule -Source $source
8383
84-
Description : change desc again
84+
Description : change description again
8585
Enabled : true
8686
LastUpdatedTime : 19-Apr-19 12:47:59 PM
8787
ProvisioningState : Succeeded
8888
Source : Microsoft.Azure.Management.Monitor.Models.Source
8989
Schedule : Microsoft.Azure.Management.Monitor.Models.Schedule
9090
Action : Microsoft.Azure.Management.Monitor.Models.AlertingAction
91-
Id : /subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/shrutika-rg/providers/microsoft.insights/scheduledqueryrules/LogAlertRulePSTest1
92-
Name : LogAlertRulePSTest1
91+
Id : /subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/MyResourceGroup/providers/microsoft.insights/scheduledqueryrules/LogAlertRule1
92+
Name : LogAlertRule1
9393
Type : microsoft.insights/scheduledqueryrules
9494
Location : centralindia
95-
Tags : {[hidden-link:/subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/shrutika-rg/providers/Microsoft.OperationalInsights/workspaces/shrutika-ws, Resource]}
95+
Tags : {[hidden-link:/subscriptions/ad825170-845c-47db-8f00-11978947b089/resourceGroups/MyResourceGroup/providers/Microsoft.OperationalInsights/workspaces/MyWorkspace, Resource]}
9696
```
9797

9898
## PARAMETERS
@@ -170,7 +170,7 @@ Accept wildcard characters: False
170170
```
171171
172172
### -Enabled
173-
The azure alert state - valid values - true, false
173+
The azure alert state - valid values - $true, $false
174174
175175
```yaml
176176
Type: System.Boolean

0 commit comments

Comments
 (0)