# 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/protocol/opentsdb.py
# class OpenTSDBClient(object):
#     """Twisted ElasticSearch API
#     """
#     def __init__(self, url='http://localhost:4242', user=None, password=None):
#         self.url = url.rstrip('/')
#         self.user = user
#         self.password = password
# 
#     def _request(self, path, data=None, method='POST'):
#         headers = {}
#         if self.user:
#             authorization = b64encode('%s:%s' % (self.user, self.password)
#                                      ).decode()
#             headers['Authorization'] = ['Basic ' + authorization]
# 
#         return utils.HTTPRequest().getJson(
#             self.url + path, method, headers=headers, data=data.encode())
# 
#     def put(self, data):
#         """Put one or more metrics
#         """
#         return self._request('/api/put', json.dumps(data))


from twisted.internet import defer, task
from twisted.python import log
from duct.objects import Output
from duct.protocol.opentsdb import OpenTSDBClient
"""
.. module:: opentsdb
   :synopsis: OpenTSDB output

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



class OpenTSDB(Output):
    """OpenTSDB HTTP API output

    **Configuration arguments:**

    :param url: URL (default: http://localhost:4242)
    :type url: str
    :param maxsize: Maximum queue backlog size (default: 250000, 0 disables)
    :type maxsize: int
    :param maxrate: Maximum rate of documents added to index (default: 100)
    :type maxrate: int
    :param interval: Queue check interval in seconds (default: 1.0)
    :type interval: int
    :param user: Optional basic auth username
    :type user: str
    :param password: Optional basic auth password
    :type password: str
    :param debug: Log tracebacks from OpenTSDB
    :type debug: str
    """
    def __init__(self, *a):

# 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/protocol/opentsdb.py
# class OpenTSDBClient(object):
#     """Twisted ElasticSearch API
#     """
#     def __init__(self, url='http://localhost:4242', user=None, password=None):
#         self.url = url.rstrip('/')
#         self.user = user
#         self.password = password
# 
#     def _request(self, path, data=None, method='POST'):
#         headers = {}
#         if self.user:
#             authorization = b64encode('%s:%s' % (self.user, self.password)
#                                      ).decode()
#             headers['Authorization'] = ['Basic ' + authorization]
# 
#         return utils.HTTPRequest().getJson(
#             self.url + path, method, headers=headers, data=data.encode())
# 
#     def put(self, data):
#         """Put one or more metrics
#         """
#         return self._request('/api/put', json.dumps(data))


# Path: duct/outputs/opentsdb.py
from twisted.internet import defer, task
from twisted.python import log
from duct.objects import Output
from duct.protocol.opentsdb import OpenTSDBClient

"""
.. module:: opentsdb
   :synopsis: OpenTSDB output

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



class OpenTSDB(Output):
    """OpenTSDB HTTP API output

    **Configuration arguments:**

    :param url: URL (default: http://localhost:4242)
    :type url: str
    :param maxsize: Maximum queue backlog size (default: 250000, 0 disables)
    :type maxsize: int
    :param maxrate: Maximum rate of documents added to index (default: 100)
    :type maxrate: int
    :param interval: Queue check interval in seconds (default: 1.0)
    :type interval: int
    :param user: Optional basic auth username
    :type user: str
    :param password: Optional basic auth password
    :type password: str
    :param debug: Log tracebacks from OpenTSDB
    :type debug: str
    """
    def __init__(self, *a):

        Output.__init__(self, *a)