Return event to CouchDB server
    Requires that configuration be enabled via 'event_return'
    option in master config.

    Example:

    event_return:
      - couchdb

def event_return(events):
    '''
    Return event to CouchDB server
    Requires that configuration be enabled via 'event_return'
    option in master config.

    Example:

    event_return:
      - couchdb

    '''
    log.debug('events data is: %s', events)

    options = _get_options()

    # Check to see if the database exists.
    _response = _request("GET", options['url'] + "_all_dbs")
    event_db = '{}-events'.format(options['db'])
    if event_db not in _response:

        # Make a PUT request to create the database.
        log.info('Creating database "%s"', event_db)
        _response = _request("PUT",
                             options['url'] + event_db,
                             user=options['user'],
                             passwd=options['passwd'])

        # Confirm that the response back was simple 'ok': true.
        if 'ok' not in _response or _response['ok'] is not True:
            log.error('Nothing logged! Lost data. Unable to create database "%s"', event_db)
            return
        log.info('Created database "%s"', event_db)

    for event in events:
        # Call _generate_doc to get a dict object of the document we're going to shove into the database.
        log.debug('event data is: %s', event)
        doc = _generate_event_doc(event)

        # Make the actual HTTP PUT request to create the doc.
        _response = _request("PUT",
                             options['url'] + event_db + "/" + doc['_id'],
                             'application/json',
                             salt.utils.json.dumps(doc))
        # Sanity check regarding the response..
        if 'ok' not in _response or _response['ok'] is not True:
            log.error('Nothing logged! Lost data. Unable to create document: "%s"', _response)