Cloudwatch Alarm Action Disable Tool

When I run cloudwatch alarmd on a daily basis, I sometimes want to disable ALM so that notifications don't skip. ALM cannot be disabled from the AWS console, it can be disabled using aws-cli as shown below.

aws cloudwatch disable-alarm-actions --alarm-name <The name of the alarm>

However, when there are hundreds of ALMs, the work is really difficult. .. .. I couldn't find a good tool, so I created it.

=> https://github.com/Gen-Arch/cwa

Since it is created with ruby, please prepare a ruby environment.

Installation

Since AWS authentication information is required in advance, create it with aws-cli. For details, see below https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html

aws configure

If you can use aws-cli, install it below

gem install cwa

Execution example

options

 $ >> cwa help
Commands:
  cwa alarms  --name ALARMNAME --regexp ALARMNAME --namespae NAMESPACE --dimensions KEY:VALUE  # show cloudwatch alms
  cwa disable --name ALARMNAME --regexp ALARMNAME --namespae NAMESPACE --dimensions KEY:VALUE  # disable cloudwatch alms
  cwa enable  --name ALARMNAME --regexp ALARMNAME --namespae NAMESPACE --dimensions KEY:VALUE  # enable cloudwatch alms
  cwa help [COMMAND]                                                                           # Describe available commands or one specific command

Options:
  [--verbose], [--no-verbose]

alm list output

 $ >> cwa alarm
+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+
| namespace | alarm_name | actions_enabled | dimensions                                                                                   | alarm_arn                                                      | alarm_description |
+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+
| AWS/EC2   | test-alm1  | true            | [#<struct Aws::CloudWatch::Types::Dimension name="InstanceId", value="i-0b19d505a7cc730cf">] | arn:aws:cloudwatch:ap-northeast-1:xxxxxxxxxxxx:alarm:test-alm1 |                   |
| AWS/EBS   | test-alm2  | true            | [#<struct Aws::CloudWatch::Types::Dimension name="VolumeId", value="vol-0051867abea8c09d7">] | arn:aws:cloudwatch:ap-northeast-1:xxxxxxxxxxxx:alarm:test-alm2 |                   |
+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+

Filter by name

 $ >> cwa alarm --name "test-alm1"
+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+
| namespace | alarm_name | actions_enabled | dimensions                                                                                   | alarm_arn                                                      | alarm_description |
+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+
| AWS/EC2   | test-alm1  | true            | [#<struct Aws::CloudWatch::Types::Dimension name="InstanceId", value="i-0b19d505a7cc730cf">] | arn:aws:cloudwatch:ap-northeast-1:xxxxxxxxxxxx:alarm:test-alm1 |                   |
+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+

Filter names by regular expression

 $ >> cwa alarm --regexp "^test.*"
+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+
| namespace | alarm_name | actions_enabled | dimensions                                                                                   | alarm_arn                                                      | alarm_description |
+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+
| AWS/EC2   | test-alm1  | true            | [#<struct Aws::CloudWatch::Types::Dimension name="InstanceId", value="i-0b19d505a7cc730cf">] | arn:aws:cloudwatch:ap-northeast-1:xxxxxxxxxxxx:alarm:test-alm1 |                   |
| AWS/EBS   | test-alm2  | true            | [#<struct Aws::CloudWatch::Types::Dimension name="VolumeId", value="vol-0051867abea8c09d7">] | arn:aws:cloudwatch:ap-northeast-1:xxxxxxxxxxxx:alarm:test-alm2 |                   |
+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+

Filter by namespace

 $ >> cwa alarm --namespace "AWS/EC2"
+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+
| namespace | alarm_name | actions_enabled | dimensions                                                                                   | alarm_arn                                                      | alarm_description |
+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+
| AWS/EC2   | test-alm1  | true            | [#<struct Aws::CloudWatch::Types::Dimension name="InstanceId", value="i-0b19d505a7cc730cf">] | arn:aws:cloudwatch:ap-northeast-1:xxxxxxxxxxxx:alarm:test-alm1 |                   |
+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+

Filter by dimensionsd

 $ >> cwa alarm --dimensions "InstanceId:i-0b19d505a7cc730cf"
+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+
| namespace | alarm_name | actions_enabled | dimensions                                                                                   | alarm_arn                                                      | alarm_description |
+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+
| AWS/EC2   | test-alm1  | true            | [#<struct Aws::CloudWatch::Types::Dimension name="InstanceId", value="i-0b19d505a7cc730cf">] | arn:aws:cloudwatch:ap-northeast-1:xxxxxxxxxxxx:alarm:test-alm1 |                   |
+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+

alm action change

Similar to the option that displayed alm is available Try to specify with --name in the example

Invalidation

 $ >> cwa disable --name "test-alm1"
--------------------------------------------------
namespace       : AWS/EC2
alarm_name      : test-alm1
dimensions      : [#<struct Aws::CloudWatch::Types::Dimension name="InstanceId", value="i-0b19d505a7cc730cf">]
actions_enabled : true
--------------------------------------------------
cloudwatch alarm disable? (yes|y/no) : y
done => test-alm1

+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+
| namespace | alarm_name | actions_enabled | dimensions                                                                                   | alarm_arn                                                      | alarm_description |
+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+
| AWS/EC2   | test-alm1  | false           | [#<struct Aws::CloudWatch::Types::Dimension name="InstanceId", value="i-0b19d505a7cc730cf">] | arn:aws:cloudwatch:ap-northeast-1:xxxxxxxxxxxx:alarm:test-alm1 |                   |
+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+

activation

 $ >> cwa enable --name "test-alm1"
--------------------------------------------------
namespace       : AWS/EC2
alarm_name      : test-alm1
dimensions      : [#<struct Aws::CloudWatch::Types::Dimension name="InstanceId", value="i-0b19d505a7cc730cf">]
actions_enabled : false
--------------------------------------------------
cloudwatch alarm enable? (yes|y/no) : y
done => test-alm1

+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+
| namespace | alarm_name | actions_enabled | dimensions                                                                                   | alarm_arn                                                      | alarm_description |
+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+
| AWS/EC2   | test-alm1  | true            | [#<struct Aws::CloudWatch::Types::Dimension name="InstanceId", value="i-0b19d505a7cc730cf">] | arn:aws:cloudwatch:ap-northeast-1:xxxxxxxxxxxx:alarm:test-alm1 |                   |
+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+

Remarks

Since it is created as a prototype version, please forgive it even if there are bugs. For the time being, I'm going to start operation with this

Recommended Posts

Cloudwatch Alarm Action Disable Tool