如何使用python获取所有没有特定标记的mysql实例?

2024-05-28 20:53:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图建立一个报警系统,将发送电子邮件,如果有些情况下没有报警。但对于一些测试实例,我不希望它们包括在内,因此我将在其中添加一个“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')

由于我们对这些实例而不是EC2使用RDS,我应该如何查找所有没有“NoAlarms”标记的实例


Tags: instances实例from标记import报警ec2boto
1条回答
网友
1楼 · 发布于 2024-05-28 20:53:14

你喜欢这个工作吗

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

相关问题 更多 >

    热门问题