HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.52.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 15 06:39:08 EDT 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/lib/fm-agent/library/__pycache__/aggregator.cpython-39.pyc
a

��i�=�@sDddlmZzddlZWney6ddlmZYn0ddlZddlZddlZddlZddl	Z	ddl
Z
zddlZWn$ddlm
ZddlmZYn0zddlZWn6ey�zddlZWney�dZYn0Yn0zddlZWndZYn0ddlmZmZmZGdd�de�ZGdd�de�ZGdd	�d	e�ZdS)
�)�datetimeN)�get_fqdn�get_platform_uuids�get_mac_addressesc@seZdZdS)�UnauthorizedResponseN��__name__�
__module__�__qualname__�rr�'/usr/lib/fm-agent/library/aggregator.pyr+src@seZdZdS)�ReinstallResponseNrrrrrr
/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�t�|jj�|_||_||_||_||_d|_	d|_
d}|durz|�dd�}t|�td�krv|�
�}|dvrrd}nd}|}|r�|r�|�|�|_
dS)N�T�enabled�)�0�falseF)�logging�	getLogger�	__class__r�log�customer_key�
server_key�agg_url�version�call_timeout�proxy�get�type�lower�parse_proxy_info)�selfrrrr�proxy_configZproxies_enabledZpevrrr�__init__9s$zClient.__init__cCs~d}|s|Sz2dD]&}|�|�}|s&qt�|�}|WSWdStyxt��d}t|�}|j�d�|��YdS0dS)N)�https�http�zparse_proxy_info error: {})	r�urlparse�	Exception�sys�exc_info�strr�info�format)r"r#Z	proxy_val�schemeZ
parsed_uri�err�errorrrrr!]s 


zClient.parse_proxy_infocCs�d}|dvr�dtjvr,tj||t��d�}q�|j�tj�trvt	td�rv|j�dt	td��tj|||j
t��d�}q�tjdkr�tj|||j
d�}q�t�||�}n4tjdkr�dtjvr�tj|||j
d�}nt�||�}|S)	N)�i� zhp-ux)�context�_create_unverified_contextz0ssl has _create_unverified_context attribute: %s��timeoutr3)��r)r6)r*�platform�httplib�HTTPSConnection�sslr4r�debug�version_info�hasattrr�HTTPConnection)r"�url�port�
connectionrrr�create_connectionos:

���
��zClient.create_connection�POSTc	Cs�dd�|j�d�D�}t�|�d}|D�]�}zTt�|�}|ddksR|ddkr`t�d|�}|ddvsx|ddkr�td	��Wnty�td
��Yn0|d}d|vr�|�d�\}}	t|	p�d�}	n|}d}	d
|vr�|d|�d
��}|j	�
d|||	�d}
d|j|f}|dk�r\|j|d<d|d<t�
t�����|d<|j	�d|�t�|�}
ddd�}|j�rx|j|d<d}
|j�r(tj|jj|jj|jt��d�}
|j	�
d�|
j|
j��|jj}|jj }|�r|�rd�||�}t!�"t#|d���$d�}d�|�}|
j%||	d|id�n|
�%||	�n|�&||	�}
�z|j	�d |||
|f�|
�'|||
|�|
�(�}t|j)�d!k�r�t�*|�+��$d��}|�,d"i��,d#��r�|d"d#}t-|��t|j.��|dk�r�t|j)�d$k�r�t|j.��n$|dk�rt|j)�d%k�rt|j.��t�*|�+��$d��}|�,d&�d'u�rL|�,d(�d)k�rLt/d*|�d+���|WSt-�yj�Yq(t/�y~�Yq(t�y�t0�1�d}t2|�}|j	�3d,|�Yq(Yq(0q(t|��dS)-NcSsg|]}|��r|���qSr)�strip)�.0rArrr�
<listcomp>��zClient.call.<locals>.<listcomp>�,rrr'zhttp://)r&r%zInvalid aggregator URLzInvalid aggregator URL format.�:r2z/vzaggregator call %r to %r:%dz/v%s/%srEZ
agent_versionZv3Zmetadata_versionZ
agent_timezData: %rzapplication/json)zContent-type�Accept�
Authorizationr5zConnection 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)4r�split�random�shuffler(r)�
ValueError�int�indexrr-r�time�mktimer�now�	timetupler=�json�dumpsrrr:r;�hostnamerBrr<r4r.�host�username�password�base64�	b64encode�bytes�decode�
set_tunnelrD�request�getresponse�status�loads�readrrrTr
r*r+r,r1)r"�action�data�methodZagg_urlsr1rZ	url_partsrArB�params�urirNrC�unameZpswd�credsZ	auth_hashZ
auth_value�respZ
pause_timeZ	resp_datar0rrr�call�s�







���

�

��
�
zClient.callcCs�t�tjtj���}|�d�d|j�d�dvrL|j�d�d�d�\}}n
|j}d}|j�d�||��|�	|t
|�f�|��dWd�S1s�0YdS)Ng@rKrJrz*get_local_ip: creating connection to {} {})�socket�AF_INET�
SOCK_DGRAM�
settimeoutrrUrr-r.�connectrY�getsockname)r"�clientrbrBrrr�get_local_ip�s

�zClient.get_local_ipFcCstt|||||||||||	|
|||
|d�}|r>t�}|r>||d<|r\|��D]}||||<qJ|rh||d<|�d|�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�keysrw)r"r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��dem_service_resultsr��payload�platform_uuidsZdsrrrr�
s8�zClient.synccCsTd}|j�d�z|jdd|id�Wn|j�d�Yn0|j�d�d}|S)	NFz beginning uninstall notification�	uninstall�remove_instance)rpzerror connectingznotified successfullyT)rr-rwr1)r"r��successrrr�notify_of_uninstallBszClient.notify_of_uninstallc
Cs
|j�d�t�}|j||t�d�}t�}|r6||d<|�|�|�|�||��|j�d�|j�tj	|dd��d}d}d}	d}
d}zL|�
d|�}|j�|�|d	}|d
}d|vr�d|dvr�|dd}Wn4t�yt
��d}|j�d
|�|}
Yn0d}	|j�d|�|�d	��s<|�d
��s<d}
d}	d|v�r�|�d��r�d}	|ddk�rjd}
n~|ddk�r~d}
nj|ddk�r�d}
nV|ddk�r�d}
nB|ddk�r�d}
n.|d�d��r�d|d�dd�}
n|d}
|j�d |	|||
�|	|||
|fS)!NzBeginning handshake)rrar�Z
mac_addressesr�zHandshaking with aggregator:r')�indentF�	handshakerrSrO�	log_levelzError connecting: %sTz/Connected successfully! Received server key: %rzIError performing handshake with the aggregator, please check connectivityr1Zinvalid_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`rwr=r)r*r+r1r�
startswith�replace)
r"r��
properties�
attributesrarpr�rrSr�r1r�r0rrrr�Psx�


��zClient.handshakecCs||r
|pgd�}|�d|�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�rw)r"r�r�r�rrrr��s
�zClient.maintenancecCs
|�d�S)z�
        Request to the aggregator that it ends all active maintenances for our server.
        POST call with no parameters.
        �end_maintenancer�)r"rrrr��szClient.end_maintenancecCs d|vr|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�rrrr��szClient.parse_attributes)NNN)F)N)N)rr	r
�__doc__r$r!rDrwrr�r�r�r�r�r�rrrrr3s$�
$)g�
5

I

r)rr:�ImportError�http.clientr~rerrVrxr*r[r(�urllib.requestrj�
urlrequest�urllib.parse�parser_�
simplejsonr<�	inspectorrrrr)rr
�objectrrrrr�<module>s<