Здравствуйте.
Пытаюсь настроить уведомления когда мой сервер упал.
Для этого делаю:
-создаю топик SNS
-делаю подписку на него (которую потом обязательно подтверждаю)
import boto.ec2.cloudwatch
import sys
import os
import boto.sns
os.environ['AWS_KEY'] = "xxxxx"
os.environ['AWS_SECRET'] = "xxxxx"
os.environ['AWS_REGION'] = "us-west-2"
def create_status_alarm(instance_id):
ec2_conn = boto.ec2.connect_to_region(
os.environ['AWS_REGION'],
aws_access_key_id=os.environ['AWS_KEY'],
aws_secret_access_key=os.environ['AWS_SECRET'])
cloudwatch_conn = boto.ec2.cloudwatch.connect_to_region(
os.environ['AWS_REGION'],
aws_access_key_id=os.environ['AWS_KEY'],
aws_secret_access_key=os.environ['AWS_SECRET'])
reservations = ec2_conn.get_all_instances(filters = {'instance-id': instance_id})
if reservations and reservations[0].instances:
instance = reservations[0].instances[0]
instance_name = instance.tags['Name']
else:
print "Invalid instance-id!"
sys.exit(1)
sns_conn = boto.sns.SNSConnection(aws_access_key_id = os.environ['AWS_KEY'], aws_secret_access_key = os.environ['AWS_SECRET'], region=boto.regioninfo.RegionInfo(name=os.environ['AWS_REGION'], endpoint='sns.%s.amazonaws.com' % os.environ['AWS_REGION']))
sns_topic = sns_conn.create_topic('qweqwe2')
topic_arn = sns_topic["CreateTopicResponse"]\
["CreateTopicResult"]\
["TopicArn"]
subscription = sns_conn.subscribe(topic_arn, "email", "xxxxxx@gmail.com")
print topic_arn
alarm = boto.ec2.cloudwatch.alarm.MetricAlarm(
connection = cloudwatch_conn,
name = instance_name + "checkfail2",
metric = 'StatusCheckFailed',
namespace = 'AWS/EC2',
statistic = 'Minimum',
comparison = '>',
description = 'status check for %s %s' % (instance_id, instance_name),
threshold = 0,
period = 60,
evaluation_periods = 2,
dimensions = {'InstanceId':instance_id},
alarm_actions = topic_arn,
ok_actions = topic_arn,
insufficient_data_actions = topic_arn)
cloudwatch_conn.put_metric_alarm(alarm)
if __name__ == '__main__':
if len(sys.argv) < 2:
print "Usage: create_status_alarm.py <instanceid>"
sys.exit(2)
create_status_alarm(sys.argv[1])
Что я делаю не так? Мой alarm постоянно попадает INSUFFICIENT_DATA.