%PDF- %PDF-
| Direktori : /lib/python2.7/site-packages/salt/log/handlers/ |
| Current File : //lib/python2.7/site-packages/salt/log/handlers/logstash_mod.pyo |
�
���^c @@ s= d Z d d l m Z m Z m Z d d l Z d d l Z d d l Z d d l Z d d l m
Z
d d l m Z d d l
Z d d l Z d d l m Z y d d l Z Wn e k
r� n Xe j e � Z d Z d � Z d � Z d
e j e f d � � YZ d e j j f d
� � YZ d e j e f d � � YZ d S( u�
Logstash Logging Handler
========================
.. versionadded:: 0.17.0
This module provides some `Logstash`_ logging handlers.
UDP Logging Handler
-------------------
For versions of `Logstash`_ before 1.2.0:
In the salt configuration file:
.. code-block:: yaml
logstash_udp_handler:
host: 127.0.0.1
port: 9999
version: 0
msg_type: logstash
In the `Logstash`_ configuration file:
.. code-block:: text
input {
udp {
type => "udp-type"
format => "json_event"
}
}
For version 1.2.0 of `Logstash`_ and newer:
In the salt configuration file:
.. code-block:: yaml
logstash_udp_handler:
host: 127.0.0.1
port: 9999
version: 1
msg_type: logstash
In the `Logstash`_ configuration file:
.. code-block:: text
input {
udp {
port => 9999
codec => json
}
}
Please read the `UDP input`_ configuration page for additional information.
ZeroMQ Logging Handler
----------------------
For versions of `Logstash`_ before 1.2.0:
In the salt configuration file:
.. code-block:: yaml
logstash_zmq_handler:
address: tcp://127.0.0.1:2021
version: 0
In the `Logstash`_ configuration file:
.. code-block:: text
input {
zeromq {
type => "zeromq-type"
mode => "server"
topology => "pubsub"
address => "tcp://0.0.0.0:2021"
charset => "UTF-8"
format => "json_event"
}
}
For version 1.2.0 of `Logstash`_ and newer:
In the salt configuration file:
.. code-block:: yaml
logstash_zmq_handler:
address: tcp://127.0.0.1:2021
version: 1
In the `Logstash`_ configuration file:
.. code-block:: text
input {
zeromq {
topology => "pubsub"
address => "tcp://0.0.0.0:2021"
codec => json
}
}
Please read the `ZeroMQ input`_ configuration page for additional
information.
.. admonition:: Important Logstash Setting
One of the most important settings that you should not forget on your
`Logstash`_ configuration file regarding these logging handlers is
``format``.
Both the `UDP` and `ZeroMQ` inputs need to have ``format`` as
``json_event`` which is what we send over the wire.
Log Level
.........
Both the ``logstash_udp_handler`` and the ``logstash_zmq_handler``
configuration sections accept an additional setting ``log_level``. If not
set, the logging level used will be the one defined for ``log_level`` in
the global configuration file section.
HWM
...
The `high water mark`_ for the ZMQ socket setting. Only applicable for the
``logstash_zmq_handler``.
.. admonition:: Inspiration
This work was inspired in `pylogstash`_, `python-logstash`_, `canary`_
and the `PyZMQ logging handler`_.
.. _`Logstash`: http://logstash.net
.. _`canary`: https://github.com/ryanpetrello/canary
.. _`pylogstash`: https://github.com/turtlebender/pylogstash
.. _`python-logstash`: https://github.com/vklochan/python-logstash
.. _`PyZMQ logging handler`: https://github.com/zeromq/pyzmq/blob/master/zmq/log/handlers.py
.. _`UDP input`: http://logstash.net/docs/latest/inputs/udp
.. _`ZeroMQ input`: http://logstash.net/docs/latest/inputs/zeromq
.. _`high water mark`: http://api.zeromq.org/3-2:zmq-setsockopt
i ( t absolute_importt print_functiont unicode_literalsN( t
LOG_LEVELS( t NewStyleClassMixIn( t sixu logstashc C@ s3 t d t k d t k g � s/ t j d � t St S( Nu logstash_udp_handleru logstash_zmq_handleru� None of the required configuration sections, 'logstash_udp_handler' and 'logstash_zmq_handler', were found in the configuration. Not loading the Logstash logging handlers module.( t anyt __opts__t logt tracet Falset __virtualname__( ( ( sB /usr/lib/python2.7/site-packages/salt/log/handlers/logstash_mod.pyt __virtual__� s c c@ s� d } } } d t k r t d j d d � } t d j d d � } t d j d d � } t d j d d � } | d k r� | d k r� t j d � q t d | d
| � } t | | � } | j | � | j t t d j d t j d d � � � | Vn d
t k r�t d
j d d � } t d
j d d � } t d
j d d � } | d k rjt j d � q�t d
| � } t
| d | �} | j | � | j t t d
j d t j d d � � � | Vn | d k r�| d k r�| d k r�t Vn d S( Nu logstash_udp_handleru hostu portu versioni u msg_typeu logstashu� The required 'logstash_udp_handler' configuration keys, 'host' and/or 'port', are not properly configured. Not configuring the logstash UDP logging handler.t msg_typet versionu log_levelu erroru logstash_zmq_handleru addressu hwmi� u� The required 'logstash_zmq_handler' configuration key, 'address', is not properly configured. Not configuring the logstash ZMQ logging handler.t zmq_hwm( t NoneR t getR t debugt LogstashFormattert DatagramLogstashHandlert setFormattert setLevelR t ZMQLogstashHanderR
( t hostt portt addressR R
t logstash_formattert udp_handlerR t zmq_handler( ( sB /usr/lib/python2.7/site-packages/salt/log/handlers/logstash_mod.pyt setup_handlers� sP
$R c B@ s8 e Z d d d d � Z d d � Z d � Z d � Z RS( u logstashi c C@ sY | | _ | | _ | | _ t | d j | � � | _ t t | � j d d d d � d S( Nu format_v{0}t fmtt datefmt( t msg_pathR
R t getattrt formatt superR t __init__R ( t selfR
R! R ( ( sB /usr/lib/python2.7/site-packages/salt/log/handlers/logstash_mod.pyR% s
c C@ s! t j j | j � j � d d S( Ni����u Z( t datetimet utcfromtimestampt createdt isoformat( R&