AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.128   [ 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 :  /snap/core20/2599/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 : /snap/core20/2599/lib/python3/dist-packages/cloudinit/reporting/__pycache__/handlers.cpython-38.pyc
U

Ӈg
<�@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.
    cCsdS)zPublish an event.Nr��self�eventrrr�
publish_event"szReportingHandler.publish_eventcCsdS)z0Ensure ReportingHandler has published all eventsNr�rrrr�flush&szReportingHandler.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.�DEBUGcsbtt|���t|t�rn>|}ztt|���}Wn&tk
rVt	�
d|�tj}YnX||_dS)Nzinvalid level '%s', using WARN)
�superr�__init__�
isinstance�int�getattr�logging�upper�	Exception�LOG�warningZWARN�level)rr'Zinput_level��	__class__rrr-s
zLogHandler.__init__cCs2t�d�dd|j|jg��}|�|j|���dS)N�.�	cloudinitZ	reporting)r"�	getLogger�join�
event_type�name�logr'�	as_string)rrZloggerrrrr:s�zLogHandler.publish_event)r)rrr
rrr�
__classcell__rrr(rr*s
rc@seZdZdZdd�ZdS)�PrintHandlerzPrint the event as a string.cCst|���dS�N)�printr1rrrrrDszPrintHandler.publish_eventN)rrr
rrrrrrr3Asr3cs6eZdZd
�fdd�	Zdd�Zdd�Zdd	�Z�ZS)�WebHookHandlerNc	s�tt|���t||||g�r:tj||||d�}|j|_ntj|_||_||_||_	t
��|_t
�|_t��|_tj|jd�|_d|j_|j��dS)N)�consumer_key�	token_key�token_secret�consumer_secret��targetT)rr6r�anyrZOauthUrlHelper�readurl�endpoint�timeout�retriesrZfetch_ssl_details�ssl_detailsr�flush_requested�queue�Queue�	threading�Thread�process_requestsZevent_processor�daemon�start)	rr?r7r8r9r:r@rAZoauth_helperr(rrrIs&
�


zWebHookHandler.__init__c
Cs�d}|j��rD|dkrDt�d�|j��s@|j��|j��q d}|jjdd�}ztz2|j	|d|d|d|d|dd	d
�d}Wn<t
k
r�}zt�d|d|�|d7}W5d}~XYnXW5|j��XqdS)Nr�zNMultiple consecutive failures in WebHookHandler. Cancelling all queued events.T��block���F)�datar@rArBZlog_req_respz0Failed posting event: %s. This was caused by: %s)rCZis_setr%r&rD�emptyZ
get_nowait�	task_done�getr>r$)rZconsecutive_failed�args�errrrHjs8�

��zWebHookHandler.process_requestscCs@|��}t�d|j|�|j�|jt�|�|j|j	|j
f�dS)NzQueuing POST to %s, data: %s)Zas_dictr%�debugr?rD�put�json�dumpsr@rArB)rrZ
event_datarrrr�s���zWebHookHandler.publish_eventcCs,|j��t�d�|j��|j��dS)Nz(WebHookHandler flushing remaining events)rC�setr%rWrDr-�clearrrrrr�s


zWebHookHandler.flush)NNNNNN)rrr
rrHrrr2rrr(rr6Hs�!&r6cs�eZdZdZdZdZdZeeZdZdZ	dZ
dZd	Zd
Z
dZe
df�fd
d�	Zedd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zeedd�d 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
    iiiZ
CLOUD_INIT�msg�resultZmsg_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)rr]r�_kvp_file_path�_truncate_guest_pool_file�_event_typesrDrE�q�_get_incarnation_noZincarnation_no�format�EVENT_PREFIX�event_key_prefixrFrG�_publish_event_routineZpublish_threadrIrJ)rZ
kvp_file_pathZevent_typesr(rrr�s"�

��z"HyperVKvpReportingHandler.__init__c
Cs�|jr
dSt��tt���}zbz*tj�|�|krHt|d��W5QRXWn2t	t
fk
r|}zt�d|�W5d}~XYnXW5d|_XdS)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.
        NT�wz$failed to truncate kvp pool file, %s)
�_already_truncated_pool_file�time�floatr�uptime�os�path�getmtime�open�OSError�IOErrorr%r&)�clsZkvp_fileZ	boot_timerVrrrrc�s"z3HyperVKvpReportingHandler._truncate_guest_pool_filecCsFt��}ztt��t|��WStk
r@t�d|�YdSXdS)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.rN)rror rmrn�
ValueErrorr%r&)rZ
uptime_strrrrrf�sz-HyperVKvpReportingHandler._get_incarnation_noc	cszt|jd��d}t�|tj�|�|�|�|j�}t|�|jkr^|�	|�}|V|�|j�}q2t�|tj
�W5QRXdS)z-iterate the kvp file from the current offset.�rbN)rsrb�fcntl�flock�LOCK_EX�seek�read�HV_KVP_RECORD_SIZE�len�_decode_kvp_item�LOCK_UN)r�offset�f�record_dataZkvp_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})rgrir.r/�uuidZuuid4rrrr�
_event_keys�z$HyperVKvpReportingHandler._event_keycCs*t�d|j|jf|�d�|�d��}|S)Nz%ds%ds�utf-8)�structZpack�HV_KVP_EXCHANGE_MAX_KEY_SIZE�HV_KVP_EXCHANGE_MAX_VALUE_SIZE�encode�r�key�valuerQrrr�_encode_kvp_items���	z*HyperVKvpReportingHandler._encode_kvp_itemcCsdt|�}||jkr$td�||j���|d|j��d��d�}||j|j��d��d�}||d�S)Nz$record_data len not correct {0} {1}.rr��)r�r�)rr~r
rgr��decode�strip)rr�Zrecord_data_len�k�vrrrr�!s0
���������z*HyperVKvpReportingHandler._decode_kvp_itemc
Csrt�d|j����Vt|jd��>}t�|tj�|D]}|�|�q4|��t�|tj	�W5QRXW5QRXdS)Nz
Appending Zab)
rZTimedrbrsryrzr{�writerr�)rr�r�rQrrr�_append_kvp_item8s�z*HyperVKvpReportingHandler._append_kvp_itemcCs�||j=t�|�}|dt|�d�}d}g}d|jd}|||j<d||j<tj||jd�}|jt|�d}	|�|dj|j|d|	�d	��}
d
�||�}|�	|�
||
��|d7}||	d�}t|�dkr<q�q<|S)NrNr�"z":""��Z
separators�z"{key}":"{desc}")r�Zdescz{}|{})�MSG_KEYrYrZr�DESC_IDX_KEY�JSON_SEPARATORS�HV_KVP_AZURE_MAX_VALUE_SIZE�replacerg�appendr�)rr��	meta_data�descriptionZdes_in_json�iZresult_arrayZmessage_place_holderZdata_without_descZ
room_for_descr�Zsubkeyrrr�_break_downBs8


��
��z%HyperVKvpReportingHandler._break_down)r�r��returnc	Csht|�|jkr |d|jd�}|�||�g}z|�|�Wn&ttfk
rbt�d||�YnXdS)zJWrite KVP key-value.

        Values will be truncated as needed.
        rrNzfailed posting kvp=%s value=%sN)rr�r�r�rtrur%r&r�rrr�	write_key`sz#HyperVKvpReportingHandler.write_keycCs�|�|�}|j|jt�|jtj���d�}t	||j
�rB|j||j
<|j||j
<tj||jd�}t|�|jkr||�|||j�S|�||�}|gSdS)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.
        )r/�typeZtsr�N)r�r/r.rZ
fromtimestampZ	timestamprZutcZ	isoformat�hasattr�
RESULT_KEYr_r�r�rYrZr�rr�r�r�)rrr�r�r�rQrrr�
_encode_eventos 
��	z'HyperVKvpReportingHandler._encode_eventc
Cs�d}z�|jjdd�}|d7}g}|dk	rn||�|�7}z|jjdd�}|d7}Wq tjk
rjd}Yq Xq zFz|�|�Wn2tt	fk
r�}zt
�d|�W5d}~XYnXW5t|�D]}|j��q�XWqtk
r�YdSXqdS)NrTrLrNFz failed posting events to kvp, %s)
rerTr�rDZEmpty�rangerSr�rtrur%r&�EOFError)rZitems_from_queuerZencoded_data�_rVrrrrj�s("z0HyperVKvpReportingHandler._publish_event_routinecCs"|jr|j|jkr|j�|�dSr4)rdr.rerXrrrrr�sz'HyperVKvpReportingHandler.publish_eventcCst�d�|j��dS)Nz0HyperVReportingHandler flushing remaining events)r%rWrer-rrrrr�s
zHyperVKvpReportingHandler.flush) rrr
rr�r�r�r~rhr�r�r�r�ZKVP_POOL_FILE_GUESTrlr�classmethodrcrfr�r�r�r�r�r��strr�r�rjrrr2rrr(rr]�s8�



r]r0r5ZwebhookZhyperv)#rryrYr"rprDr�rFrmr�rrr�typingrr+rrrZcloudinit.registryr	r,rr%r$r
�ABCMetarrr3r6r]ZHandlerTypeZavailable_handlersZ
register_itemrrrr�<module>sH
`��

Anon7 - 2022
AnonSec Team