Example #1
0
 def __init__(self,
              host,
              port,
              message_type="tcp",
              ttl=60,
              flush_threshold=10,
              bubble=False,
              filter=None,
              level=NOTSET):
     """
     :param host: riemann host
     :param port: riemann port
     :param message_type: selects transport. Currently available 'tcp' and 'udp'
     :param ttl: defines time to live in riemann
     :param flush_threshold: count of events after which we send to riemann
     """
     if riemann_client is None:
         raise NotImplementedError("The Riemann handler requires the riemann_client package") # pragma: no cover
     Handler.__init__(self, level, filter, bubble)
     self.host = host
     self.port = port
     self.ttl = ttl
     self.queue = []
     self.flush_threshold = flush_threshold
     if message_type == "tcp":
         self.transport = riemann_client.transport.TCPTransport
     elif message_type == "udp":
         self.transport = riemann_client.transport.UDPTransport
     elif message_type == "test":
         self.transport = riemann_client.transport.BlankTransport
     else:
         msg = ("Currently supported message types for RiemannHandler are: {0}. \
                 {1} is not supported."
                .format(",".join(["tcp", "udp", "test"]), message_type))
         raise RuntimeError(msg)
Example #2
0
 def __init__(self, application_name=None, record_limit=None,
              record_delta=None, level=NOTSET, filter=None, bubble=False):
     Handler.__init__(self, level, filter, bubble)
     LimitingHandlerMixin.__init__(self, record_limit, record_delta)
     if application_name is None:
         application_name = get_application_name()
     self.application_name = application_name
Example #3
0
    def __init__(self, host='127.0.0.1', port=6379, key='redis', extra_fields={},
                flush_threshold=128, flush_time=1, level=NOTSET, filter=None,
                password=False, bubble=True, context=None, push_method='rpush'):
        Handler.__init__(self, level, filter, bubble)
        try:
            import redis
            from redis import ResponseError
        except ImportError:
            raise RuntimeError('The redis library is required for '
                               'the RedisHandler')

        self.redis = redis.Redis(host=host, port=port, password=password, decode_responses=True)
        try:
            self.redis.ping()
        except ResponseError:
            raise ResponseError('The password provided is apparently incorrect')
        self.key = key
        self.extra_fields = extra_fields
        self.flush_threshold = flush_threshold
        self.queue = []
        self.lock = Lock()
        self.push_method = push_method

        #Set up a thread that flushes the queue every specified seconds
        self._stop_event = threading.Event()
        self._flushing_t = threading.Thread(target=self._flush_task,
                                            args=(flush_time, self._stop_event))
        self._flushing_t.daemon = True
        self._flushing_t.start()
Example #4
0
    def __init__(self, filename, format_string=None,
                 level=NOTSET, filter=None, bubble=False):

        Handler.__init__(self, level, filter, bubble)
        StringFormatterHandlerMixin.__init__(self, format_string)

        self.filename = filename
        self.lock_filename = filename + ".lock"
Example #5
0
 def __init__(self, uri, app_id='generic', level=NOTSET,
              filter=None, bubble=False, hash_salt=None, backend=None,
              **db_options):
     Handler.__init__(self, level, filter, bubble)
     if backend is None:
         backend = self._default_backend
     db_options['uri'] = uri
     self.set_backend(backend, **db_options)
     self.app_id = app_id
     self.hash_salt = hash_salt or app_id.encode('utf-8')
Example #6
0
    def __init__(self, uri=None, queue="logging", level=NOTSET, filter=None, bubble=False, context=None):
        Handler.__init__(self, level, filter, bubble)
        try:
            import kombu
        except ImportError:
            raise RuntimeError("The kombu library is required for " "the RabbitMQSubscriber.")
        if uri:
            connection = kombu.Connection(uri)

        self.queue = connection.SimpleQueue(queue)
Example #7
0
 def __init__(self, arguments, stdin_format=None,
              encoding='utf-8', level=NOTSET, filter=None,
              bubble=False):
     Handler.__init__(self, level, filter, bubble)
     self.encoding = encoding
     self._arguments = list(arguments)
     if stdin_format is not None:
         stdin_format = stdin_format
     self._stdin_format = stdin_format
     import subprocess
     self._subprocess = subprocess
Example #8
0
 def __init__(self, uri=None, level=NOTSET, filter=None, bubble=False):
     Handler.__init__(self, level, filter, bubble)
     try:
         import zmq
     except ImportError:
         raise RuntimeError('The pyzmq library is required for '
                            'the ZeroMQHandler.')
     #: the zero mq context
     self.context = zmq.Context()
     #: the zero mq socket.
     self.socket = self.context.socket(zmq.PUB)
     if uri is not None:
         self.socket.bind(uri)
Example #9
0
    def __init__(self, api_token, channel, level=NOTSET, format_string=None, filter=None,
                 bubble=False):

        Handler.__init__(self, level, filter, bubble)
        StringFormatterHandlerMixin.__init__(self, format_string)
        self.api_token = api_token

        try:
            from slacker import Slacker
        except ImportError:
            raise RuntimeError('The slacker library is required for '
                               'the SlackHandler.')

        self.channel = channel
        self.slack = Slacker(api_token)
Example #10
0
    def __init__(self, uri=None, level=NOTSET, filter=None, bubble=False, context=None, multi=False):
        Handler.__init__(self, level, filter, bubble)
        try:
            import zmq
        except ImportError:
            raise RuntimeError("The pyzmq library is required for " "the ZeroMQHandler.")
        #: the zero mq context
        self.context = context or zmq.Context()

        if multi:
            #: the zero mq socket.
            self.socket = self.context.socket(zmq.PUSH)
            if uri is not None:
                self.socket.connect(uri)
        else:
            #: the zero mq socket.
            self.socket = self.context.socket(zmq.PUB)
            if uri is not None:
                self.socket.bind(uri)
Example #11
0
    def __init__(self, consumer_key, consumer_secret, username,
                 password, level=NOTSET, format_string=None, filter=None,
                 bubble=False):
        Handler.__init__(self, level, filter, bubble)
        StringFormatterHandlerMixin.__init__(self, format_string)
        self.consumer_key = consumer_key
        self.consumer_secret = consumer_secret
        self.username = username
        self.password = password

        try:
            import oauth2
        except ImportError:
            raise RuntimeError('The python-oauth2 library is required for '
                               'the TwitterHandler.')

        self._oauth = oauth2
        self._oauth_token = None
        self._oauth_token_secret = None
        self._consumer = oauth2.Consumer(consumer_key,
                                         consumer_secret)
        self._client = oauth2.Client(self._consumer)
Example #12
0
 def __init__(self, handler, action_level=ERROR, buffer_size=0,
              pull_information=True, filter=None, bubble=False):
     Handler.__init__(self, NOTSET, filter, bubble)
     self.lock = Lock()
     self._level = action_level
     if isinstance(handler, Handler):
         self._handler = handler
         self._handler_factory = None
     else:
         self._handler = None
         self._handler_factory = handler
     #: the buffered records of the handler.  Once the action is triggered
     #: (:attr:`triggered`) this list will be None.  This attribute can
     #: be helpful for the handler factory function to select a proper
     #: filename (for example time of first log record)
     self.buffered_records = deque()
     #: the maximum number of entries in the buffer.  If this is exhausted
     #: the oldest entries will be discarded to make place for new ones
     self.buffer_size = buffer_size
     self._buffer_full = False
     self._pull_information = pull_information
     self._action_triggered = False
Example #13
0
 def pop_greenlet(self):
     Handler.pop_greenlet(self)
     self.flush()
Example #14
0
 def pop_thread(self):
     Handler.pop_thread(self)
     self.flush()
Example #15
0
 def pop_application(self):
     Handler.pop_application(self)
     self.flush()
Example #16
0
 def __init__(self,
              format_string='message repeated {count} times: {message}',
              *args, **kwargs):
     Handler.__init__(self, bubble=False, *args, **kwargs)
     self._format_string = format_string
     self.clear()
Example #17
0
 def __init__(self, exc_type, level=NOTSET, format_string=None,
              filter=None, bubble=False):
     Handler.__init__(self, level, filter, bubble)
     StringFormatterHandlerMixin.__init__(self, format_string)
     self.exc_type = exc_type
Example #18
0
 def __init__(self, callback):
     Handler.__init__(self, level=logbook.ERROR)
     self.callback = callback
Example #19
0
 def __init__(self, hash_salt, level=NOTSET, filter=None, bubble=False):
     Handler.__init__(self, level, filter, bubble)
     self.hash_salt = hash_salt
Example #20
0
 def __init__(self, channel, level=NOTSET, filter=None, bubble=False):
     Handler.__init__(self, level, filter, bubble)
     self.channel = channel
Example #21
0
 def __init__(self, queue, level=NOTSET, filter=None, bubble=False):
     Handler.__init__(self, level, filter, bubble)
     self.queue = queue
     _fix_261_mplog()
Example #22
0
 def __init__(self, queue, level=NOTSET, filter=None, bubble=False):
     Handler.__init__(self, level, filter, bubble)
     self.queue = queue
     _fix_261_mplog()
 def pop_thread(self):
     Handler.pop_thread(self)
     self.flush()
Example #24
0
 def __init__(self, handlers):
     Handler.__init__(self)
     self.handlers = handlers
Example #25
0
 def __setattr__(self, name, value):
     if name in self._direct_attrs:
         return Handler.__setattr__(self, name, value)
     setattr(self.handler, name, value)
Example #26
0
 def pop_greenlet(self):
     Handler.pop_greenlet(self)
     self.flush()
Example #27
0
 def __init__(self, channel, level=NOTSET, filter=None, bubble=False):
     Handler.__init__(self, level, filter, bubble)
     self.channel = channel
 def pop_application(self):
     Handler.pop_application(self)
     self.flush()
 def __init__(self, handlers, filter=None, bubble=False):
     Handler.__init__(self, NOTSET, filter, bubble)
     assert isinstance(handlers, dict)
     self._handlers = dict(
         (tag, isinstance(handler, Handler) and [handler] or handler)
         for (tag, handler) in iteritems(handlers))
Example #30
0
    def __init__(self, format_string=None, record_limit=None, record_delta=None,
                 level=NOTSET, filter=None, bubble=False):

        Handler.__init__(self, level, filter, bubble)
        StringFormatterHandlerMixin.__init__(self, format_string)
        LimitingHandlerMixin.__init__(self, record_limit, record_delta)
Example #31
0
 def __init__(self, handlers, filter=None, bubble=False):
     Handler.__init__(self, NOTSET, filter, bubble)
     assert isinstance(handlers, dict)
     self._handlers = dict(
         (tag, isinstance(handler, Handler) and [handler] or handler)
         for (tag, handler) in handlers.iteritems())
 def __init__(self, hash_salt, level=NOTSET, filter=None, bubble=False):
     Handler.__init__(self, level, filter, bubble)
     self.hash_salt = hash_salt