NineSec Team Shell
Server IP : 184.107.3.203  /  Your IP : 216.73.216.51
Web Server : Apache
System : Linux dedicated2.avenfashion.com.ph 4.18.0-553.40.1.el8_10.x86_64 #1 SMP Mon Feb 10 12:11:18 EST 2025 x86_64
User : adminteladeoro ( 1015)
PHP Version : 8.2.28
Disable Function : exec,passthru,shell_exec,system
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /usr/lib/python3.6/site-packages/sos/collector/transports/__pycache__/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //usr/lib/python3.6/site-packages/sos/collector/transports/__pycache__/saltstack.cpython-36.pyc
3

~�g8�@s`ddlZddlZddlZddlZddlmZddlmZmZddl	m
Z
mZGdd�de�ZdS)�N)�RemoteTransport)�ConnectionException�#SaltStackMasterUnsupportedException)�
is_executable�sos_get_command_outputcs�eZdZdZdZdd�Zd�fdd	�	Zd
d�Zdd
�Ze	dd��Z
ddd�Zddd�Zdd�Z
e	dd��Zdd�Zdd�Z�ZS)�SaltStackMasterz�
    A transport for collect that leverages SaltStack's Master Pub/Sub
    functionality to send commands to minions.

    This transport will by default assume the use cmd.shell module to
    execute commands on the minions.
    Z	saltstackcCsttj|�j��dS)Nr)�list�json�loads�values)�selfZjson_output�r
�/usr/lib/python3.6/saltstack.py�_convert_output_json!sz$SaltStackMaster._convert_output_json�FNc
s@t�j|||||�}tjt��|j|d�|d<WdQRX|S)z�
        Run a command on the remote host using SaltStack Master.
        If the output is json, convert it to a string.
        �outputN)�super�run_command�
contextlib�suppress�	Exceptionr)r�cmd�timeoutZ	need_root�envZ	use_shell�ret)�	__class__r
rr$s
zSaltStackMaster.run_commandcCs.d|�d|�d|��}t|dd�}|ddkS)zO
        Execute cp.get_file on the remote host using SaltStack Master
        zsalt-cp � �)r�statusr)r)r�node�fname�destr�resr
r
r�_salt_copy_file0szSaltStackMaster._salt_copy_filecCsZd|�d|��}t|�}|ddkrVd|j�d�}tjj||jd��}tj||�dSd	S)
zK
        Execute cp.push on the remote host using SaltStack Master
        zsalt z	 cp.push rrz/var/cache/salt/master/minions/z/files�/TF)r�address�os�path�join�lstrip�shutilZmove)rrr r!rr"ZcachedirZ
cachedir_filer
r
r�_salt_retrieve_file8sz#SaltStackMaster._salt_retrieve_filecCs|jddd�}|ddkS)z>Check if the remote host is responding using SaltStack Master.zecho Connected�
)rrr)r)rZupr
r
r�	connectedEszSaltStackMaster.connectedcCs,d}t|�}|ddkr$|ddkSt�dS)a�Checks to see if the local system supported SaltStack Master.

        This check relies on feedback from the salt binary. The command being
        run should always generate stderr output, but depending on what that
        output reads we can determine if SaltStack Master is supported or not.

        For our purposes, a host that does not support SaltStack Master is not
        able to run sos collect.

        Returns
            True if SaltStack Master is supported, else raise Exception
        zsalt-run manage.statusrrN)rr)r�passwordrr"r
r
r�_check_for_saltstackLs
z$SaltStackMaster._check_for_saltstackcCs�td�s|jd�dSy|j�Wn tk
rB|jd��YnX|jd�d}|j|dd�}|d	d
krvt|j��|d	dkS)aDConnect to the remote host using SaltStack Master.

        This method will attempt to connect to the remote host using SaltStack
        Master. If the connection fails, an exception will be raised.

        If the connection is successful, the connection will be stored in the
        self._connection attribute.
        Zsaltz salt command is not executable. Fz$Transport is not locally supported. z4Transport is locally supported and service running. zecho Connectedr)rr�r)rZ	log_errorr/rZlog_inforr%)rr.r�resultr
r
r�_connect`s	



zSaltStackMaster._connectcCsdS)NTr
)rr
r
r�_disconnectyszSaltStackMaster._disconnectcCsd}d|�d|j�d�S)z7The remote execution command to use for this transport.z--out json --static --no-colorzsalt rz cmd.exec_code sh )r%)rZ	salt_argsr
r
r�remote_exec|szSaltStackMaster.remote_execcCs|jr|j|j||�SdS)aCopy a file to the remote host using SaltStack Master

        Parameters
            fname   The path to the file on the master
            dest    The path to the destination directory on the remote host

        Returns
            True if the file was copied, else False
        F)r-r#r%)rr r!r
r
r�_copy_file_to_remote�sz$SaltStackMaster._copy_file_to_remotecCs|jr|j|j||�SdS)aRetrieve a file from the remote host using saltstack

        Parameters
            fname   The path to the file on the remote host
            dest    The path to the destination directory on the master

        Returns
            True if the file was retrieved, else False
        F)r-r+r%)rr r!r
r
r�_retrieve_file�szSaltStackMaster._retrieve_file)rFNF)N)N)�__name__�
__module__�__qualname__�__doc__�namerrr#r+�propertyr-r/r2r3r4r5r6�
__classcell__r
r
)rrrs


r)
rr	r&r*Zsos.collector.transportsrZsos.collector.exceptionsrrZ
sos.utilitiesrrrr
r
r
r�<module>s

NineSec Team - 2022