我正在尝试建立一个警报系统,如果某些实例没有警报,该系统将发送电子邮件。但对于某些测试实例,我不希望它们包含在内,因此我将在其中添加“NoAlarms”标签。我想在我现有的 python 脚本中添加此功能。
这基本上就是我现在所拥有的。
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”标签的实例?
最佳答案
这样的东西有用吗?
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
关于python - 如何使用python获取所有没有特定标签的mysql实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36223377/