CyberAlphaWolf

Server : Apache
System : Linux 182.49.167.72.host.secureserver.net 4.18.0-553.92.1.el8_10.x86_64 #1 SMP Wed Jan 14 06:31:58 EST 2026 x86_64
User : kikai ( 1014)
PHP Version : 8.3.30
Disable Function : NONE
Directory :  /lib/fm-agent/library/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/fm-agent/library/__pycache__/aggregator.cpython-36.pyc
3

,`ri�=�&@sDddlmZyddlZWnek
r6ddljZYnXddlZddlZddlZddlZddl	Z	ddl
Z
yddlZWn ddlj
ZddljZYnXyddlZWn:ek
r�yddlZWnek
r�dZYnXYnXyddlZWndZYnXddlmZmZmZGdd�de�ZGdd�de�ZGdd	�d	e�ZdS)
�)�datetimeN)�get_fqdn�get_platform_uuids�get_mac_addressesc@seZdZdS)�UnauthorizedResponseN)�__name__�
__module__�__qualname__�r
r
�'/usr/lib/fm-agent/library/aggregator.pyr+src@seZdZdS)�ReinstallResponseN)rrr	r
r
r
rr/src@s�eZdZdZddd�Zdd�Zdd�Zid	fd
d�Zdd
�Zdidiifdd�Z	ddd�Z
ddd�Zddd�Zdd�Z
dd�ZdS)�Clientzy
    This is a client used for communicating with an aggregator, either *the*
    Aggregator or an Onsight instance.
    NcCs�tj|jj�|_||_||_||_||_d|_	d|_
d}|dk	rz|jdd�}t|�td�krv|j
�}|dkrrd}nd}|}|r�|r�|j|�|_
dS)	N�T�enabled��0�falseF)rr)�logging�	getLogger�	__class__r�log�customer_key�
server_key�agg_url�version�call_timeout�proxy�get�type�lower�parse_proxy_info)�selfrrrr�proxy_configZproxies_enabledZpevr
r
r�__init__9s$zClient.__init__cCszd}|s|Sy.x(dD] }|j|�}|s(qtj|�}|SWdStk
rttj�d}t|�}|jjdj|��dSXdS)N�https�http�zparse_proxy_info error: {})r$r%)	r�urlparse�	Exception�sys�exc_info�strr�info�format)r!r"Z	proxy_val�schemeZ
parsed_uri�err�errorr
r
rr ]s 


zClient.parse_proxy_infocCs�d}|dkr�dtjkr,tj||tj�d�}q�|jjtj�trvt	td�rv|jjdt	td��tj|||j
tj�d�}q�tjd
kr�tj|||j
d�}q�tj||�}n4tjdkr�dtjkr�tj|||j
d�}ntj||�}|S)N�� zhp-ux)�context�_create_unverified_contextz0ssl has _create_unverified_context attribute: %s)�timeoutr3��r)r5)r1r2)r6r7r)r6r7r)r)�platform�httplib�HTTPSConnection�sslr4r�debug�version_info�hasattrr�HTTPConnection)r!�url�port�
connectionr
r
r�create_connectionos0

zClient.create_connection�POSTcCs�dd�|jjd�D�}tj|�d}�x�|D�]�}yTtj|�}|ddksV|ddkrdtjd|�}|dd.ks||ddkr�td
��Wntk
r�td��YnX|d}d|kr�|jd�\}}	t|	p�d
�}	n|}d
}	d|kr�|d|jd��}|j	j
d|||	�d}
d|j|f}|dk�rb|j|d<d|d<tj
tj�j��|d<|j	jd|�tj|�}
ddd�}|j�r~|j|d<d}
|j�r.tj|jj|jj|jtj�d�}
|j	j
dj|
j|
j��|jj}|jj }|�r |�r dj||�}t!j"t#|d��j$d�}dj|�}|
j%||	d|id �n|
j%||	�n|j&||	�}
�y|j	jd!|||
|f�|
j'|||
|�|
j(�}t|j)�d"k�r�tj*|j+�j$d��}|j,d#i�j,d$��r�|d#d$}t-|��t|j.��|dk�r�t|j)�d%k�r�t|j.��n$|dk�rt|j)�d&k�rt|j.��tj*|j+�j$d��}|j,d'�d(k�rR|j,d)�d*k�rRt/d+|�d,���|St-k
�rl�Yq,t/k
�r��Yq,tk
�r�t0j1�d}t2|�}|j	j3d-|�w,Yq,Xq,Wt|��dS)/NcSsg|]}|j�r|j��qSr
)�strip)�.0r@r
r
r�
<listcomp>�szClient.call.<locals>.<listcomp>�,rrr&zhttp://r%r$zInvalid aggregator URLzInvalid aggregator URL format.�:i�z/vzaggregator call %r to %r:%dz/v%s/%srDZ
agent_versionZv3Zmetadata_versionZ
agent_timezData: %rzapplication/json)zContent-type�Accept�
Authorization)r5r3zConnection via proxy {}:{}z{}:{}zutf-8zBasic {}zProxy-Authorization)�headersz%s - %s - %s - %si��commands�pause�����found_serverF�reasonzFortiClient serial mismatchzSync z+ failed due to FortiClient serial conflict.zUnable to connect: %s)r%r$)4r�split�random�shuffler'r(�
ValueError�int�indexrr,r�time�mktimer�now�	timetupler<�json�dumpsrrr9r:�hostnamerArr;r4r-�host�username�password�base64�	b64encode�bytes�decode�
set_tunnelrC�request�getresponse�status�loads�readrrrRrr)r*r+r0)r!�action�data�methodZagg_urlsr0rZ	url_partsr@rA�params�urirLrB�unameZpswd�credsZ	auth_hashZ
auth_value�respZ
pause_timeZ	resp_datar/r
r
r�call�s�









zClient.callcCs�tjtjtj��x}|jd�d|jjd�dkrL|jjd�djd�\}}n
|j}d}|jjdj||��|j	|t
|�f�|j�dSQRXdS)Ng@rIrHrz*get_local_ip: creating connection to {} {})�socket�AF_INET�
SOCK_DGRAM�
settimeoutrrSrr,r-�connectrW�getsockname)r!�clientr`rAr
r
r�get_local_ip�s
zClient.get_local_ipFcCsxt|||||||||||	|
|||
|d�}|r>t�}|r>||d<|r`x|j�D]}||||<qLW|rl||d<|jd|�S)N)�results�
outage_events�metadata�countermeasures_metadata�facts�discovered_containers�deleted_containers�force_send_schedules�command_results�register�register_custom_metrics�	incidents�config�ips�auto_topo_scans�dem_enabled�fm_server_identifiers�fortisase_attributes�sync)�dictr�keysru)r!r~rr�r�r�r�r�r�r�r�r�r�r�r�r�r��dem_service_resultsr��payload�platform_uuidsZdsr
r
rr�
s6zClient.syncc
CsTd}|jjd�y|jdd|id�Wn|jjd�YnX|jjd�d}|S)	NFz beginning uninstall notification�	uninstall�remove_instance)rnzerror connectingznotified successfullyT)rr,rur0)r!r��successr
r
r�notify_of_uninstallBszClient.notify_of_uninstallc
Cs|jjd�t�}|j||t�d�}t�}|r6||d<|j|�|j|j||��|jjd�|jjtj	|dd��d}d}d}	d}
d}yL|j
d|�}|jj|�|d	}|d
}d|kr�d|dkr�|dd}Wn6tk
�r
t
j�d}|jjd
|�|}
YnXd}	|jjd|�|jd	��p2|jd
��s>d}
d}	d|k�r�|jd��r�d}	|ddk�rld}
n~|ddk�r�d}
nj|ddk�r�d}
nV|ddk�r�d}
nB|ddk�r�d}
n.|djd��r�d|djdd�}
n|d}
|jjd |	|||
�|	|||
|fS)!NzBeginning handshake)rr_r�Z
mac_addressesr�zHandshaking with aggregator:r&)�indentF�	handshakerrQrM�	log_levelzError connecting: %sTz/Connected successfully! Received server key: %rzIError performing handshake with the aggregator, please check connectivityr0Zinvalid_credentialszIncorrect username/passwordZinvalid_customer_keyzUnknown/invalid customer keyZinvalid_server_groupzUnknown server groupZinactive_customerzCustomer inactiveZno_user_found_for_customerz%No active user found for the customerZinvalid_template_idzUnknown template id %szinvalid_template_id:rz8Success: %s, server key: %s, found server: %s, error: %s)rr,rrrr�update�parse_attributesr]r^rur<r(r)r*r0r�
startswith�replace)
r!r��
properties�
attributesr_rnr�rrQr�r0r�r/r
r
rr�Psr



zClient.handshakecCs||r
|pgd�}|jd|�S)a
        Request to the aggregator that it starts a maintenance for our server.
        It requires the duration of the maintenance in minutes, and
        accepts an optional list of tags to mark metrics that are going to be affected
        by it.
        )�duration�metric_tags�maintenance)ru)r!r�r�r�r
r
rr��szClient.maintenancecCs
|jd�S)z�
        Request to the aggregator that it ends all active maintenances for our server.
        POST call with no parameters.
        �end_maintenance)ru)r!r
r
rr��szClient.end_maintenancecCs d|kr|rd|ipiSiSdS)z�
        Receive a dictionary containing the attributes stored in the manifest file.
        Parse them accordingly and store them in an attribute dictionary. Attributes get parsed
        only if the customer key is present in the properties.
        rr�Nr
)r!r�r�r
r
rr��szClient.parse_attributes)NNN)F)N)N)rrr	�__doc__r#r rCrur}r�r�r�r�r�r�r
r
r
rr
3s 
#)g"

I

r
)rr9�ImportError�http.clientr|rcrrTrvr)rYr'�urllib.requestrh�
urlrequest�urllib.parse�parser]�
simplejsonr;�	inspectorrrrr(rr�objectr
r
r
r
r�<module>s<



XYZEAZ - Cyber Alpha Wolf © All Rights Reserved