我在AWS中有一些现有的cloudwatch警报,我已经成功地将它们提取并存储在dicts列表中,如下所示:
[ { 'alarm_name': u'emsclassicldap_db_connections',
'alarm_threshold': 200.0,
'rds_name': u'emsclassicldap',
'rds_type': u'db.m3.medium'},
{ 'alarm_name': u'smso-jenkins-40-shared_db_connections',
'alarm_threshold': 266.0,
'rds_name': u'smso-jenkins-40-shared',
'rds_type': u'db.m3.medium'},
{ 'alarm_name': u'smso-jenkins-master-shared_db_connections',
'alarm_threshold': 266.0,
'rds_name': u'smso-jenkins-master-shared',
'rds_type': u'db.m3.large'},
{ 'alarm_name': u'syd01-devops-deepali-shared_db_connections',
'alarm_threshold': 266.0,
'rds_name': u'syd01-devops-deepali-shared',
'rds_type': u'db.m3.medium'}]
以上是一个简单的清单,没有什么特别的。现在我发现上面的一些警报有一些错误的alarm_threshold
值,需要用以下标准正确的值进行更新:
我写了以下更新警报
my_region_list=['ap-southeast-2']
def final_compare_update(w):
for region in my_region_list:
c = boto.ec2.cloudwatch.connect_to_region(region)
for each_dict in w:
#print each_dict['rds_type']
if each_dict['rds_type']=="db.m2.medium" and each_dict['alarm_threshold'] != thershold_db_t2_medium:
c.update_alarm(name=each_dict['alarm_name'],comparision='>=',threshold=thershold_db_t2_medium, period=300, evaluation_periods=3,statistic='Maximum')
print "updated "+each_dict['alarm_name']
elif each_dict['rds_type']=="db.m3.medium" and each_dict['alarm_threshold'] != thershold_db_m3_medium:
c.update_alarm(name=each_dict['alarm_name'], comparision='>=', threshold=thershold_db_m3_medium,period=300, evaluation_periods=3, statistic='Maximum')
print "updated " + each_dict['alarm_name']
elif each_dict['rds_type'] == "db.m3.large" and each_dict['alarm_threshold'] != thershold_db_m3_large:
c.update_alarm(name=each_dict['alarm_name'], comparision='>=', threshold=thershold_db_m3_large, period=300,evaluation_periods=3, statistic='Maximum')
print "updated " + each_dict['alarm_name']
elif each_dict['rds_type'] == "db.m3.xlarge" and each_dict['alarm_threshold'] != thershold_db_m3_xlarge:
c.update_alarm(name=each_dict['alarm_name'], comparision='>=', threshold=thershold_db_m3_xlarge,period=300,evaluation_periods=3, statistic='Maximum')
print "updated " + each_dict['alarm_name']
elif each_dict['rds_type'] == "db.m3.2xlarge" and each_dict['alarm_threshold'] != thershold_db_m3_2xlarge:
c.update_alarm(name=each_dict['alarm_name'], comparision='>=', threshold=thershold_db_m3_2xlarge,period=300, evaluation_periods=3, statistic='Maximum')
print "updated " + each_dict['alarm_name']
elif each_dict['rds_type'] == "db.m4.large" and each_dict['alarm_threshold'] != thershold_db_m4_large:
c.update_alarm(name=each_dict['alarm_name'], comparision='>=', threshold=thershold_db_m4_large,period=300, evaluation_periods=3, statistic='Maximum')
print "updated " + each_dict['alarm_name']
elif each_dict['rds_type'] == "db.m4.xlarge" and each_dict['alarm_threshold'] != thershold_db_m4_xlarge:
c.update_alarm(name=each_dict['alarm_name'], comparision='>=', threshold=thershold_db_m4_xlarge,period=300, evaluation_periods=3, statistic='Maximum')
print "updated " + each_dict['alarm_name']
elif each_dict['rds_type'] == "db.m4.2xlarge" and each_dict['alarm_threshold'] != thershold_db_m4_2xlarge:
c.update_alarm(name=each_dict['alarm_name'], comparision='>=', threshold=thershold_db_m4_2xlarge,period=300, evaluation_periods=3, statistic='Maximum')
print "updated " + each_dict['alarm_name']
else:
print "Nothing was updated!"
这给我带来了一个错误:
Traceback (most recent call last):
File "update_alarm.py", line 128, in <module>
final = final_compare_update(w)
File "update_alarm.py", line 88, in final_compare_update
c.update_alarm(name=each_dict['alarm_name'], comparision='>=', threshold=thershold_db_m3_medium,period=300, evaluation_periods=3, statistic='Maximum')
TypeError: put_metric_alarm() got an unexpected keyword argument 'name'
怎么做?在
update_alarm()
函数接受一个MetricAlarm
对象作为输入。以下是来自boto documentation的示例:顺便说一下,it appears that}的别名,这就是错误消息提到该函数的原因。在
update_alarm()
是{下面是一个对我有效的方法,它叫
^{pr2}$update_alarm()
:因此,您的代码应更新为:
相关问题 更多 >
编程相关推荐