Esempio n. 1
0
 def _configure_scribe(self, host, port):
     self.socket = TSocket.TSocket(host=host, port=port)
     self.socket.setTimeout(1000)
     self.transport = TTransport.TFramedTransport(self.socket)
     self.protocol = TBinaryProtocol.TBinaryProtocolAccelerated(
         trans=self.transport, strictRead=False, strictWrite=False)
     self.client = scribe.Client(iprot=self.protocol, oprot=self.protocol)
Esempio n. 2
0
 def setup_mock_client(self):
     self.mox.StubOutClassWithMocks(TBinaryProtocol, "TBinaryProtocol")
     self.mock_protocol = TBinaryProtocol.TBinaryProtocol(
         trans=self.mock_transport, strictRead=False, strictWrite=False)
     self.mox.StubOutClassWithMocks(scribe, "Client")
     self.mock_client = scribe.Client(iprot=self.mock_protocol,
                                      oprot=self.mock_protocol)
Esempio n. 3
0
 def client(self):
     """Scribe client object."""
     if not self._client:
         protocol = TBinaryProtocol.TBinaryProtocol(trans=self.transport,
                                                    strictRead=False,
                                                    strictWrite=False)
         self._client = scribe.Client(iprot=protocol, oprot=protocol)
     return self._client
 def openConnection(self):
     socket = TSocket.TSocket(host=self.host, port=self.port)
     self.transport = TTransport.TFramedTransport(socket)
     protocol = TBinaryProtocol.TBinaryProtocol(trans=self.transport,
                                                strictRead=False,
                                                strictWrite=False)
     self.client = scribe.Client(protocol)
     self.transport.open()
Esempio n. 5
0
 def __init__(self, host, port, category=None):
     super(ScribeLogHandler, self).__init__()
     socket = TSocket.TSocket(host=host, port=port)
     self.transport = TTransport.TFramedTransport(socket)
     protocol = TBinaryProtocol.TBinaryProtocol(trans=self.transport,
                                                strictRead=False,
                                                strictWrite=False)
     self.client = scribe.Client(iprot=protocol, oprot=protocol)
     self.category = category
Esempio n. 6
0
 def connect(self, host, port):
     socket = TSocket.TSocket(host=host, port=port)
     self.transport = TTransport.TFramedTransport(socket)
     protocol = TBinaryProtocol.TBinaryProtocol(trans=self.transport,
                                                strictRead=False,
                                                strictWrite=False)
     self.client = scribe.Client(iprot=protocol, oprot=protocol)
     self.connected = 1
     self.thriftEx = TTransport.TTransportException()
Esempio n. 7
0
 def _connect(self):
     socket = TSocket.TSocket(self.host, self.port)
     self.transport = TTransport.TFramedTransport(socket)
     protocol = TBinaryProtocol.TBinaryProtocol(self.transport, False,
                                                False)
     self.scribe_client = scribe.Client(protocol)
     try:
         self.transport.open()
     except TTransport.TTransportException as e:
         warnings.warn(e.message)
Esempio n. 8
0
    def setupClients(self, sender_host, sender_port):
        socket = TSocket.TSocket(host=sender_host, port=sender_port)
        transport = TTransport.TFramedTransport(socket)
        protocol = TBinaryProtocol.TBinaryProtocol(trans=transport,
                                                   strictRead=False,
                                                   strictWrite=False)

        fb303_client = FacebookService.Client(protocol, protocol)
        scribe_client = scribe.Client(iprot=protocol, oprot=protocol)

        return fb303_client, scribe_client, transport
Esempio n. 9
0
 def __init__(self, host="127.0.0.1", port=1463, category=None):
     self.category = category
     self.host = host
     self.port = port
     self.socket = TSocket.TSocket(host=self.host, port=self.port)
     self.transport = TTransport.TFramedTransport(self.socket)
     self.protocol = TBinaryProtocol.TBinaryProtocol(trans=self.transport,
                                                     strictRead=False,
                                                     strictWrite=False)
     self.client = scribe.Client(iprot=self.protocol, oprot=self.protocol)
     self.transport.open()
Esempio n. 10
0
 def __init__(self, host, port, timeout=None, unix_socket=None):
     self._transObj = _Transport(host,
                                 port,
                                 timeout=timeout,
                                 unix_socket=unix_socket)
     self._protocol = TBinaryProtocol.TBinaryProtocol(
         trans=self._transObj.get_trans(),
         strictRead=False,
         strictWrite=False)
     self.client = scribe.Client(iprot=self._protocol, oprot=self._protocol)
     self._transObj.connect()
Esempio n. 11
0
    def __send_events(self):
        """Send all events
        """
        socket = TSocket.TSocket(host=self.scribeHost, port=self.scribePort)
        transport = TTransport.TFramedTransport(socket)
        protocol = TBinaryProtocol.TBinaryProtocol(trans=transport, strictRead=False, strictWrite=False)
        client = scribe.Client(iprot=protocol, oprot=protocol)

        transport.open()
        log.info('Sending %d messages from file %s to %s:%d', len(self.events), self.infile, self.scribeHost, self.scribePort)
        result = client.Log(messages=self.events)
        transport.close()

        return result
Esempio n. 12
0
    def run(self):
        category_name = getLocalIp() + "%" + self.handleFile.split(
            '/')[-2] + "%" + self.handleFile.split('/')[-1]
        socket = TSocket.TSocket(host=self.host, port=self.port)
        transport = TTransport.TFramedTransport(socket)
        protocol = TBinaryProtocol.TBinaryProtocol(trans=transport,
                                                   strictRead=False,
                                                   strictWrite=False)
        client = scribe.Client(iprot=protocol, oprot=protocol)

        try:
            transport.open()
        except Exception, e:
            syslog.syslog("%s\n" % e)
            sys.exit(2)
Esempio n. 13
0
  def scribe_error(*args, **kw):
    options = app.get_options()
    socket = TSocket.TSocket(host=options.twitter_common_scribe_host,
                             port=options.twitter_common_scribe_port)
    transport = TTransport.TFramedTransport(socket)
    protocol = TBinaryProtocol.TBinaryProtocol(trans=transport, strictRead=False, strictWrite=False)
    client = scribe.Client(iprot=protocol, oprot=protocol)
    value = BasicExceptionHandler.format(*args, **kw)
    log_entry = scribe.LogEntry(category=options.twitter_common_scribe_category,
      message=value)

    try:
      transport.open()
      result = client.Log(messages=[log_entry])
      transport.close()
      if result != scribe.ResultCode.OK:
        AppScribeExceptionHandler.log_error('Failed to scribe exception!')
    except TTransport.TTransportException:
      AppScribeExceptionHandler.log_error('Could not connect to scribe!')
Esempio n. 14
0
 def open(self):
     """
     UDP has no notion of open, we are just preparing the thrift transport
     """
     try:
         if not self._transport:
             socket = TSocket.TSocket(host=self._serverip,
                                      port=self._serverport)
             self._transport = TTransport.TFramedTransport(socket)
             protocol = TBinaryProtocol.TBinaryProtocol(
                 trans=self._transport, strictRead=False, strictWrite=False)
             self._client = scribe.Client(iprot=protocol, oprot=protocol)
         if not self._transport.isOpen():
             self._transport.open()
         return True
     except NameError:
         raise
     except Exception, ex:
         return False
Esempio n. 15
0
def screenshot_scribe(msg):
    try:
        socket = TSocket.TSocket(host=SCRIBE_HOST, port=SCRIBE_PORT)
        transport = TTransport.TFramedTransport(socket)
        protocol = TBinaryProtocol.TBinaryProtocol(trans=transport,
                                                   strictRead=False,
                                                   strictWrite=False)
        client = scribe.Client(protocol)
        transport.open()

        category = SCRIBE_CATEGORY
        log_entry = scribe.LogEntry(category, msg)
        result = client.Log(messages=[log_entry])
        if result == 0:
            return True
        else:
            return False
    except Exception as e:
        logging.error(e)
        return False
Esempio n. 16
0
def send_events(events, scribeHost, scribePort):
    """Send all specified events

    Keyword arguments:
    events -- list of LogEntry events to send
    scribeHost -- Scribe server to talk to
    scribePort -- Scribe server's port

    """
    socket = TSocket.TSocket(host=scribeHost, port=scribePort)
    transport = TTransport.TFramedTransport(socket)
    protocol = TBinaryProtocol.TBinaryProtocol(trans=transport, strictRead=False, strictWrite=False)
    client = scribe.Client(iprot=protocol, oprot=protocol)

    transport.open()
    log.info('Sending %d messages to %s:%d', len(events), scribeHost, scribePort)
    result = client.Log(messages=events)
    transport.close()

    return result
Esempio n. 17
0
def send_bi(host, port, category, message):
    assert message
    assert category

    if (message is None) or (category is None):
        return "error args"

    result = 0
    socket = TSocket.TSocket(host=host, port=port)
    socket.setTimeout(3000)
    transport = TTransport.TFramedTransport(socket)
    protocol = TBinaryProtocol.TBinaryProtocol(trans=transport,
                                               strictRead=False,
                                               strictWrite=False)
    client = scribe.Client(iprot=protocol, oprot=protocol)

    try:
        transport.open()
        log_entry = scribe.LogEntry(category=category, message=message)
        result = client.Log(messages=[log_entry])
    except Exception as e:
        result = "failed to write bilog"
        traceback.print_exc(file=sys.stdout)
    finally:
        try:
            transport.close()
        except Exception as e:
            result = "failed to close socket"
            traceback.print_exc(file=sys.stdout)

    if result == scribe.ResultCode.OK:
        result = "success for sending bi log"
    elif result == scribe.ResultCode.TRY_LATER:
        result = "try it later"
    else:
        result = "Unknown error code."

    return result
Esempio n. 18
0
import time

from scribe import scribe
from thrift.transport import TTransport, TSocket
from thrift.protocol import TBinaryProtocol

NB_MSGS = 20

transportOut = TTransport.TMemoryBuffer()
protocolOut = TBinaryProtocol.TBinaryProtocol(transportOut)

timeInMilliSinceEpoch = int(time.time()) * 1000
logEntry = scribe.LogEntry("hello", str(timeInMilliSinceEpoch) + ":world")

socket = TSocket.TSocket(host='127.0.0.1', port=7911)
transport = TTransport.TFramedTransport(socket)
protocol = TBinaryProtocol.TBinaryProtocol(trans=transport,
                                           strictRead=False,
                                           strictWrite=False)
client = scribe.Client(iprot=protocol, oprot=protocol)

transport.open()
i = 0
print "Number of messages sent: ",
while i < NB_MSGS:
    result = client.Log(messages=[logEntry])
    print i, "..",
    i += 1
transport.close()
Esempio n. 19
0
    def _make_client(self):

        protocol = TBinaryProtocol.TBinaryProtocol(trans=self.transport,
                                                   strictRead=False,
                                                   strictWrite=False)
        self.client = scribe.Client(protocol)