gpt4 book ai didi

amazon-cloudwatch - 重命名 Amazon CloudWatch 警报

转载 作者:行者123 更新时间:2023-12-01 09:28:10 26 4
gpt4 key购买 nike

我正在尝试组织大量 CloudWatch 警报以实现可维护性,并且 Web 控制台在编辑时将名称字段灰显。是否有另一种方法(最好是可编写脚本的)来更新 CloudWatch 警报的名称?除了简单的可执行脚本之外,我更喜欢不需要任何编程的解决方案。

最佳答案

这是我们暂时用来执行此操作的脚本:

import sys
import boto


def rename_alarm(alarm_name, new_alarm_name):
conn = boto.connect_cloudwatch()

def get_alarm():
alarms = conn.describe_alarms(alarm_names=[alarm_name])
if not alarms:
raise Exception("Alarm '%s' not found" % alarm_name)
return alarms[0]

alarm = get_alarm()

# work around boto comparison serialization issue
# https://github.com/boto/boto/issues/1311
alarm.comparison = alarm._cmp_map.get(alarm.comparison)

alarm.name = new_alarm_name
conn.update_alarm(alarm)

# update actually creates a new alarm because the name has changed, so
# we have to manually delete the old one
get_alarm().delete()

if __name__ == '__main__':
alarm_name, new_alarm_name = sys.argv[1:3]

rename_alarm(alarm_name, new_alarm_name)

它假设您位于具有允许此操作的角色的 ec2 实例上,或者您有一个包含凭据的 ~/.boto 文件。手动添加你的很容易。

关于amazon-cloudwatch - 重命名 Amazon CloudWatch 警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19501345/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com