2016-03-25 9 views
0

一部のインスタンスにアラームがない場合に電子メールを送信するアラームシステムを設定しようとしています。しかし、テストのインスタンスの中には、それらに含まれないようにするために、「NoAlarms」というタグを付けます。私は、私の存在するpythonスクリプトでこの機能を追加したいと思っています。pythonを使って特定のタグを持たないすべてのmysqlインスタンスを取得する方法は?

これは基本的に私が今持っているものです。

from RDSFunctions import GetListRDSEndpoints 
from RDSFunctions import GetListRDSIdentifiers 
from boto.ec2.cloudwatch import CloudWatchConnection 
from SMTPMail import SendSMTPMail 
from boto import ec2 
lst_instances = GetListRDSIdentifiers(accesskey, secretkey) 
lst_expected_alarms = [] 
for inst in lst_instances: 
    if "relprac" not in inst.lower(): 
     lst_expected_alarms.append(inst + ' - ' + 'CPUUtilization') 

我々はこれらのインスタンスではないEC2のためにRDSを使用しているので、私は「NoAlarms」タグを持たないすべてのインスタンスを見つけるために何をすべきでしょうか?

答えて

0

この作品のようですか?

import boto.ec2 

conn = boto.ec2.connect_to_region("your_region", accesskey, secretkey) 

lst_instances = conn.get_only_instances() #gets all instances 

for instance in lst_instances: 

    if instance.tags['NoAlarms']: #tags are a dictionary ie.['Name': 'NoAlarms'] 
     pass 
    else: 
     #add alarms 
関連する問題