Listen to salt events and forward them to logstash.

    url
        The Logstash endpoint.

    funs: ``None``
        A list of functions to be compared against, looking into the ``fun``
        field from the event data. This option helps to select the events
        generated by one or more functions.
        If an event does not have the ``fun`` field in the data section, it
        will be published. For a better selection, consider using the ``tags``
        option.
        By default, this option accepts any event to be submitted to Logstash.

    tags: ``None``
        A list of pattern to compare the event tag against.
        By default, this option accepts any event to be submitted to Logstash.

def start(url, funs=None, tags=None):
    '''
    Listen to salt events and forward them to logstash.

    url
        The Logstash endpoint.

    funs: ``None``
        A list of functions to be compared against, looking into the ``fun``
        field from the event data. This option helps to select the events
        generated by one or more functions.
        If an event does not have the ``fun`` field in the data section, it
        will be published. For a better selection, consider using the ``tags``
        option.
        By default, this option accepts any event to be submitted to Logstash.

    tags: ``None``
        A list of pattern to compare the event tag against.
        By default, this option accepts any event to be submitted to Logstash.
    '''
    if __opts__.get('id').endswith('_master'):
        instance = 'master'
    else:
        instance = 'minion'
    event_bus = salt.utils.event.get_event(instance,
                                           sock_dir=__opts__['sock_dir'],
                                           transport=__opts__['transport'],
                                           opts=__opts__)
    while True:
        event = event_bus.get_event(full=True)
        if event:
            publish = True
            if tags and isinstance(tags, list):
                found_match = False
                for tag in tags:
                    if fnmatch.fnmatch(event['tag'], tag):
                        found_match = True
                publish = found_match
            if funs and 'fun' in event['data']:
                if not event['data']['fun'] in funs:
                    publish = False
            if publish:
                _logstash(url, event['data'])