Skip to content

Commit cfb174f

Browse files
author
Mahak Jain
committed
Resolve PR comments
1 parent e0a4511 commit cfb174f

File tree

4 files changed

+113
-107
lines changed

4 files changed

+113
-107
lines changed

src/AlertsManagement/AlertsManagement/ActionRuleCommands/GetAzureActionRule.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,6 @@ public class GetAzureActionRule : AlertsManagementBaseCmdlet
9595
[Parameter(Mandatory = false,
9696
ParameterSetName = ListActionRulesParameterSet,
9797
HelpMessage = "Filter on Resource type of the target resource of alert.")]
98-
[Parameter(Mandatory = false,
99-
ParameterSetName = ListActionRulesByTargetResourceIdParameterSet,
100-
HelpMessage = "Filter on Resource type of the target resource of alert.")]
10198
[Parameter(Mandatory = false,
10299
ParameterSetName = ListActionRulesByTargetResourceGroupParameterSet,
103100
HelpMessage = "Filter on Resource type of the target resource of alert.")]

src/AlertsManagement/AlertsManagement/ActionRuleCommands/RemoveAzureActionRule.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Microsoft.Azure.Commands.AlertsManagement
2323
{
2424
[Cmdlet("Remove", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ActionRule", DefaultParameterSetName = ByNameParameterSet,
2525
SupportsShouldProcess = true)]
26-
[OutputType(typeof(string))]
26+
[OutputType(typeof(bool))]
2727
public class RemoveAzureActionRule : AlertsManagementBaseCmdlet
2828
{
2929
private const string ByInputObjectParameterSet = "ByInputObject";
@@ -69,6 +69,14 @@ public class RemoveAzureActionRule : AlertsManagementBaseCmdlet
6969
HelpMessage = "The action rule resource")]
7070
public PSActionRule InputObject { get; set; }
7171

72+
/// <summary>
73+
/// Gets or sets the PassThru switch parameter to force return an object when removing
74+
/// </summary>
75+
[Parameter(Mandatory = false,
76+
HelpMessage = "PassThru returns an object representing the item with which you are working."+
77+
" By default, this cmdlet does not generate any output.")]
78+
public SwitchParameter PassThru;
79+
7280
#endregion
7381

7482
protected override void ProcessRecordInternal()
@@ -88,9 +96,9 @@ protected override void ProcessRecordInternal()
8896
.Result.Body;
8997
}
9098

91-
if ((bool)isDeleted)
99+
if (PassThru.IsPresent)
92100
{
93-
WriteObject(string.Format("Successfully deleted the action rule: {0}", ResourceId));
101+
WriteObject(isDeleted);
94102
}
95103
break;
96104

@@ -106,10 +114,11 @@ protected override void ProcessRecordInternal()
106114
.Result.Body;
107115
}
108116

109-
if ((bool)isDeleted)
117+
if (PassThru.IsPresent)
110118
{
111-
WriteObject(string.Format("Successfully deleted the action rule: {0}", Name));
119+
WriteObject(isDeleted);
112120
}
121+
113122
break;
114123

115124
case ByNameParameterSet:
@@ -123,17 +132,12 @@ protected override void ProcessRecordInternal()
123132
.Result.Body;
124133
}
125134

126-
if ((bool)isDeleted)
135+
if (PassThru.IsPresent)
127136
{
128-
WriteObject(string.Format("Successfully deleted the action rule: {0}", Name));
137+
WriteObject(isDeleted);
129138
}
130139
break;
131140
}
132-
133-
if (!(bool)isDeleted)
134-
{
135-
WriteObject(string.Format("Couldn't delete the action rule. Please retry!"));
136-
}
137141
}
138142
}
139143
}

src/AlertsManagement/AlertsManagement/ActionRuleCommands/SetAzureActionRule.cs

Lines changed: 96 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -304,101 +304,106 @@ public class SetAzureActionRule : AlertsManagementBaseCmdlet
304304
protected override void ProcessRecordInternal()
305305
{
306306
PSActionRule actionRule = new PSActionRule();
307-
switch (ParameterSetName)
307+
if (ShouldProcess(
308+
target: string.Format("Create new Action Rule"),
309+
action: "Create the action rule"))
308310
{
309-
case BySimplifiedFormatActionGroupActionRuleParameterSet:
310-
if (ActionRuleType != "ActionGroup")
311-
{
312-
throw new PSInvalidOperationException("Incorrect Action Rule Type for given set of parameters. +" +
313-
"Use ActionGroup type for this parameter set.");
314-
}
315-
316-
// Create Action Rule
317-
ActionRule actionGroupAR = new ActionRule(
318-
location: "Global",
319-
tags: new Dictionary<string, string>(),
320-
properties: new ActionGroup(
321-
scope: ParseScope(),
322-
conditions: ParseConditions(),
323-
actionGroupId: ActionGroupId,
324-
description: Description,
325-
status: Status
326-
)
327-
);
328-
329-
actionRule = new PSActionRule(this.AlertsManagementClient.ActionRules.CreateUpdateWithHttpMessagesAsync(
330-
resourceGroupName: ResourceGroupName, actionRuleName: Name, actionRule: actionGroupAR).Result.Body);
331-
break;
332-
333-
case BySimplifiedFormatSuppressionActionRuleParameterSet:
334-
335-
if (ActionRuleType != "Suppression")
336-
{
337-
throw new PSInvalidOperationException("Incorrect Action Rule Type for given set of parameters. +" +
338-
"Use Suppression type for this parameter set.");
339-
}
340-
341-
SuppressionConfig config = new SuppressionConfig(recurrenceType: ReccurenceType);
342-
if (ReccurenceType != "Always")
343-
{
344-
config.Schedule = new SuppressionSchedule(
345-
startDate: SuppressionStartTime.Split(' ')[0],
346-
endDate: SuppressionEndTime.Split(' ')[0],
347-
startTime: SuppressionStartTime.Split(' ')[1],
348-
endTime: SuppressionEndTime.Split(' ')[1]
349-
);
350-
351-
if (ReccurentValue.Length > 0)
311+
switch (ParameterSetName)
312+
{
313+
case BySimplifiedFormatActionGroupActionRuleParameterSet:
314+
if (ActionRuleType != "ActionGroup")
352315
{
353-
//config.Schedule.RecurrenceValues = new List<int?>(ReccurentValue.ToList<int?>());
316+
throw new PSInvalidOperationException("Incorrect Action Rule Type for given set of parameters. +" +
317+
"Use ActionGroup type for this parameter set.");
318+
}
319+
320+
// Create Action Rule
321+
ActionRule actionGroupAR = new ActionRule(
322+
location: "Global",
323+
tags: new Dictionary<string, string>(),
324+
properties: new ActionGroup(
325+
scope: ParseScope(),
326+
conditions: ParseConditions(),
327+
actionGroupId: ActionGroupId,
328+
description: Description,
329+
status: Status
330+
)
331+
);
332+
333+
actionRule = new PSActionRule(this.AlertsManagementClient.ActionRules.CreateUpdateWithHttpMessagesAsync(
334+
resourceGroupName: ResourceGroupName, actionRuleName: Name, actionRule: actionGroupAR).Result.Body);
335+
break;
336+
337+
case BySimplifiedFormatSuppressionActionRuleParameterSet:
338+
339+
if (ActionRuleType != "Suppression")
340+
{
341+
throw new PSInvalidOperationException("Incorrect Action Rule Type for given set of parameters. +" +
342+
"Use Suppression type for this parameter set.");
354343
}
355-
}
356-
357-
// Create Action Rule
358-
ActionRule suppressionAR = new ActionRule(
359-
location: "Global",
360-
tags: new Dictionary<string, string>(),
361-
properties: new Suppression(
362-
scope: ParseScope(),
363-
conditions: ParseConditions(),
364-
description: Description,
365-
status: Status,
366-
suppressionConfig: config
367-
)
368-
);
369-
370-
actionRule = new PSActionRule(this.AlertsManagementClient.ActionRules.CreateUpdateWithHttpMessagesAsync(
371-
resourceGroupName: ResourceGroupName, actionRuleName: Name, actionRule: suppressionAR).Result.Body);
372-
break;
373-
374-
case BySimplifiedFormatDiagnosticsActionRuleParameterSet:
375-
if (ActionRuleType != "Diagnostics")
376-
{
377-
throw new PSInvalidOperationException("Incorrect Action Rule Type for given set of parameters. +" +
378-
"Use Diagnostics type for this parameter set.");
379-
}
380-
381-
// Create Action Rule
382-
ActionRule diagnosticsAR = new ActionRule(
383-
location: "Global",
384-
tags: new Dictionary<string, string>(),
385-
properties: new Diagnostics(
386-
scope: ParseScope(),
387-
conditions: ParseConditions(),
388-
description: Description,
389-
status: Status
390-
)
391-
);
392-
393-
actionRule = new PSActionRule(this.AlertsManagementClient.ActionRules.CreateUpdateWithHttpMessagesAsync(
394-
resourceGroupName: ResourceGroupName, actionRuleName: Name, actionRule: diagnosticsAR).Result.Body);
395-
396-
break;
397-
case ByInputObjectParameterSet:
398-
break;
399-
}
400344

401-
WriteObject(sendToPipeline: actionRule);
345+
SuppressionConfig config = new SuppressionConfig(recurrenceType: ReccurenceType);
346+
if (ReccurenceType != "Always")
347+
{
348+
config.Schedule = new SuppressionSchedule(
349+
startDate: SuppressionStartTime.Split(' ')[0],
350+
endDate: SuppressionEndTime.Split(' ')[0],
351+
startTime: SuppressionStartTime.Split(' ')[1],
352+
endTime: SuppressionEndTime.Split(' ')[1]
353+
);
354+
355+
if (ReccurentValue.Length > 0)
356+
{
357+
config.Schedule.RecurrenceValues = ReccurentValue.OfType<int?>().ToList();
358+
}
359+
}
360+
361+
// Create Action Rule
362+
ActionRule suppressionAR = new ActionRule(
363+
location: "Global",
364+
tags: new Dictionary<string, string>(),
365+
properties: new Suppression(
366+
scope: ParseScope(),
367+
conditions: ParseConditions(),
368+
description: Description,
369+
status: Status,
370+
suppressionConfig: config
371+
)
372+
);
373+
374+
actionRule = new PSActionRule(this.AlertsManagementClient.ActionRules.CreateUpdateWithHttpMessagesAsync(
375+
resourceGroupName: ResourceGroupName, actionRuleName: Name, actionRule: suppressionAR).Result.Body);
376+
break;
377+
378+
case BySimplifiedFormatDiagnosticsActionRuleParameterSet:
379+
if (ActionRuleType != "Diagnostics")
380+
{
381+
throw new PSInvalidOperationException("Incorrect Action Rule Type for given set of parameters. +" +
382+
"Use Diagnostics type for this parameter set.");
383+
}
384+
385+
// Create Action Rule
386+
ActionRule diagnosticsAR = new ActionRule(
387+
location: "Global",
388+
tags: new Dictionary<string, string>(),
389+
properties: new Diagnostics(
390+
scope: ParseScope(),
391+
conditions: ParseConditions(),
392+
description: Description,
393+
status: Status
394+
)
395+
);
396+
397+
actionRule = new PSActionRule(this.AlertsManagementClient.ActionRules.CreateUpdateWithHttpMessagesAsync(
398+
resourceGroupName: ResourceGroupName, actionRuleName: Name, actionRule: diagnosticsAR).Result.Body);
399+
400+
break;
401+
case ByInputObjectParameterSet:
402+
break;
403+
}
404+
405+
WriteObject(sendToPipeline: actionRule);
406+
}
402407
}
403408

404409
private Conditions ParseConditions()

src/AlertsManagement/AlertsManagement/ChangeLog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020

21-
## Version 1.0.0
21+
## Version 0.1.0
2222
* Preview of `Az.AlertsManagement` module
2323
* Powershell Cmdlets for Alerts Management Resource Provider to manage alerts, action rules and smart groups.
2424

0 commit comments

Comments
 (0)