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/engines/__pycache__/script.cpython-310.pyc
o

�N�g�@spdZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
e�e�Z
dd�Zdd�Zd
dd�ZdS)a�
Send events based on a script's stdout

Example Config

.. code-block:: yaml

    engines:
      - script:
          cmd: /some/script.py -a 1 -b 2
          output: json
          interval: 5
          onchange: false

Script engine configs:

cmd
    Script or command to execute

output
    Any available saltstack deserializer

interval
    How often in seconds to execute the command

onchange
    .. versionadded:: 3006.0

    Only fire an event if the tag-specific output changes. Defaults to False.
�N)�CommandExecutionErrorccs�t|jjd�EdHdS)z'
    Generator that returns stdout
    �N)�iter�stdout�readline)�proc�r�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/engines/script.py�_read_stdout-s�r
cCs8tj�t�}zt||�WStytd|�d���w)zM
    Helper to return known serializer based on
    pass output argument
    zUnknown serializer `z` found for output option)�salt�loader�serializers�__opts__�getattr�AttributeErrorr)�outputr
rrr	�_get_serializer4s
��r�json�Fc
Cs�zt�|�}Wntyt�t|��}Ynwt�d|�t|�}t�d�dkr5t	j
j�ttd�j
}ntd}|r=i}	z�zutj|tjtjd�}t�d|j�t|�D]E}t�|�|�|�}	|	�d	d
�}
|	�di�}|ryd|vrytd|d<|
r�|r�|
|vr�||
|kr�qUt�d
|
�||
|d�|r�|||
<qUt�d|j�|j��|��}|r�t�||��Wntjy�}
zt�|
�WYd
}
~
nd
}
~
wwW|jd
ur�|��n|jd
ur�|��wwt�|�q>)aC
    Parse stdout of a command and generate an event

    The script engine will scrap stdout of the
    given script and generate an event based on the
    presence of the 'tag' key and its value.

    If there is a data obj available, that will also
    be fired along with the tag.

    Example:

        Given the following json output from a script:

            .. code-block:: json

                { "tag" : "lots/of/tacos",
                "data" : { "toppings" : "cilantro" }
                }

        This will fire the event 'lots/of/tacos'
        on the event bus with the data obj as is.

    :param cmd: The command to execute
    :param output: How to deserialize stdout of the script
    :param interval: How often to execute the script
    :param onchange: Only fire an event if the tag-specific output changes
    zscript engine using command %sZ__roleZmasterZsock_dirz
event.sendT)r�stderrzStarting script with pid %d�tagN�data�idz&script engine firing event with tag %s)rrzClosing script with pid %d) �shlex�splitr�str�log�debugrr�getr�utils�eventZget_master_eventZ
fire_eventZ__salt__�
subprocess�Popen�PIPE�STDOUT�pidr
Zdeserialize�infor�close�wait�CalledProcessError�error�poll�	terminate�time�sleep)�cmdr�intervalZonchangeZ
serializerZfire_master�eventsrZ	raw_eventr rr�rc�errr	�startBsp���
�

�
����
�
�
�
�r4)rrF)�__doc__�loggingrr!r-Zsalt.loaderrZsalt.utils.eventZsalt.utils.processZsalt.exceptionsr�	getLogger�__name__rr
rr4rrrr	�<module>s