# -*- coding: utf-8 -*-
'''
An engine that reads messages from the salt event bus and pushes
them onto a logstash endpoint.

.. versionadded: 2015.8.0

:configuration:

    Example configuration
        engines:
          - logstash:
            host: log.my_network.com
            port: 5959

:depends: logstash
'''

# Import python libraries
from __future__ import absolute_import
import logging

# Import salt libs
import salt.utils.event

# Import third-party libs
try:
    import logstash
    HAS_LOGSTASH = True
except ImportError:
    HAS_LOGSTASH = False


def __virtual__():
    if not HAS_LOGSTASH:
        return False
    else:
        return True

log = logging.getLogger(__name__)


def start(host, port=5959, tag='salt/engine/logstash'):
    '''
    Listen to salt events and forward them to logstash
    '''
    logstash_logger = logging.getLogger('python-logstash-logger')
    logstash_logger.setLevel(logging.INFO)
    logstash_logger.addHandler(logstash.LogstashHandler(host, port, version=1))

    if __opts__.get('id').endswith('_master'):
        event_bus = salt.utils.event.get_master_event(
                __opts__,
                __opts__['sock_dir'],
                listen=True)
    else:
        event_bus = salt.utils.event.get_event(
            'minion',
            transport=__opts__['transport'],
            opts=__opts__,
            sock_dir=__opts__['sock_dir'],
            listen=True)
        log.debug('Logstash engine started')

    while True:
        event = event_bus.get_event()
        if event:
            logstash_logger.info(tag, extra=event)

@@ -286,16 +286,39 @@
 rt: 5959
+%0A            proto: tcp
 %0A%0A:depen
@@ -740,16 +740,29 @@
 rt=5959,
+ proto='tcp',
  tag='sa
@@ -850,24 +850,182 @@
 ash%0A    '''%0A
+%0A    if proto == 'tcp':%0A        logstashHandler = logstash.TCPLogstashHandler%0A    elif proto == 'udp':%0A        logstashHandler = logstash.UDPLogstashHandler%0A%0A
     logstash
@@ -1121,16 +1121,16 @@
 g.INFO)%0A
+
     logs
@@ -1164,17 +1164,8 @@
 tash
-.Logstash
 Hand

Add ip protocol to logstash engine