%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/fluent_mod.pyc

�
���^c@@s"dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZddlZddlmZeje�ZyFddlZejejddd	g�d
e�dkre�nWn[ek
rdyddlZWqeek
r`dZejjde�ej d
�qeXnXdZ!da"idd6dd6dd6d	d6dd6dd6dd6dd6Z#d�Z$d�Z%d�Z&d�Z'dej(efd ��YZ)d!ej*fd"��YZ+d#e,fd$��YZ-dS(%uX
    Fluent Logging Handler
    ======================

    .. versionadded:: 2015.8.0

    This module provides some fluentd_ logging handlers.


    Fluent Logging Handler
    ----------------------

    In the `fluent` configuration file:

    .. code-block:: text

        <source>
          type forward
          bind localhost
          port 24224
        </source>

    Then, to send logs via fluent in Logstash format, add the
    following to the salt (master and/or minion) configuration file:

    .. code-block:: yaml

        fluent_handler:
          host: localhost
          port: 24224

    To send logs via fluent in the Graylog raw json format, add the
    following to the salt (master and/or minion) configuration file:

    .. code-block:: yaml

        fluent_handler:
          host: localhost
          port: 24224
          payload_type: graylog
          tags:
          - salt_master.SALT

    The above also illustrates the `tags` option, which allows
    one to set descriptive (or useful) tags on records being
    sent.  If not provided, this defaults to the single tag:
    'salt'.  Also note that, via Graylog "magic", the 'facility'
    of the logged message is set to 'SALT' (the portion of the
    tag after the first period), while the tag itself will be
    set to simply 'salt_master'.  This is a feature, not a bug :)

    Note:
    There is a third emitter, for the GELF format, but it is
    largely untested, and I don't currently have a setup supporting
    this config, so while it runs cleanly and outputs what LOOKS to
    be valid GELF, any real-world feedback on its usefulness, and
    correctness, will be appreciated.

    Log Level
    .........

    The ``fluent_handler`` configuration section accepts 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.

    .. admonition:: Inspiration

        This work was inspired in `fluent-logger-python`_

    .. _fluentd: http://www.fluentd.org
    .. _`fluent-logger-python`: https://github.com/fluent/fluent-logger-python

i(tabsolute_importtprint_functiontunicode_literalsN(t
LOG_LEVELS(tNewStyleClassMixIn(tsixiiituse_listu[%(levelname)-8s] %(message)st
log_formatu7Unable to import msgpack or msgpack_pure python modulesufluentuEMERGuALERTuCRITuERRiuWARNINGiuNOTICEiuINFOiuDEBUGcK@s@|jdd�}|jdd�}t|d|d|�adS(Nuhostu	localhostuporti�^thosttport(tgettFluentSendert_global_sender(ttagtkwargsRR	((s@/usr/lib/python2.7/site-packages/salt/log/handlers/fluent_mod.pytsetup�scC@stS(N(R(((s@/usr/lib/python2.7/site-packages/salt/log/handlers/fluent_mod.pytget_global_sender�scC@s*tdtkg�s&tjd�tStS(Nufluent_handleru�The required configuration section, 'fluent_handler', was not found the in the configuration. Not loading the fluent logging handlers module.(tanyt__opts__tlogttracetFalset__virtualname__(((s@/usr/lib/python2.7/site-packages/salt/log/handlers/fluent_mod.pyt__virtual__�s
cc@s�d}}dtkrjtdjdd�}tdjdd�}tdjdd�}tdjddg�}|r�|dnd}|dkr�d}n1|d	kr�d
}nd}tdjdd
�}|dkr�|dkr�tjd�qjtd|d|d|�}t|d|d|�}|j|�|jt	tdjdtjdd���|Vn|dkr�|dkr�t
VndS(Nufluent_handleruhostuportupayload_typeutagsusaltiugraylogugelfg�������?ulogstashuversioniu�The required 'fluent_handler' configuration keys, 'host' and/or 'port', are not properly configured. Not enabling the fluent logging handler.tpayload_typetversionttagsRR	u	log_leveluerror(tNoneRR
RtdebugtMessageFormattert
FluentHandlertsetFormattertsetLevelRR(RR	RRR
Rt	formattertfluent_handler((s@/usr/lib/python2.7/site-packages/salt/log/handlers/fluent_mod.pytsetup_handlers�s0
		

'RcB@sGeZddd�Zdd�Zd�Zd�Zd�Zd�ZRS(cC@s�||_||_|r"|dnd|_||_|r@|n||_|rU|n||_dj||�jdd�}t||�|_t	t
|�jdddd�dS(Niusaltuformat_{0}_v{1}u.u_tfmttdatefmt(
RRR
Rtmsg_pathtmsg_typetformattreplacetgetattrtsuperRt__init__R(tselfRRRR'R&tformat_func((s@/usr/lib/python2.7/site-packages/salt/log/handlers/fluent_mod.pyR,�s			cC@s7|jdkr|jStjj|j�j�d dS(Nugelfi����uZ(Rtcreatedtdatetimetutcfromtimestampt	isoformat(R-trecordR%((s@/usr/lib/python2.7/site-packages/salt/log/handlers/fluent_mod.pyt
formatTime�scC@s
i|j�d6|j|�d6tj|jd�d6|jd6}|jru|j|j�}|ji|d6�nx�t	j
|j�D]z\}}|dkr�q�nt|t	j
ttttttjf�r�|}nt|�}|ji|dj|�6�q�W|S(u

        Graylog 'raw' format is essentially the raw record, minimally munged to provide
        the bare minimum that td-agent requires to accept and route the event.  This is
        well suited to a config where the client td-agents log directly to Graylog.
        umessageu	timestampuALERTulevelutagufull_messageuargsuasctimeubracketlevelubracketnameubracketprocessucreateduexc_infouexc_textuidu	levelnameulevelnoumsecsumsgurelativeCreateduversionu{0}(uargsuasctimeubracketlevelubracketnameubracketprocessucreateduexc_infouexc_textuidu	levelnameulevelnoumsecsumsecsumessageumsgurelativeCreateduversion(t
getMessageR4t
syslog_levelsR
t	levelnameR
texc_infotformatExceptiontupdateRt	iteritemst__dict__t
isinstancetstring_typestbooltdicttfloattinttlistttypestNoneTypetreprR((R-R3tmessage_dictR8tkeytvaluetval((s@/usr/lib/python2.7/site-packages/salt/log/handlers/fluent_mod.pytformat_graylog_v0�s$

		*	!cC@s'i|jd6tjjj�d6|j�d6|j|�d6tj|j	d�d6|j
d6}|jr�|j|j�}|j
i|d6�nx�tj|j�D]z\}}|dkr�q�nt|tjttttttjf�r�|}nt|�}|j
i|dj|�6�q�W|S(u�
        If your agent is (or can be) configured to forward pre-formed GELF to Graylog
        with ZERO fluent processing, this function is for YOU, pal...
        uversionuhostu
short_messageu	timestampuALERTulevelu_tagufull_messageuargsuasctimeubracketlevelubracketnameubracketprocessucreateduexc_infouexc_textuidu	levelnameulevelnoumsecsumessageumsgurelativeCreatedu_{0}(uargsuasctimeubracketlevelubracketnameubracketprocessucreateduexc_infouexc_textuidu	levelnameulevelnoumsecsumsecsumessageumsgurelativeCreateduversion(Rtsalttutilstnetworktget_fqhostnameR5R4R6R
R7R
R8R9R:RR;R<R=R>R?R@RARBRCRDRERFR((R-R3RGR8RHRIRJ((s@/usr/lib/python2.7/site-packages/salt/log/handlers/fluent_mod.pytformat_gelf_v1_1�s(


		*	!cC@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|jd6|jd6|jd6}|jr�|j|j�|d
d<nx�tj|j�D]�\}}|d!kr$qn|d"krD||d
|<qnt|tjtttttf�r|||d
|<qnt|�|d
|<qW|S(#uG
        Messages are formatted in logstash's expected format.
        u
@timestampu	levelnameuloggerulinenoupathnameuprocessu
threadNameufuncNameuprocessNameu@fieldsu@messageu
{0}://{1}/{2}u@sourceu@source_hostu@source_pathu@tagsu@typeuexc_infouargsuasctimeucreateduexc_textufilenameuidulevelnoumoduleumsecsumessageumsgunameurelativeCreateduthread(uargsuasctimeucreateduexc_infouexc_textufilenameufuncNameuidu	levelnameulevelnoulinenoumoduleumsecsumsecsumessageumsgunameupathnameuprocessuprocessNameurelativeCreateduthreadu
threadNameN( RLRMRNROR4R7tnametlinenotpathnametprocesst
threadNametfuncNametprocessNameR5R(R'R&RR8R9RR;R<RR=R>R?R@RARBRCRF(R-R3RRGRHRI((s@/usr/lib/python2.7/site-packages/salt/log/handlers/fluent_mod.pytformat_logstash_v0sN











		$cC@s\idd6|j|�d6tjjj�d6|jd6|jd6|jd6|jd6|j	d	6|j
d
6|jd6|jd6|j
�d
6|jd6|jd6}|jr�|j|j�|d<nx�tj|j�D]~\}}|dkr�q�n|dkr|||<q�nt|tjtttttf�rD|||<q�nt|�||<q�W|S( uG
        Messages are formatted in logstash's expected format.
        iu@versionu
@timestampuhostu	levelnameuloggerulinenoupathnameuprocessu
threadNameufuncNameuprocessNameumessageutagsutypeuexc_infouargsuasctimeucreateduexc_textufilenameuidulevelnoumoduleumsecsumsgunameurelativeCreateduthread(uargsuasctimeucreateduexc_infouexc_textufilenameufuncNameuidu	levelnameulevelnoulinenoumoduleumsecsumsecsumessageumsgunameupathnameuprocessuprocessNameurelativeCreateduthreadu
threadNameN(R4RLRMRNROR7RQRRRSRTRURVRWR5RR'R8R9RR;R<RR=R>R?R@RARBRCRF(R-R3RGRHRI((s@/usr/lib/python2.7/site-packages/salt/log/handlers/fluent_mod.pytformat_logstash_v1RsB










		
$
N(	t__name__t
__module__RR,R4RKRPRXRY(((s@/usr/lib/python2.7/site-packages/salt/log/handlers/fluent_mod.pyR�s	!	#	7RcB@s5eZdZddded�Zd�Zd�ZRS(u%
    Logging Handler for fluent.
    u	localhosti�^g@c
C@sD||_t|d|d|d|d|�|_tjj|�dS(NRR	ttimeouttverbose(R
RtsendertloggingtHandlerR,(R-R
RR	R\R]((s@/usr/lib/python2.7/site-packages/salt/log/handlers/fluent_mod.pyR,�s
		cC@s&|j|�}|jjd|�dS(N(R(R^temitR(R-R3tdata((s@/usr/lib/python2.7/site-packages/salt/log/handlers/fluent_mod.pyRa�scC@s=|j�z!|jj�tjj|�Wd|j�XdS(N(tacquireR^t_closeR_R`tclosetrelease(R-((s@/usr/lib/python2.7/site-packages/salt/log/handlers/fluent_mod.pyRe�s


(RZR[t__doc__RR,RaRe(((s@/usr/lib/python2.7/site-packages/salt/log/handlers/fluent_mod.pyR�s	RcB@s_eZdddded�Zd�Zd�Zd�Zd	�Zd
�Zd�Z	d�Z
RS(u	localhosti�^iig@cC@s�||_||_||_||_||_||_d|_d|_t	j
�|_y|j�Wnt
k
r�|j�nXdS(N(R
RR	tbufmaxR\R]Rtsockettpendingst	threadingtLocktlockt
_reconnectt	ExceptionRd(R-R
RR	RhR\R]((s@/usr/lib/python2.7/site-packages/salt/log/handlers/fluent_mod.pyR,�s								
cC@s)ttj��}|j|||�dS(N(RBttimetemit_with_time(R-tlabelRbtcur_time((s@/usr/lib/python2.7/site-packages/salt/log/handlers/fluent_mod.pyRa�scC@s&|j|||�}|j|�dS(N(t_make_packett_send(R-Rrt	timestampRbtbytes_((s@/usr/lib/python2.7/site-packages/salt/log/handlers/fluent_mod.pyRq�scC@s\|r!dj|j|f�}n	|j}|||f}|jrOt|�ntj|�S(Nu.(tjoinR
R]tprinttmsgpacktpackb(R-RrRvRbR
tpacket((s@/usr/lib/python2.7/site-packages/salt/log/handlers/fluent_mod.pyRt�s		
cC@s3|jj�z|j|�Wd|jj�XdS(N(RmRct_send_internalRf(R-Rw((s@/usr/lib/python2.7/site-packages/salt/log/handlers/fluent_mod.pyRu�s
cC@s�|jr$|j|7_|j}ny'|j�|jj|�d|_WnQtk
r�|j�|jr�t|j�|jkr�d|_q�||_nXdS(N(	RjRnRitsendallRRoRdtlenRh(R-Rw((s@/usr/lib/python2.7/site-packages/salt/log/handlers/fluent_mod.pyR}�s	



!cC@s�|js�|jjd�r`tjtjtj�}|j|j�|j|jtd��nAtjtj	tj�}|j|j�|j|j|j
f�||_ndS(Nuunix://(RiRt
startswithtAF_UNIXtSOCK_STREAMt
settimeoutR\tconnectRtAF_INETR	(R-tsock((s@/usr/lib/python2.7/site-packages/salt/log/handlers/fluent_mod.pyRn�s	cC@s&|jr|jj�nd|_dS(N(RiReR(R-((s@/usr/lib/python2.7/site-packages/salt/log/handlers/fluent_mod.pyRd�s	ii(RZR[RR,RaRqRtRuR}RnRd(((s@/usr/lib/python2.7/site-packages/salt/log/handlers/fluent_mod.pyR�s			
			(.Rgt
__future__RRRR_tlogging.handlersRpR0RiRkRDtsalt.log.setupRtsalt.log.mixinsRtsalt.utils.networkRLtsalt.extRt	getLoggerRZRRztloadstdumpstTrueRtImportErrortmsgpack_puret
LOG_FORMATtsetup_console_loggertfatalRRR6RRRR#t	FormatterRR`RtobjectR(((s@/usr/lib/python2.7/site-packages/salt/log/handlers/fluent_mod.pyt<module>JsT-



				'�

Zerion Mini Shell 1.0