HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/beacons/__pycache__/haproxy.cpython-310.pyc
o

�N�gm�@s>dZddlZddlZe�e�ZdZdd�Zdd�Z	dd	�Z
dS)
z�
Watch current connections of haproxy server backends.
Fire an event when over a specified threshold.

.. versionadded:: 2016.11.0
�NZhaproxycCs&dtvrtSd}t�dt|�d|fS)z@
    Only load the module if haproxyctl module is installed
    �haproxy.get_sessionsz haproxy.get_sessions is missing.zUnable to load %s beacon: %sF)�__salt__�__virtualname__�log�error)�err_msg�r�H/opt/saltstack/salt/lib/python3.10/site-packages/salt/beacons/haproxy.py�__virtual__s
r
cCs�t|t�sdStjj�|�}d|vrdSt|dt�sdS|dD]'}t�d|d|�d|d|vr8dS|d|d}t|t�sHdSq!d	S)
z+
    Validate the beacon configuration
    )Fz0Configuration for haproxy beacon must be a list.�backends)Fz3Configuration for haproxy beacon requires backends.)Fz1Backends for haproxy beacon must be a dictionary.z	config %s�servers)Fz,Backends for haproxy beacon require servers.)Fz*Servers for haproxy beacon must be a list.)TzValid beacon configuration)	�
isinstance�list�salt�utils�beacons�list_to_dict�dictr�debug)�config�backendZ_serversrrr	�validates 

�rc	Cs�g}tjj�|�}|�dd�D]8}|d|}|d}|dD]'}td||�}|rFt|�t|�krF|||d�}t�d||||�|�	|�qq|S)a�
    Check if current number of sessions of a server for a specific haproxy backend
    is over a defined threshold.

    .. code-block:: yaml

        beacons:
          haproxy:
            - backends:
                www-backend:
                    threshold: 45
                    servers:
                      - web1
                      - web2
            - interval: 120
    rr�	thresholdrr)�server�scurrz!Emit because %s > %s for %s in %s)
rrrr�getr�intrr�append)r�retrZbackend_configrrrZ_serverrrr	�beacon=s0��
��r)�__doc__�loggingZsalt.utils.beaconsr�	getLogger�__name__rrr
rrrrrr	�<module>s