Post an event to the Datadog stream.

    CLI Example

    .. code-block:: bash

        salt-call datadog.post_event api_key='0123456789' \\
                                     app_key='9876543210' \\
                                     title='Salt Highstate' \\
                                     text="Salt highstate was run on $(salt-call grains.get id)" \\
                                     tags='["service:salt", "event:highstate"]'

    Required arguments

    :param title:   The event title. Limited to 100 characters.
    :param text:    The body of the event. Limited to 4000 characters. The text
                    supports markdown.

    Optional arguments

    :param date_happened:       POSIX timestamp of the event.
    :param priority:            The priority of the event ('normal' or 'low').
    :param host:                Host name to associate with the event.
    :param tags:                A list of tags to apply to the event.
    :param alert_type:          "error", "warning", "info" or "success".
    :param aggregation_key:     An arbitrary string to use for aggregation,
                                max length of 100 characters.
    :param source_type_name:    The type of event being posted.

def post_event(api_key=None,
               app_key=None,
               title=None,
               text=None,
               date_happened=None,
               priority=None,
               host=None,
               tags=None,
               alert_type=None,
               aggregation_key=None,
               source_type_name=None):
    '''
    Post an event to the Datadog stream.

    CLI Example

    .. code-block:: bash

        salt-call datadog.post_event api_key='0123456789' \\
                                     app_key='9876543210' \\
                                     title='Salt Highstate' \\
                                     text="Salt highstate was run on $(salt-call grains.get id)" \\
                                     tags='["service:salt", "event:highstate"]'

    Required arguments

    :param title:   The event title. Limited to 100 characters.
    :param text:    The body of the event. Limited to 4000 characters. The text
                    supports markdown.

    Optional arguments

    :param date_happened:       POSIX timestamp of the event.
    :param priority:            The priority of the event ('normal' or 'low').
    :param host:                Host name to associate with the event.
    :param tags:                A list of tags to apply to the event.
    :param alert_type:          "error", "warning", "info" or "success".
    :param aggregation_key:     An arbitrary string to use for aggregation,
                                max length of 100 characters.
    :param source_type_name:    The type of event being posted.
    '''
    _initialize_connection(api_key, app_key)
    if title is None:
        raise SaltInvocationError('title must be specified')
    if text is None:
        raise SaltInvocationError('text must be specified')
    if alert_type not in [None, 'error', 'warning', 'info', 'success']:
        # Datadog only supports these alert types but the API doesn't return an
        # error for an incorrect alert_type, so we can do it here for now.
        # https://github.com/DataDog/datadogpy/issues/215
        message = ('alert_type must be one of "error", "warning", "info", or '
                   '"success"')
        raise SaltInvocationError(message)

    ret = {'result': False,
           'response': None,
           'comment': ''}

    try:
        response = datadog.api.Event.create(title=title,
                                            text=text,
                                            date_happened=date_happened,
                                            priority=priority,
                                            host=host,
                                            tags=tags,
                                            alert_type=alert_type,
                                            aggregation_key=aggregation_key,
                                            source_type_name=source_type_name
                                           )
    except ValueError:
        comment = ('Unexpected exception in Datadog Post Event API '
                   'call. Are your keys correct?')
        ret['comment'] = comment
        return ret

    ret['response'] = response
    if 'status' in response.keys():
        ret['result'] = True
        ret['comment'] = 'Successfully sent event'
    else:
        ret['comment'] = 'Error in posting event.'
    return ret