# Path: duct/protocol/riemann.py
# class RiemannProtobufMixin(object):
# class RiemannProtocol(Int32StringReceiver, RiemannProtobufMixin):
# class RiemannClientFactory(protocol.ReconnectingClientFactory):
# class RiemannUDP(DatagramProtocol, RiemannProtobufMixin):
#     def __init__(self):
#     def encodeEvent(self, event):
#     def encodeMessage(self, events):
#     def decodeMessage(self, data):
#     def sendEvents(self, events):
#     def stringReceived(self, string):
#     def __init__(self, hosts, failover=False):
#     def buildProtocol(self, addr):
#     def _do_failover(self, connector):
#     def clientConnectionLost(self, connector, reason):
#     def clientConnectionFailed(self, connector, reason):
#     def __init__(self, host, port):
#     def sendString(self, string):
# 
# Path: duct/objects.py
# class Output(object):
#     """Output parent class
# 
#     Outputs can inherit this object which provides a construct
#     for a working output
# 
#     :param config: Dictionary config for this queue (usually read from the
#              yaml configuration)
#     :param duct: A DuctService object for interacting with the queue manager
#     """
#     def __init__(self, config, duct):
#         self.config = config
#         self.duct = duct
#         self.events = []
#         self.maxsize = 0
# 
#     def createClient(self):
#         """Deferred which sets up the output
#         """
#         pass
# 
#     def eventsReceived(self, events):
#         """Receives a list of events and queues them
# 
#         Arguments:
#         events -- list of `duct.objects.Event`
#         """
#         # Make sure queue isn't oversized
#         if self.maxsize > 0:
#             if (self.maxsize < 1) or (len(self.events) < self.maxsize):
#                 self.events.extend(events)
#         else:
#             self.events.extend(events)
# 
#     def stop(self):
#         """Called when the service shuts down
#         """
#         pass


import time
import random
from twisted.internet import reactor, defer, task
from twisted.python import log
    from OpenSSL import SSL
    from twisted.internet import ssl
from duct.protocol import riemann
from duct.objects import Output
   :synopsis: Riemann output

.. moduleauthor:: Colin Alston <colin@imcol.in>
"""


# pylint: disable=C0412
try:
except:
    SSL = None



if SSL:
    class ClientTLSContext(ssl.ClientContextFactory):
        """SSL Context factory
        """
        def __init__(self, key, cert):
            self.key = key
            self.cert = cert

        def getContext(self):
            self.method = SSL.TLSv1_METHOD
            ctx = ssl.ClientContextFactory.getContext(self)
            ctx.use_certificate_file(self.cert)
            ctx.use_privatekey_file(self.key)

            return ctx



# Path: duct/protocol/riemann.py
# class RiemannProtobufMixin(object):
# class RiemannProtocol(Int32StringReceiver, RiemannProtobufMixin):
# class RiemannClientFactory(protocol.ReconnectingClientFactory):
# class RiemannUDP(DatagramProtocol, RiemannProtobufMixin):
#     def __init__(self):
#     def encodeEvent(self, event):
#     def encodeMessage(self, events):
#     def decodeMessage(self, data):
#     def sendEvents(self, events):
#     def stringReceived(self, string):
#     def __init__(self, hosts, failover=False):
#     def buildProtocol(self, addr):
#     def _do_failover(self, connector):
#     def clientConnectionLost(self, connector, reason):
#     def clientConnectionFailed(self, connector, reason):
#     def __init__(self, host, port):
#     def sendString(self, string):
# 
# Path: duct/objects.py
# class Output(object):
#     """Output parent class
# 
#     Outputs can inherit this object which provides a construct
#     for a working output
# 
#     :param config: Dictionary config for this queue (usually read from the
#              yaml configuration)
#     :param duct: A DuctService object for interacting with the queue manager
#     """
#     def __init__(self, config, duct):
#         self.config = config
#         self.duct = duct
#         self.events = []
#         self.maxsize = 0
# 
#     def createClient(self):
#         """Deferred which sets up the output
#         """
#         pass
# 
#     def eventsReceived(self, events):
#         """Receives a list of events and queues them
# 
#         Arguments:
#         events -- list of `duct.objects.Event`
#         """
#         # Make sure queue isn't oversized
#         if self.maxsize > 0:
#             if (self.maxsize < 1) or (len(self.events) < self.maxsize):
#                 self.events.extend(events)
#         else:
#             self.events.extend(events)
# 
#     def stop(self):
#         """Called when the service shuts down
#         """
#         pass


# Path: duct/outputs/riemann.py
import time
import random
from twisted.internet import reactor, defer, task
from twisted.python import log
    from OpenSSL import SSL
    from twisted.internet import ssl
from duct.protocol import riemann
from duct.objects import Output

   :synopsis: Riemann output

.. moduleauthor:: Colin Alston <colin@imcol.in>
"""


# pylint: disable=C0412
try:
except:
    SSL = None



if SSL:
    class ClientTLSContext(ssl.ClientContextFactory):
        """SSL Context factory
        """
        def __init__(self, key, cert):
            self.key = key
            self.cert = cert

        def getContext(self):
            self.method = SSL.TLSv1_METHOD
            ctx = ssl.ClientContextFactory.getContext(self)
            ctx.use_certificate_file(self.cert)
            ctx.use_privatekey_file(self.key)

            return ctx



class RiemannTCP(Output):