2016-03-25 45 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') 

由于我们使用RDS这些实例并不EC2,我应该怎么办,发现没有“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 
相关问题