def format_record()

in Solutions/AWSSCV-DashboardAlarms/Code/awsscv_alarm_to_chatter/awsscv_alarm_to_chatter.py [0:0]


def format_record(record):
    messageSegments = []

    messageSegments.extend([
        { 'markupType': 'Paragraph', 'type': 'MarkupBegin' },
        { 'markupType': 'Bold', 'type': 'MarkupBegin' },
        { 'text': record['Sns']['Subject'], 'type': 'Text'},
        { 'markupType': 'Bold', 'type': 'MarkupEnd' },
        { 'markupType': 'Paragraph', 'type': 'MarkupEnd' }
    ])

    try:
        message = json.loads(record['Sns']['Message'])

        trigger = message['Trigger']

        del message['Trigger']

        for key in message:
            value = message[key]

            messageSegments.extend([
                { 'markupType': 'Paragraph', 'type': 'MarkupBegin' },
                { 'text': '{} - {}'.format(key, value), 'type': 'Text' },
                { 'markupType': 'Paragraph', 'type': 'MarkupEnd' }
            ])

        messageSegments.extend([
            { 'text': 'Trigger', 'type': 'Text'},
            { 'markupType': 'UnorderedList', 'type': 'MarkupBegin' }
        ])

        for key in trigger:
            value = trigger[key]

            messageSegments.extend([
                { 'markupType': 'ListItem', 'type': 'MarkupBegin' },
                { 'text': '{} - {}'.format(key, value), 'type': 'Text' },
                { 'markupType': 'ListItem', 'type': 'MarkupEnd' }
            ])


        messageSegments.extend([
            { 'markupType': 'UnorderedList', 'type': 'MarkupEnd' }
        ])

    except Exception as e:
        message = record['Sns']['Message']

        messageSegments.extend([
            { 'markupType': 'Paragraph', 'type': 'MarkupBegin' },
            { 'text': 'Message - {}'.format(message), 'type': 'Text' },
            { 'markupType': 'Paragraph', 'type': 'MarkupEnd' }
        ])

    logger.debug(messageSegments)

    return messageSegments