%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/log/handlers/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/log/handlers/logstash_mod.pyc

�
���^c@@s=dZddlmZmZmZddlZddlZddlZddlZddl	m
Z
ddlmZddl
ZddlZddlmZyddlZWnek
r�nXeje�ZdZd�Zd	�Zd
ejefd��YZdejjfd
��YZdejefd��YZ dS(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(tabsolute_importtprint_functiontunicode_literalsN(t
LOG_LEVELS(tNewStyleClassMixIn(tsixulogstashcC@s3tdtkdtkg�s/tjd�tStS(Nulogstash_udp_handlerulogstash_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.(tanyt__opts__tlogttracetFalset__virtualname__(((sB/usr/lib/python2.7/site-packages/salt/log/handlers/logstash_mod.pyt__virtual__�sc	c@s�d}}}dtkrtdjdd�}tdjdd�}tdjdd�}tdjdd�}|dkr�|dkr�tjd�qtd	|d
|�}t||�}|j|�|jt	tdjdtjdd���|Vnd
tkr�td
jdd�}td
jdd�}td
jdd�}|dkrjtjd�q�td
|�}t
|d|�}|j|�|jt	td
jdtjdd���|Vn|dkr�|dkr�|dkr�tVndS(Nulogstash_udp_handleruhostuportuversioniumsg_typeulogstashu�The required 'logstash_udp_handler' configuration keys, 'host' and/or 'port', are not properly configured. Not configuring the logstash UDP logging handler.tmsg_typetversionu	log_leveluerrorulogstash_zmq_handleruaddressuhwmi�u�The required 'logstash_zmq_handler' configuration key, 'address', is not properly configured. Not configuring the logstash ZMQ logging handler.tzmq_hwm(tNoneRtgetRtdebugtLogstashFormattertDatagramLogstashHandlertsetFormattertsetLevelRtZMQLogstashHanderR
(	thosttporttaddressRR
tlogstash_formattertudp_handlerRtzmq_handler((sB/usr/lib/python2.7/site-packages/salt/log/handlers/logstash_mod.pytsetup_handlers�sP





$RcB@s8eZdddd�Zdd�Zd�Zd�ZRS(ulogstashicC@sY||_||_||_t|dj|��|_tt|�jdddd�dS(Nuformat_v{0}tfmttdatefmt(	tmsg_pathR
RtgetattrtformattsuperRt__init__R(tselfR
R!R((sB/usr/lib/python2.7/site-packages/salt/log/handlers/logstash_mod.pyR%s
			cC@s!tjj|j�j�d dS(Ni����uZ(tdatetimetutcfromtimestamptcreatedt	isoformat(R&trecordR ((sB/usr/lib/python2.7/site-packages/salt/log/handlers/logstash_mod.pyt
formatTimescC@s�tjjj�}i|j|�d6i|jd6|jd6|jd6|jd6|j	d6|j
d6|jd6|jd	6d
6|j
�d6dj|j||j�d
6|d6|jd6dgd6|jd6}|jr�|j|j�|d
d<nx�tj|j�D]�\}}|d"kr$qn|dkrD||d
|<qnt|tjtttttf�r|||d
|<qnt|�|d
|<qWtjjj |�S(#Nu
@timestampu	levelnameuloggerulinenoupathnameuprocessu
threadNameufuncNameuprocessNameu@fieldsu@messageu
{0}://{1}/{2}u@sourceu@source_hostu@source_pathusaltu@tagsu@typeuexc_infouargsuasctimeucreateduexc_textufilenameuidulevelnoumoduleumsecsumessageumsgunameurelativeCreateduthread(uargsuasctimeucreateduexc_infouexc_textufilenameufuncNameuidu	levelnameulevelnoulinenoumoduleumsecsumsecsumessageumsgunameupathnameuprocessuprocessNameurelativeCreateduthreadu
threadName(!tsalttutilstnetworktget_fqhostnameR,t	levelnametnametlinenotpathnametprocesst
threadNametfuncNametprocessNamet
getMessageR#R
R!texc_infotformatExceptionRt	iteritemst__dict__Rt
isinstancetstring_typestbooltdicttfloattinttlisttreprtjsontdumps(R&R+Rtmessage_dicttkeytvalue((sB/usr/lib/python2.7/site-packages/salt/log/handlers/logstash_mod.pyt	format_v0sN











		$cC@skidd6|j|�d6tjjj�d6|jd6|jd6|jd6|jd6|j	d	6|j
d
6|jd6|jd6|j
�d
6dgd6|jd6}|jr�|j|j�|d<nx�tj|j�D]~\}}|dkr�q�n|dkr|||<q�nt|tjtttttf�rD|||<q�nt|�||<q�Wtjjj|�S( Niu@versionu
@timestampuhostu	levelnameuloggerulinenoupathnameuprocessu
threadNameufuncNameuprocessNameumessageusaltutagsutypeuexc_infouargsuasctimeucreateduexc_textufilenameuidulevelnoumoduleumsecsumsgunameurelativeCreateduthread(uargsuasctimeucreateduexc_infouexc_textufilenameufuncNameuidu	levelnameulevelnoulinenoumoduleumsecsumsecsumessageumsgunameupathnameuprocessuprocessNameurelativeCreateduthreadu
threadName(R,R-R.R/R0R1R2R3R4R5R6R7R8R9R
R:R;RR<R=RR>R?R@RARBRCRDRERFRG(R&R+RHRIRJ((sB/usr/lib/python2.7/site-packages/salt/log/handlers/logstash_mod.pyt	format_v1JsB










		
$
N(t__name__t
__module__R%RR,RKRL(((sB/usr/lib/python2.7/site-packages/salt/log/handlers/logstash_mod.pyRs	4RcB@seZdZd�ZRS(u'
    Logstash UDP logging handler.
    cC@s
|j|�S(N(R#(R&R+((sB/usr/lib/python2.7/site-packages/salt/log/handlers/logstash_mod.pyt
makePickle|s(RMRNt__doc__RO(((sB/usr/lib/python2.7/site-packages/salt/log/handlers/logstash_mod.pyRwsRcB@sAeZdZejdd�Zed��Zd�Zd�Z	RS(u'
    Logstash ZMQ logging handler.
    i�cC@sNtt|�jd|�d|_|_||_||_tj	�|_
dS(Ntlevel(R$RR%Rt_contextt
_publishert_addresst_zmq_hwmtostgetpidt_pid(R&RRQR((sB/usr/lib/python2.7/site-packages/salt/log/handlers/logstash_mod.pyR%�s
		cC@s�tj�}t|d�s+|j|kr�||_tj�|_|jjtj�|_	y|j	j
tj|j�WnCt
k
r�|j	j
tj|j�|j	j
tj|j�nX|j	j|j�n|j	S(Nu
_publisher(RVRWR"RXtzmqtContextRRtsockettPUBRSt
setsockopttHWMRUtAttributeErrortSNDHWMtRCVHWMtconnectRT(R&tcurrent_pid((sB/usr/lib/python2.7/site-packages/salt/log/handlers/logstash_mod.pyt	publisher�s	
cC@s#|j|�}|jj|�dS(N(R#Rdtsend(R&R+tformatted_object((sB/usr/lib/python2.7/site-packages/salt/log/handlers/logstash_mod.pytemit�scC@s�|jdk	r�t|jd�r4|jjd�q�t|dd�dk	rr|jjtjd�|jj	�n|jj
tkr�|jj�q�ndS(Nudestroyii�u
_publisheri�i�(
RRRthasattrtdestroyR"RSR]RYtLINGERtclosetclosedR
tterm(R&((sB/usr/lib/python2.7/site-packages/salt/log/handlers/logstash_mod.pyRk�s(
RMRNRPtloggingtNOTSETR%tpropertyRdRgRk(((sB/usr/lib/python2.7/site-packages/salt/log/handlers/logstash_mod.pyR�s
	(!RPt
__future__RRRRVRntlogging.handlersR'tsalt.log.setupRtsalt.log.mixinsRtsalt.utils.jsonR-tsalt.utils.networktsalt.extRRYtImportErrort	getLoggerRMRRRRt	FormatterRthandlerstDatagramHandlerRtHandlerR(((sB/usr/lib/python2.7/site-packages/salt/log/handlers/logstash_mod.pyt<module>�s*
	
	Fl	

Zerion Mini Shell 1.0