def handler(event, context):
    message_content = event['Records'][0]['Sns']
    message_data = json.loads(message_content['Message'])
    print(message_data)
    
    # sanity check
    if len(message_data) != 1:
        raise Exception('expected a single key/value pair')
    
    # extract the only key and value
    event_key, event_source = list(message_data.items())[0]
    
    # remove the 'ElastiCache:' portion
    event_name = event_key.split(':')[1]
    
    # put spaces between capital letters
    event_name = " ".join(event_name.split('(?=[A-Z])'))

    subject = "cache event in {}".format(event_source)
    message = "{} in cluster {}.".format(event_name, event_source)

    publish_event(
        source='ElastiCache',
        subject=subject,
        message=message,
        data={
            'event_name': event_name,
            'cache_cluster': event_source,
            'details': message_data,
        }
    )
def handler(event, context):
    print(event)

    event_source = event['source']
    event_type = event['detail-type']

    if event_source == 'aws.health':
        message = get_health_event_description(event)
        source = 'PersonalHealthDashboard'

    elif event_source == 'aws.ecs':
        message = get_ecs_event_description(event)
        source = 'ECS'

    else:
        message = get_generic_event_description(event)
        source = 'CloudWatchEvents'

    publish_event(source=source,
                  subject=event_type,
                  message=message,
                  data={
                      'resources': event['resources'],
                      'details': event['detail'],
                  })
def handler(event, context):
    message_content = event['Records'][0]['Sns']
    message_data = parse_message(message_content['Message'])
    print(message_data)

    # skip individual resource update events
    if message_data['ResourceType'] != 'AWS::CloudFormation::Stack':
        print('skipping non-stack resource')
        return

    status = message_data['ResourceStatus']
    stack_name = message_data['StackName']

    message = "Stack '{}' has entered state '{}'.".format(
        stack_name,
        status,
    )

    publish_event(source='CloudFormation',
                  subject='CloudFormation Event',
                  message=message,
                  data={
                      'status': status,
                      'stack_name': stack_name,
                      'details': message_data,
                  })
def handler(event, context):
    print(event)

    subject = event['detail-type']
    message = get_event_description(event)

    publish_event(source='PersonalHealthDashboard',
                  subject=subject,
                  message=message,
                  data={
                      'resources': event['resources'],
                      'details': event['detail'],
                  })
Example #5
0
def handler(event, context):
    print(event)

    subject = event['detail-type']
    message = get_event_description(event)
    
    publish_event(
        source='ECS',
        subject=subject,
        message=message,
        data={
            'details': event['detail'],
        }
    )
def handler(event, context):
    message_content = event['Records'][0]['Sns']
    message_data = parse_message(message_content['Message'])
    print(message_data)

    subject = message_content.get('Subject', 'ElasticBeanstalk Event')
    message = message_data.get('Message', '')

    publish_event(source='ElasticBeanstalk',
                  subject=subject,
                  message=message,
                  data={
                      'application_name': message_data['Application'],
                      'environment_name': message_data['Environment'],
                      'details': message_data,
                  })
def handler(event, context):
    message_content = event['Records'][0]['Sns']
    message_data = json.loads(message_content['Message'])
    subject = message_content.get('Subject', '')

    message = "Alarm '{}' is in state '{}'".format(
        message_data['AlarmName'],
        message_data['NewStateValue'],
    )

    publish_event(source='CloudWatch',
                  subject=subject,
                  message=message,
                  data={
                      'alarm_name': message_data['AlarmName'],
                      'alarm_state': message_data['NewStateValue'],
                      'details': message_data,
                  })
Example #8
0
def handler(event, context):
    message_data = json.loads(event['Records'][0]['Sns']['Message'])
    print(message_data)

    event_message = message_data.get('Event Message', '')
    database_name = message_data['Source ID']
    database_url = message_data['Identifier Link']

    eventID = message_data.get('Event ID', '').strip()
    last_hash = eventID.rfind('#')
    event_name = eventID[last_hash + 1:] if last_hash > 0 else None

    # try to make a relevant event name when there is none
    if event_name is None:
        if 'The free storage capacity for DB Instance:' in event_message:
            event_name = 'FreeStorageLow'
        else:
            event_name = '???'

    subject = "Database Event - {}".format(database_name)

    message = "{}\n{}".format(
        event_message,
        database_url,
    )

    if eventID:
        message += "\n\nSee {} for more information.".format(eventID)

    publish_event(source='RDS',
                  subject=subject,
                  message=message,
                  data={
                      'event_name': event_name,
                      'database_name': database_name,
                      'details': message_data
                  })
Example #9
0
def read_dict(conf_dict={}, filename="SWIM_config"):
    """

    Open and read a dictionary of key-value pairs from the file given by
    filename. Use the read-in values to augment or update the dictionary passed
    in, then return the new dictionary.

    """
    from utils import publish_event
    try:
        config_file = open(filename, "r")
        if config_file:
            line = config_file.readline().strip()
        else:
            line = ""
    except:
        message = "Unable to open config file " + filename
        publish_event(message, topic=FSP_log, action="halt_run")  # noqa: F821
        print(message)
        raise IOError("Unable to open config file in read_dict")

    try:
        while line:
            name, val = line.split("=")
            name = name.strip()
            val = val.strip()
            conf_dict[name] = val
            if config_file:
                line = config_file.readline().strip()
            else:
                line = ""
        config_file.close()
        return conf_dict
    except Exception as ex:
        print("Unable to augment conf_dict in read_dict: %s" % ex)
        raise IOError("Unable to augment conf_dict in read_dict")