2017-03-12 6 views
-2

私はAWSにいくつかの既存のCloudWatchのアラームを持って、私は正常にそれらをexractedとdictsのリストにそれらを格納していますbotoを使って既存のクラウドウォッチALARMを更新するには?次のように

[ { '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値持っている:

thershold_db_t2_medium = 309 # 99% of 312 
thershold_db_m3_medium = 316 # 99% of 320 
thershold_db_m3_large = 633 # 99% of 640 
thershold_db_m3_xlarge = 1267 # 99% of 1280 
thershold_db_m3_2xlarge= 2534 # 99% of 2560 
thershold_db_m4_large = 675 # 99% of 682 
thershold_db_m4_xlarge = 1351 # 99% of 1365 
thershold_db_m4_2xlarge= 2703 # 99% of 2730 

を私は次のアラームに

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' 

どのようにすればいいですか?

+0

小文字: 'each_dict ['rds_type'] ==" db.m2.medium "とeach_dict ['alarm_threshold']!= thershold_db_t2_medium:'それはm2とt2を比較しています。また、 "しきい値"ではなく "thershold"のインスタンスがいくつかあります。 –

+0

また、 'comparison'ではなく' comparision'です。 –

+0

ああ、申し訳ありません。とった – Kittystone

答えて

0

update_alarm()関数は、MetricAlarmオブジェクトを入力として受け取ります。ところで

from boto.ec2.cloudwatch import MetricAlarm 
scale_up_alarm = MetricAlarm(
      name='scale_up_on_cpu', namespace='AWS/EC2', 
      metric='CPUUtilization', statistic='Average', 
      comparison='>', threshold='70', 
      period='60', evaluation_periods=2, 
      alarm_actions=[scale_up_policy.policy_arn], 
      dimensions=alarm_dimensions) 
cloudwatch.create_alarm(scale_up_alarm) 

it appears thatupdate_alarm()エラーメッセージがそのfuncitonと述べた理由であるput_metric_alarm()の別名である:ここでboto documentationの例です。ここで

update_alarm()を呼び出して、私のために働いていたものです:

c.update_alarm(MetricAlarm(
      name='hello', namespace='AWS/EC2', 
      metric='CPUUtilization', statistic='Average', 
      comparison='<', threshold='60', 
      period='60', evaluation_periods=2 
      )) 

したがって、あなたのコードがに更新する必要があります。それはあなたのエラーの原因ではないですが、FYIあなたが持っている

c.update_alarm(MetricAlarm(
      name=each_dict['alarm_name'], 
      comparison='>=', 
      threshold=threshold_db_m3_medium, 
      period=300, 
      evaluation_periods=3, 
      statistic='Maximum' 
      )) 
関連する問題