Spamworldpro Mini Shell
Spamworldpro


Server : Apache/2.4.52 (Ubuntu)
System : Linux webserver 6.8.0-49-generic #49~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Nov 6 17:42:15 UTC 2 x86_64
User : www-data ( 33)
PHP Version : 8.1.2-1ubuntu2.21
Disable Function : NONE
Directory :  /lib/python3/dist-packages/cloudinit/reporting/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/cloudinit/reporting/__pycache__/handlers.cpython-310.pyc
o

}��fa;�@sJddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
m
Z
ddlmZddlm
Z
ddlmZmZddlmZe�e�ZGdd�de�ZGd	d
�d
ejd�ZGdd
�d
e�ZGdd�de�ZGdd�de�ZGdd�de�Ze
eeeeefZe�Ze� de�e� de�e� de�e� de�dS)�N)�datetime)�Event)�Union)�
url_helper�util)�DictRegistryc@seZdZdS)�ReportExceptionN)�__name__�
__module__�__qualname__�rr�>/usr/lib/python3/dist-packages/cloudinit/reporting/handlers.pyrsrc@s&eZdZdZejdd��Zdd�ZdS)�ReportingHandlerz�Base class for report handlers.

    Implement :meth:`~publish_event` for controlling what
    the handler does with an event.
    cC�dS)zPublish an event.Nr��self�eventrrr
�
publish_event"�zReportingHandler.publish_eventcCr)z0Ensure ReportingHandler has published all eventsNr�rrrr
�flush&rzReportingHandler.flushN)r	r
r�__doc__�abc�abstractmethodrrrrrr
rs

r)�	metaclasscs*eZdZdZd�fdd�	Zdd�Z�ZS)�
LogHandlerzBPublishes events to the cloud-init log at the ``DEBUG`` log level.�DEBUGcs`tt|���t|t�r
n|}z	tt|���}Wnty*t	�
d|�tj}Ynw||_dS)Nzinvalid level '%s', using WARN)
�superr�__init__�
isinstance�int�getattr�logging�upper�	Exception�LOG�warning�WARN�level)rr(�input_level��	__class__rr
r-s

�
zLogHandler.__init__cCs2t�d�dd|j|jg��}|�|j|���dS)N�.�	cloudinit�	reporting)r"�	getLogger�join�
event_type�name�logr(�	as_string)rr�loggerrrr
r:s�zLogHandler.publish_event)r)r	r
rrrr�
__classcell__rrr*r
r*s
rc@seZdZdZdd�ZdS)�PrintHandlerzPrint the event as a string.cCst|���dS�N)�printr4rrrr
rDszPrintHandler.publish_eventN)r	r
rrrrrrr
r7Asr7csBeZdZ						d
�fdd�	Zdd�Zdd�Zdd	�Z�ZS)�WebHookHandlerNc	s�tt|���t||||g�rtj||||d�}|j|_ntj|_||_||_||_	t
��|_t
�|_t��|_tj|jd�|_d|j_|j��dS)N)�consumer_key�	token_key�token_secret�consumer_secret��targetT)rr:r�anyr�OauthUrlHelper�readurl�endpoint�timeout�retriesr�fetch_ssl_details�ssl_detailsr�flush_requested�queue�Queue�	threading�Thread�process_requests�event_processor�daemon�start)	rrDr;r<r=r>rErF�oauth_helperr*rr
rIs&
�


zWebHookHandler.__init__c
Cs�d}	|j��r'|dkr't�d�|j��s%|j��|j��|j��rd}|jjdd�}z@z|j	|d|d|d|d|dd	d
�d}Wnt
yg}zt�d|d|�|d7}WYd}~nd}~wwW|j��n|j��wq)NrT�zNMultiple consecutive failures in WebHookHandler. Cancelling all queued events.��block���F)�datarErFrH�log_req_respz0Failed posting event: %s. This was caused by: %s)rI�is_setr%r&rJ�empty�
get_nowait�	task_done�getrCr$)r�consecutive_failed�args�errr
rNjsD�



�������zWebHookHandler.process_requestscCs@|��}t�d|j|�|j�|jt�|�|j|j	|j
f�dS)NzQueuing POST to %s, data: %s)�as_dictr%�debugrDrJ�put�json�dumpsrErFrH)rr�
event_datarrr
r�s���zWebHookHandler.publish_eventcCs,|j��t�d�|j��|j��dS)Nz(WebHookHandler flushing remaining events)rI�setr%rdrJr0�clearrrrr
r�s


zWebHookHandler.flush)NNNNNN)r	r
rrrNrrr6rrr*r
r:Hs�!&r:cs�eZdZdZdZdZdZeeZdZdZ	dZ
dZd	Zd
Z
dZe
df�fd
d�	Zedd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zded ed!dfd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Z�ZS),�HyperVKvpReportingHandlera,
    Reports events to a Hyper-V host using Key-Value-Pair exchange protocol
    and can be used to obtain high level diagnostic information from the host.

    To use this facility, the KVP user-space daemon (hv_kvp_daemon) has to be
    running. It reads the kvp_file when the host requests the guest to
    enumerate the KVP's.

    This reporter collates all events for a module (origin|name) in a single
    json string in the dictionary.

    For more information, see
    https://technet.microsoft.com/en-us/library/dn798287.aspx#Linux%20guests
    iii�
CLOUD_INIT�msg�result�msg_i)�,�:z/var/lib/hyperv/.kvp_pool_1FNcsrtt|���||_t�|j�||_t��|_|�	�|_
d�|j|j
�|_
tj|jd�|_d|j_|j��dS)Nz{0}|{1}r?T)rrkr�_kvp_file_path�_truncate_guest_pool_file�_event_typesrJrK�q�_get_incarnation_no�incarnation_no�format�EVENT_PREFIX�event_key_prefixrLrM�_publish_event_routine�publish_threadrPrQ)r�
kvp_file_path�event_typesr*rr
r�s �

��z"HyperVKvpReportingHandler.__init__c
Cs�|jrdSt��tt���}zFztj�|�|kr.t|d��Wd�n1s)wYWnt	t
fyI}zt�d|�WYd}~nd}~wwWd|_dSWd|_dSd|_w)a
        Truncate the pool file if it has not been truncated since boot.
        This should be done exactly once for the file indicated by
        KVP_POOL_FILE_GUEST constant above. This method takes a filename
        so that we can use an arbitrary file during unit testing.
        Since KVP is a best-effort telemetry channel we only attempt to
        truncate the file once and only if the file has not been modified
        since boot. Additional truncation can lead to loss of existing
        KVPs.
        N�wz$failed to truncate kvp pool file, %sT)
�_already_truncated_pool_file�time�floatr�uptime�os�path�getmtime�open�OSError�IOErrorr%r&)�cls�kvp_file�	boot_timerbrrr
rs�s"�����
�z3HyperVKvpReportingHandler._truncate_guest_pool_filecCs@t��}ztt��t|��WStyt�d|�YdSw)z�
        use the time passed as the incarnation number.
        the incarnation number is the number which are used to
        distinguish the old data stored in kvp and the new data.
        z"uptime '%s' not in correct format.r)rr�r r�r��
ValueErrorr%r&)r�
uptime_strrrr
rv�s�z-HyperVKvpReportingHandler._get_incarnation_noccs��t|jd��>}t�|tj�|�|�|�|j�}t|�|jkr6|�	|�}|V|�|j�}t|�|jks!t�|tj
�Wd�dS1sHwYdS)z-iterate the kvp file from the current offset.�rbN)r�rr�fcntl�flock�LOCK_EX�seek�read�HV_KVP_RECORD_SIZE�len�_decode_kvp_item�LOCK_UN)r�offset�f�record_data�kvp_itemrrr
�
_iterate_kvps�s�

�"�z'HyperVKvpReportingHandler._iterate_kvpscCsd�|j|j|jt���S)z�
        the event key format is:
        CLOUD_INIT|<incarnation number>|<event_type>|<event_name>|<uuid>
        [|subevent_index]
        z{0}|{1}|{2}|{3})rxrzr1r2�uuid�uuid4rrrr
�
_event_keys�z$HyperVKvpReportingHandler._event_keycCs*t�d|j|jf|�d�|�d��}|S)Nz%ds%ds�utf-8)�struct�pack�HV_KVP_EXCHANGE_MAX_KEY_SIZE�HV_KVP_EXCHANGE_MAX_VALUE_SIZE�encode�r�key�valuerYrrr
�_encode_kvp_items���	z*HyperVKvpReportingHandler._encode_kvp_itemcCsdt|�}||jkrtd�||j���|d|j��d��d�}||j|j��d��d�}||d�S)Nz$record_data len not correct {0} {1}.rr��)r�r�)r�r�rrxr��decode�strip)rr��record_data_len�k�vrrr
r�!s$
���
��
z*HyperVKvpReportingHandler._decode_kvp_itemcCsjt|jd��%}t�|tj�|D]}|�|�q|��t�|tj�Wd�dS1s.wYdS)N�ab)r�rrr�r�r��writerr�)rr�r�rYrrr
�_append_kvp_item8s"�z*HyperVKvpReportingHandler._append_kvp_itemcCs�||j=t�|�}|dt|�d�}d}g}d|jd}	|||j<d||j<tj||jd�}|jt|�d}	|�|d	j|j|d|	�d
��}
d�||�}|�	|�
||
��|d7}||	d�}t|�dkrl	|Sq)NrVr�"z":""T���
separators�z"{key}":"{desc}")r��descz{}|{})�MSG_KEYrfrgr��DESC_IDX_KEY�JSON_SEPARATORS�HV_KVP_AZURE_MAX_VALUE_SIZE�replacerx�appendr�)rr��	meta_data�description�des_in_json�i�result_array�message_place_holder�data_without_desc�
room_for_descr��subkeyrrr
�_break_down@s8


�����z%HyperVKvpReportingHandler._break_downr�r��returnc	Csft|�|jkr|d|jd�}|�||�g}z|�|�WdSttfy2t�d||�YdSw)zJWrite KVP key-value.

        Values will be truncated as needed.
        rrVzfailed posting kvp=%s value=%sN)r�r�r�r�r�r�r%r&r�rrr
�	write_key^s�z#HyperVKvpReportingHandler.write_keycCs�|�|�}|j|jt�|j���dd�}t||j�r!|j	||j<|j
||j<tj
||jd�}t|�|jkr>|�|||j
�S|�||�}|gS)z�
        encode the event into kvp data bytes.
        if the event content reaches the maximum length of kvp value.
        then it would be cut to multiple slices.
        �Z)r2�type�tsr�)r�r2r1r�utcfromtimestamp�	timestamp�	isoformat�hasattr�
RESULT_KEYrnr�r�rfrgr�r�r�r�r�)rrr�r�r�rYrrr
�
_encode_eventms
�z'HyperVKvpReportingHandler._encode_eventc
Cs
	d}zv|jjdd�}|d7}g}|dur:||�|�7}z
|jjdd�}|d7}Wntjy5d}Ynw|dusz0z|�|�Wnttfy\}zt�	d|�WYd}~nd}~wwWt
|�D]}|j��qbn
t
|�D]}|j��qowWn
ty�YdSwq)NTrrTrVFz failed posting events to kvp, %s)
rur_r�rJ�Emptyr�r�r�r%r&�ranger^�EOFError)r�items_from_queuer�encoded_datarb�_rrr
r{�s>���������z0HyperVKvpReportingHandler._publish_event_routinecCs&|jr	|j|jvr|j�|�dSdSr8)rtr1rurerrrr
r�s�z'HyperVKvpReportingHandler.publish_eventcCst�d�|j��dS)Nz0HyperVReportingHandler flushing remaining events)r%rdrur0rrrr
r�s
zHyperVKvpReportingHandler.flush) r	r
rrr�r�r�r�ryr�r�r�r��KVP_POOL_FILE_GUESTr�r�classmethodrsrvr�r�r�r�r�r��strr�r�r{rrr6rrr*r
rk�s:�


rkr3r9�webhook�hyperv)!rr�rfr"r�rJr�rLr�r�rr�typingrr-rr�cloudinit.registryrr/r	r%r$r�ABCMetarrr7r:rk�HandlerType�available_handlers�
register_itemrrrr
�<module>sJ
`��

Spamworldpro Mini