HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/beacons.cpython-310.pyc
o

�N�g�n�@s�dZddlZddlZddlZddlZddlZddlZe�e	�Z
dZddd�Zd dd	�Z
d!d
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)"zO
Module for managing the Salt beacons on a minion

.. versionadded:: 2015.8.0

�N�<�list�reload)�list_Zreload_Tc
Ks�d}zDtjjjdtdd��0}tdd||d�d�}|r6|jd	|�d
t�d�}t�	d|�|r6|d
r6|d}Wd�n1s@wYWnt
y[i}d|d<d|d<|YSw|rkd|i}	tjjj|	dd�S|S)aF
    List the beacons currently configured on the minion

    :param return_yaml:    Whether to return YAML formatted output,
                           default ``True``

    :param include_pillar: Whether to include beacons that are
                           configured in pillar, default is ``True``.

    :param include_opts:   Whether to include beacons that are
                           configured in opts, default is ``True``.

    :return:               List of currently configured Beacons.

    CLI Example:

    .. code-block:: bash

        salt '*' beacons.list

    N�minionT��opts�listen�
event.firer)�func�include_pillar�include_opts�manage_beaconsz)/salt/minion/minion_beacons_list_complete�timeout��tag�wait�event_ret %s�complete�beaconsF�resultz/Event module not available. Beacon list failed.�comment�Zdefault_flow_style)
�salt�utils�event�	get_event�__opts__�__salt__�get�default_event_wait�log�debug�KeyError�yaml�	safe_dump)
�return_yamlrr
�kwargsr�	event_bus�res�	event_ret�ret�tmp�r-�H/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/beacons.pyrsD���
�����rc	
Ks�d}z<tjjjdtdd��(}tdddid�}|r.|jd	|�d
t�d�}|r.|dr.|d
}Wd�n1s8wYWnty\}zi}d|d<d|d<|WYd}~Sd}~ww|rp|rnd
|i}tjj	j
|dd�S|Sd
iiS)aG
    List the beacons currently available on the minion

    :param return_yaml:     Whether to return YAML formatted output, default
                            ``True``
    :return:                List of currently configured Beacons.

    CLI Example:

    .. code-block:: bash

        salt '*' beacons.list_available

    NrTrr
r�list_availablerz3/salt/minion/minion_beacons_list_available_completerrrrFrz9Event module not available. Beacon list_available failed.rr)rrrrrrrr r#r$r%)	r&r'rr(r)r*�er+r,r-r-r.r/Ps<�
������r/c
s�d��d�dd�}�td+ddi|��vr"d��d�|d<d	|d
<|Stdd�|D��r9td
d�|D��}|d}n�}|td+ddi|��vrPd|�d�|d<|Sd|vrf|drfd	|d
<d��d�|d<|SzTtjjjdtd	d��@}t	d�|dd�d�}|r�|jd|�
dt�d�}|d}|d}	|s�d|d
<d��|	�|d<|Wd �WSWd �n1s�wYWnt
y�d|d
<d!|d<|YSwz�tjjjdtd	d��u}t	d�|d"d�d�}|�rE|jd#|�
dt�d�}|�r|d$�r|d%���v�rt��fd&d'�|D���rd	|d
<d(��d�|d<n|�r,d|d
<|d|d<nd|d
<d)�|�
dt��|d<|Wd �WSWd �W|S1�sRwYW|St
�yld|d
<d*|d<Y|Sw),a�
    Add a beacon on the minion

    :param name:            Name of the beacon to configure
    :param beacon_data:     Dictionary or list containing configuration for beacon.
    :return:                Boolean and status message on success or failure of add.

    CLI Example:

    .. code-block:: bash

        salt '*' beacons.add ps "[{'processes': {'salt-master': 'stopped', 'apache2': 'stopped'}}]"

    zFailed to add beacon �.F�rrr&�Beacon z is already configured.rTrcss�|]}d|vVqdS��
beacon_moduleNr-)�.0�keyr-r-r.�	<genexpr>�s�zadd.<locals>.<genexpr>css�|]	}d|vr|VqdSr4r-)r6�valuer-r-r.r8�s�r5zBeacon "z" is not available.�test�Beacon: z would be added.rrr
�validate_beacon��name�beacon_datarr�./salt/minion/minion_beacon_validation_completerr�valid�vcommentz/Beacon {} configuration invalid, not adding.
{}Nz5Event module not available. Beacon validation failed.�addz'/salt/minion/minion_beacon_add_completerrcsg|]}|��v�qSr-r-)r6�item�rr>r-r.�
<listcomp>�szadd.<locals>.<listcomp>zAdded beacon: zGDid not receive the beacon add complete event before the timeout of {}sz.Event module not available. Beacon add failed.r-)r�any�nextr/rrrrrrrr �formatr#�all)
r>r?r'r+r)Zbeacon_namer(r*rArBr-rEr.rC~s�
I����
��������
�
���
����#�#�
�rCcKs ddd�}td)ddi|��}||vrd|�d�|d<|Sd	|vr2|d	r2d|d
<d|�d�|d<|SzTtjjjd
tdd��@}td||dd�d�}|r^|jd|�dt�d�}|d}|d}	|svd|d
<d�	||	�|d<|Wd�WSWd�n1s�wYWnt
y�d|d
<d|d<|YSw|s�d|d
<d�	||	�|d<|S||}
|}||
kr�d|�d�|d<|Sg}|
D]}
|�dd�|
��D��q�g}|D]}
|�dd�|
��D��q�t
�||�}i|d <d�|�|d d!<z�tjjjd
tdd��o}td||d"d�d�}|�rh|jd#|�dt�d�}|�rA|d$�rA|d%}||v�r@|||k�r@d|d
<d&|�d'�|d<n|�rOd|d
<|d|d<nd|d
<d(�	|�dt��|d<|Wd�WSWd�W|S1�suwYW|St
�y�d|d
<d|d<Y|Sw)*a�
    Modify an existing beacon

    :param name:            Name of the beacon to configure
    :param beacon_data:     Dictionary or list containing updated configuration for beacon.
    :return:                Boolean and status message on success or failure of modify.

    CLI Example:

    .. code-block:: bash

        salt '*' beacons.modify ps "[{'salt-master': 'stopped'}, {'apache2': 'stopped'}]"
    �Tr2r&Fr3z is not configured.rr:rr;z would be modified.rrr
r<r=rr@rrrArBz2Beacon {} configuration invalid, not modifying.
{}Nz1Event module not available. Beacon modify failed.zJob z in correct statecS� g|]\}}|�d|�d��qS��:�
r-�r6r7r9r-r-r.rF?� zmodify.<locals>.<listcomp>cSrLrMr-rPr-r-r.rFCrQZchanges�diff�modifyz*/salt/minion/minion_beacon_modify_completerrzModified beacon: r1zKDid not receive the beacon modify complete  event before the timeout of {}sr-)rrrrrrrrr rIr#�extend�items�difflibZunified_diff�join)r>r?r'r+Zcurrent_beaconsr(r)r*rArBZ_currentZ_newZ_current_linesZ_itemZ
_new_linesZ_diffrr-r-r.rS�s�
e����
�����������
�
��
����!�!�
�rScKs�d|�d�dd�}d|vr|drd|d<d|�d	�|d
<|Sz�tjjjdtdd��}}td
|dd�d�}|r�|jd|�dt�d�}|rg|drg|d}||vrfd|d<d|�d�|d
<|Wd�WSn.|rtd|d<|d
|d
<n*d|d<d�|�dt��|d
<Wd�W|SWd�W|SWd�W|SWd�W|S1s�wYW|St	y�d|d<d|d
<Y|Sw)a'
    Delete a beacon item

    :param name:            Name of the beacon to delete
    :return:                Boolean and status message on success or failure of delete.

    CLI Example:

    .. code-block:: bash

        salt '*' beacons.delete ps

        salt '*' beacons.delete load

    zFailed to delete beacon r1Fr2r:Trr;z would be deleted.rrrr
�delete)r>rrz*/salt/minion/minion_beacon_delete_completerrrrzDeleted beacon: NzJDid not receive the beacon delete complete event before the timeout of {}sz1Event module not available. Beacon delete failed.�
rrrrrrrr rIr#)r>r'r+r(r)r*rr-r-r.rXnsj#��
�
��

��� �� �� �� � �
�rXcKs�gdd�}tdddd�|��}tj�tj�td�tj�td�d�}|r3d|i}tjjj	|dd	�}nd
}z(tjj
�|d��
}|�|�Wd�n1sNwYd
|�d�|d<W|St
ysd|�d�|d<d|d<Y|Sw)z�
    Save all configured beacons to the minion config

    :return:                Boolean and status message on success or failure of save.

    CLI Example:

    .. code-block:: bash

        salt '*' beacons.save
    Tr2F)r&rZ	conf_fileZdefault_includezbeacons.confrrrKzw+NzBeacons saved to r1rz#Unable to write to beacons file at z. Check permissions.rr-)r�os�pathrW�dirnamerrrr$r%�filesZfopen�write�OSError)r'r+rZsfnr,Zyaml_outZfp_r-r-r.�save�s,

���
�r`cKs4gdd�}d|vr|drd|d<|Szttjjjdtdd��_}tdd	d
id�}|rt|jd|�d
t�d�}|rj|drj|d}d|vrP|drPd|d<d|d<n|r[d|d<d|d<nd|d<d�|�d
t��|d<|Wd�WSWd�W|S1s�wYW|St	y�d|d<d|d<Y|Sw)z�
    Enable all beacons on the minion

    Returns:
        bool: Boolean and status message on success or failure of enable.

    CLI Example:

    .. code-block:: bash

        salt '*' beacons.enable
    Tr2r:zBeacons would be enabled.rrrr
r�enablerz,/salt/minion/minion_beacons_enabled_completerrrr�enabledrzEnabled beacons on minion.Fz#Failed to enable beacons on minion.�KDid not receive the beacon enabled complete event before the timeout of {}sNz6Event module not available. Beacons enable job failed.rY�r'r+r(r)r*rr-r-r.ra�sR
!��
�


������
�racKs@gdd�}d|vr|drd|d<|Szztjjjdtdd��e}tdd	d
id�}|rz|jd|�d
t�d�}t�	d|�|rp|drp|d}d|vrV|dsVd|d<d|d<n|rad|d<d|d<nd|d<d�
|�d
t��|d<|Wd�WSWd�W|S1s�wYW|Sty�d|d<d|d<Y|Sw)z�
    Disable all beacons jobs on the minion

    :return:                Boolean and status message on success or failure of disable.

    CLI Example:

    .. code-block:: bash

        salt '*' beacons.disable
    Tr2r:�Beacons would be disabled.rrrr
r�disablerz-/salt/minion/minion_beacons_disabled_completerrrrrrbrzDisabled beacons on minion.Fz$Failed to disable beacons on minion.�LDid not receive the beacon disabled complete event before the timeout of {}sNz7Event module not available. Beacons disable job failed.)rrrrrrrr r!r"rIr#rdr-r-r.rfsT

"��
�


������
�rfcCs*i}t|t�rtt|j|��|S|}|S)N)�
isinstancer�map�update)Z
beacon_config�beacon_config_dictr-r-r.�_get_beacon_config_dict:s
�rlc	Ks�gdd�}|sd|d<d|d<|Sd|vr#|dr#d|�d	�|d<|Stdd
di|��}||vr>d|�d�|d<d|d<|Sz�tjjjdtdd
��y}tdd|d�d�}|r�|jd|�dt�d�}|r�|dr�|d}t	||�}d|vr�|dr�d|d<d|�d�|d<n)d|d<d|�d�|d<n|r�d|d<|d|d<nd|d<d�
|�dt��|d<|Wd�WSWd�W|S1s�wYW|Sty�d|d<d|d<Y|Sw)a
    Enable beacon on the minion

    :name:                  Name of the beacon to enable.
    :return:                Boolean and status message on success or failure of enable.

    CLI Example:

    .. code-block:: bash

        salt '*' beacons.enable_beacon ps
    Tr2�Beacon name is required.rFrr:r3z would be enabled.r&� is not currently configured.rrr
�
enable_beacon�rr>rz+/salt/minion/minion_beacon_enabled_completerrrrrbzEnabled beacon z on minion.zFailed to enable beacon rcNz<Event module not available. Beacon enable_beacon job failed.r-�rrrrrrrrr rlrIr#�	r>r'r+Z_beaconsr(r)r*rrkr-r-r.roDsv
5��
�
��
�
����,�,���roc	Ks�gdd�}|sd|d<d|d<|Sd|vr|drd|d<|Stdd	di|��}||vr:d
|�d�|d<d|d<|Sz�tjjjdtdd
��t}tdd|d�d�}|r�|jd|�dt�d�}|r�|dr�|d}t	||�}d|vr�|ds�d|d<d�
|�|d<n%d|d<d|d<n|r�d|d<|d|d<nd|d<d�
|�dt��|d<|Wd�WSWd�W|S1s�wYW|Sty�d|d<d|d<Y|Sw)a
    Disable a beacon on the minion

    :name:                  Name of the beacon to disable.
    :return:                Boolean and status message on success or failure of disable.

    CLI Example:

    .. code-block:: bash

        salt '*' beacons.disable_beacon ps
    Tr2rmrFrr:rer&r3rnrrr
�disable_beaconrprz,/salt/minion/minion_beacon_disabled_completerrrrrbzDisabled beacon {} on minion.z#Failed to disable beacon on minion.rgNz=Event module not available. Beacon disable_beacon job failed.r-rqrrr-r-r.rs�sx
5��
�
��
�

����,�,���rscKsgdd�}|�d�rd|d<|Szhtjjjdtdd��S}tdd	d
id�}|re|jd|�d
t�d�}|rA|drAd|d<d|d<nd|d<|durP|d|d<nd�|�d
t��|d<|Wd�WSWd�W|S1sqwYW|St	y�d|d<d|d<Y|Sw)z~
    Reset beacon configuration on the minion

    CLI Example:

    .. code-block:: bash

        salt '*' beacons.reset
    Tr2r:zBeacons would be reset.rrrr
r�resetrz)/salt/minion/minion_beacon_reset_completerrrrzBeacon configuration reset.FNz@Did not receive the beacon reset event before the timeout of {}sz4Event module not available. Beacon reset job failed.)
rrrrrrrr rIr#)r'r+r(r)r*r-r-r.rt�sL

��
�

������
�rt)TTT)T)�__doc__rV�loggingrZZsalt.utils.eventrZsalt.utils.filesZsalt.utils.yaml�	getLogger�__name__r!r Z__func_alias__rr/rCrSrXr`rarfrlrorsrtr-r-r-r.�<module>s.



:.p;'55
NN