0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

CloudwatchAlarmのアクション無効化ツール

Last updated at Posted at 2020-10-03

cloudwatch alarmdを日々運用してると、たまにALMを無効化して通知がとばないようにしたいと思うことがある。
ALMの無効化はAWSコンソール上からではできず、下記の様にaws-cliを使用して無効化が可能

aws cloudwatch disable-alarm-actions --alarm-name <アラームの名前>

だが、ALM数が数百個等あるとさすがに作業がしんどい。。。
ぐぐってもよさげなツールが見つからなかったので作成した。

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

rubyで作成してるのでruby環境を用意してください。

インストール

事前にAWSの認証情報が必要な為、aws-cliで作成します。
詳しくは下記
https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html

aws configure

aws-cliが使用出来れば下記でインストール

gem install cwa

実行例

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一覧出力

 $ >> 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 |                   |
+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+

名前でフィルタ

 $ >> 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 |                   |
+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+

名前を正規表現でフィルタ

 $ >> 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 |                   |
+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+

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 |                   |
+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+

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アクション変更

almを表示させたオプションと同様のが使用可能
例で--nameで指定してみる

無効化

 $ >> 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 |                   |
+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+

有効化

 $ >> 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 |                   |
+-----------+------------+-----------------+----------------------------------------------------------------------------------------------+----------------------------------------------------------------+-------------------+

備考

試作版として作成してるのでバグ等あってもゆるしてください。
ひとまずはこれで運用開始してみようと思う
※随時アップデート予定

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?