Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-CWAlarm issue with CompositeAlarm #206

Open
1 task
zewar96 opened this issue Mar 20, 2021 · 7 comments
Open
1 task

Get-CWAlarm issue with CompositeAlarm #206

zewar96 opened this issue Mar 20, 2021 · 7 comments
Labels
bug This issue is a bug. module/powershell-cmdlets p2 This is a standard priority issue queued v5

Comments

@zewar96
Copy link

zewar96 commented Mar 20, 2021

Description

When running Get-CWAlarm -AlarmType "CompositeAlarm" I expect to receive all composite alarms created within my account. This actually returns no information from the call. However, when running the same command in the CLI it returns the 2 alarms

Reproduction Steps

Using version 4.1.9
Make sure you have at least 1 composite alarm setup in your account
Run:
Get-CWAlarm -AlarmType "CompositeAlarm"

I get no results. However, If i run:
aws cloudwatch describe-alarms --alarm-types "CompositeAlarm"
I get the 2 composite alarms i have setup

Running the powershell command with -AlarmType "MetricAlarm" returns all individual alarms without issue

Logs

I have enabled logging and was able to see the repsonse is actually returning the information in the repsonse (at least the first 1024 bytes), but for some reason the function doesn't return anything

Environment

  • Build Version: 4.1.9
  • OS Info: Windows 10
  • Build Environment:
  • Targeted .NET Platform:

Resolution

  • 👋 I can/would-like-to implement a fix for this problem myself

This is a 🐛 bug-report

@zewar96 zewar96 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 20, 2021
@ashishdhingra
Copy link
Contributor

ashishdhingra commented Mar 22, 2021

Get-CWAlarm -AlarmType @('CompositeAlarm', 'MetricAlarm') works but only returns metric alarms. Kindly note that -AlarmType is a string array.

The below C# code utilizing AWSSDK.CloudWatch, correctly returns the alarms in CompositeAlarms and MetricAlarms properties.

using System.Collections.Generic;
using Amazon.CloudWatch;
using Amazon.CloudWatch.Model;

namespace CloudWatchAlarmListTest
{
    class Program
    {
        static void Main(string[] args)
        {
            AmazonCloudWatchClient amazonCloudWatchClient = new AmazonCloudWatchClient();
            var result =  amazonCloudWatchClient.DescribeAlarmsAsync(new DescribeAlarmsRequest() {
                AlarmTypes = new List<string>() { "CompositeAlarm", "MetricAlarm" } }
            ).Result;
        }
    }
}

Not sure if PowerShell is considering both CompositeAlarms and MetricAlarms properties from the service response.

@ashishdhingra ashishdhingra removed the needs-triage This issue or PR still needs to be triaged. label Mar 22, 2021
@ashishdhingra
Copy link
Contributor

ashishdhingra commented Mar 25, 2021

Findings: (for Get-CWAlarm-Cmdlet)

Hence, CompositeAlarms returned by service are never returned in output.

Possible Solution
Change the Select delegate property for GetCWAlarmCmdlet::CmdletContext to:

public System.Func<Amazon.CloudWatch.Model.DescribeAlarmsResponse, GetCWAlarmCmdlet, object> Select { get; set; } =
        (response, cmdlet) =>
        {
            List<object> alarms = new List<object>();
            if (response.CompositeAlarms != null && response.CompositeAlarms.Count > 0) alarms.AddRange(response.CompositeAlarms);
            if (response.MetricAlarms != null && response.MetricAlarms.Count > 0) alarms.AddRange(response.MetricAlarms);

            return alarms;
        };

@ashishdhingra
Copy link
Contributor

Hi @zewar96,

Good afternoon.

Please try using the -Select parameter with value CompositeAlarm as a workaround and see if works. For example the below command selects the CompositeAlarms from output:

Get-CWAlarm  -AlarmType @('MetricAlarm', 'CompositeAlarm') -Select 'CompositeAlarms' 

OR

Get-CWAlarm  -AlarmType 'CompositeAlarm' -Select 'CompositeAlarms' 

In case you need to select both CompositeAlarms and MetricAlarms, use -Select with value *:

Get-CWAlarm  -AlarmType @('MetricAlarm', 'CompositeAlarm') -Select '*' 

This would return an object with CompositeAlarms and MetricAlarms properties.

Hope this helps.

Thanks,
Ashish

@zewar96
Copy link
Author

zewar96 commented Mar 25, 2021

@ashishdhingra This will work fine until the code is corrected. Thanks for the work around!

@github-actions
Copy link

We have noticed this issue has not received attention in 1 year. We will close this issue for now. If you think this is in error, please feel free to comment and reopen the issue.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Mar 27, 2022
@ashishdhingra
Copy link
Contributor

No close.

@github-actions github-actions bot removed the closing-soon This issue will automatically close in 4 days unless further comments are made. label Mar 28, 2022
@ashishdhingra ashishdhingra added queued p2 This is a standard priority issue and removed B labels Nov 2, 2022
@ashishdhingra
Copy link
Contributor

In monitoring.xml service model config, DescribeAlarms is configured with OutputProperty as MetricAlarms. CmdletSourceWriter uses WriteContextClass() method to use OutputProperty as part of Select delegate here.

To implement this breaking change:

  • Either we move this CmdLet from Basic to Advanced folder to hand-craft the logic. This should be excluded from generator process; OR
  • Support multiple output properties and generate the logic proposed in Get-CWAlarm issue with CompositeAlarm #206 (comment). However, we would somehow need to inspect the return type of output properties.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. module/powershell-cmdlets p2 This is a standard priority issue queued v5
Projects
None yet
Development

No branches or pull requests

2 participants