Ë
    À7j	  ã                  óœ   — d Z ddlmZ ddlmZmZ ddlmZ ddlmZm	Z	 ddl
mZ ddlmZ ddlmZmZmZ dd	lmZ  ed
«      Zddd„Zddd„Zy)a+  Heartbeat: periodic liveness + light metrics to the Central API.

The heartbeat must be resilient: if the API is unavailable the agent logs the
failure and keeps running, retrying on the next interval. It never crashes the
service and never blocks indefinitely (the API client has its own timeout).
é    )Úannotations)ÚdatetimeÚtimezone)ÚAny)Ú	ApiClientÚApiError)ÚConfig)Úsystem)Úload_agent_tokenÚsave_statusÚsave_last_error)Ú
get_loggerÚ	heartbeatc           	     ó2  — | j                   || j                  t        j                  «       t	        j
                  t        j                  «      j                  «       t        j                  «       t        j                  «       t        j                  «       dœdœS )zôAssemble the heartbeat payload.

    The frozen heartbeat contract requires `agent_version` and `status`; the
    agent is identified by its X-Agent-Token header, not the body. Light metrics
    are sent as additional informational fields.
    )Úload_averageÚ
disk_usageÚmemory)Úagent_versionÚstatusÚ	server_idÚhostnameÚ	timestampÚmetrics)r   r   r
   r   r   Únowr   ÚutcÚ	isoformatr   r   Úmemory_usage)Úconfigr   s     úC/var/www/downloads.wolfpanel.net/public_html/agent/src/heartbeat.pyÚbuild_payloadr       so   € ð  ×-Ñ-ØØ×%Ñ%Ü—O‘OÓ%Ü—\‘\¤(§,¡,Ó/×9Ñ9Ó;ä"×/Ñ/Ó1Ü ×+Ñ+Ó-Ü×)Ñ)Ó+ñ
ñð ó    c                óÆ  — | j                   dk(  rt        j                  d«       yt        | |«      }	 |j	                  |t        | «      «       t        j                  d|«       t        | d«       y# t        $ rf}t        | t        |«      «       |j                  dk(  r"t        | d«       t        j                  d«       nt        j                  d	|«       Y d}~yd}~ww xY w)
u«   Send a single heartbeat. Returns True on success, False on failure.

    Never raises â€” transport errors are caught and reported so the caller's
    loop continues.
    Úrevokedz$Heartbeat skipped: Agent is revoked.Fzheartbeat ok (status=%s)NTi‘  z3Heartbeat rejected by Central; marked agent revokedz.heartbeat failed, will retry next interval: %s)r   ÚlogÚwarningr    r   r   Úinfor   r   ÚstrÚstatus_coder   )r   Ú
api_clientr   ÚpayloadÚexcs        r   Ú	send_oncer,   +   s¶   € ð ‡}�}˜	Ò!Ü�‰Ð:Ô;Øä˜F FÓ+€GðØ×Ñ˜WÔ&6°vÓ&>Ô?Ü�‰Ð+¨VÔ4Ü˜ Ô%ØøÜò Ü˜¤ C£Ô)Ø�?‰?˜cÒ!Ü˜ 	Ô*Ü�K‰KÐMÕNä�K‰KÐHÈ#ÔNÜûðús   ³=A1 Á1	C Á:ACÃC N)Úonline)r   r	   r   r'   Úreturnzdict[str, Any])r   r	   r)   r   r   r'   r.   Úbool)Ú__doc__Ú
__future__r   r   r   Útypingr   r)   r   r   r   r	   Ú	discoveryr
   Úidentityr   r   r   Úloggerr   r$   r    r,   © r!   r   ú<module>r7      s;   ðñõ #ç 'Ý ç *Ý Ý ß CÑ CÝ á�Ó€ôõ*r!   