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