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/modules/__pycache__/nagios.cpython-310.pyc
o

�N�g��@s�dZddlZddlZddlZe�e�ZdZdd�Zddd	�Z	d
d�Z
dd
�Zddd�Zddd�Z
ddd�Zdd�Zdd�Zdd�Zdd�ZdS)zA
Run nagios plugins/checks from salt and get the return as data.
�Nz/usr/lib/nagios/plugins/cCstj�t�rdSdS)z3
    Only load if nagios-plugins are installed
    Znagios)FzOThe nagios execution module cannot be loaded: nagios-plugins are not installed.)�os�path�isdir�	PLUGINDIR�rr�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/nagios.py�__virtual__sr��cmd.retcodecCs4i}t�}||vrt|t�|�d|��dd�}|S)z`
    Execute nagios plugin if it's in the directory with salt command specified in run_type
    � F)Zpython_shell)�list_plugins�__salt__r)�plugin�args�run_type�dataZall_pluginsrrr�_execute_cmds
rc
Cs�td|�}i}|D]3}i||<||}|D]&}t|t�r*tt|����}||}n|}d}t||�}	|||�|||	<qq
|S)a]
    Run one or more nagios plugins from pillar data and get the result of run_type
    The pillar have to be in this format:
    ------
    webserver:
        Ping_google:
            - check_icmp: 8.8.8.8
            - check_icmp: google.com
        Load:
            - check_load: -w 0.8 -c 1
        APT:
            - check_apt
    -------
    �
pillar.getr	)r
�
isinstance�dict�next�iter�keys�_format_dict_key)
�pillar_namer�groupsr�group�commands�commandrrZcommand_keyrrr�_execute_pillar(s


�rcCs,|}|�dd�}|dkrd|}||}|S)Nrr	�_)�replace)rr�key_nameZargs_keyrrrrKsrcC�t||d�}|S)z�
    Run nagios plugin and return all the data execution with cmd.run

    CLI Example:

    .. code-block:: bash

        salt '*' nagios.run check_apt
        salt '*' nagios.run check_icmp '8.8.8.8'
    zcmd.run�r�rrrrrr�runUsr&cCs:i}|durt||�}i||<t||d�}|||d<|S)zC
    Run one nagios plugin and return retcode of the execution
    Nr
�status)rr)rrr"rr'rrr�retcodees
r(cCr#)zN
    Run nagios plugin and return all the data execution with cmd.run_all
    zcmd.run_allr$r%rrr�run_allwsr)cCs�td|�}i}i}|D]V}||}|D]M}t|t�r(tt|����}||}n|}d}|�t|||��d}	t||d�}
||vrKt||d�}	|
|	ksS||vra||vr[i||<|
||d<qq|S)a�
    Run one or more nagios plugins from pillar data and get the result of cmd.retcode
    The pillar have to be in this format::

        ------
        webserver:
            Ping_google:
                - check_icmp: 8.8.8.8
                - check_icmp: google.com
            Load:
                - check_load: -w 0.8 -c 1
            APT:
                - check_apt
        -------

    webserver is the role to check, the next keys are the group and the items
    the check with the arguments if needed

    You must to group different checks(one o more) and always it will return
    the highest value of all the checks

    CLI Example:

    .. code-block:: bash

        salt '*' nagios.retcode webserver
    rr	rr')	r
rrrrr�updater(�int)rr�checkrrrrrrZ
current_valueZ	new_valuerrr�retcode_pillars.

��r-cC�t|t�}|S)a�
    Run one or more nagios plugins from pillar data and get the result of cmd.run
    The pillar have to be in this format::

        ------
        webserver:
            Ping_google:
                - check_icmp: 8.8.8.8
                - check_icmp: google.com
            Load:
                - check_load: -w 0.8 -c 1
            APT:
                - check_apt
        -------

    webserver is the role to check, the next keys are the group and the items
    the check with the arguments if needed

    You have to group different checks in a group

    CLI Example:

    .. code-block:: bash

        salt '*' nagios.run webserver
    )rr&�rrrrr�
run_pillar�s
r0cCr.)a�
    Run one or more nagios plugins from pillar data and get the result of cmd.run_all
    The pillar have to be in this format::

        ------
        webserver:
            Ping_google:
                - check_icmp: 8.8.8.8
                - check_icmp: google.com
            Load:
                - check_load: -w 0.8 -c 1
            APT:
                - check_apt
        -------

    webserver is the role to check, the next keys are the group and the items
    the check with the arguments if needed

    You have to group different checks in a group

    CLI Example:

    .. code-block:: bash

        salt '*' nagios.run webserver
    )rr)r/rrr�run_all_pillar�s
r1cCsNt�t�}g}|D]}tj�t|�}tjt�|�tj@}|r$|�|�q	|S)zw
    List all the nagios plugins

    CLI Example:

    .. code-block:: bash

        salt '*' nagios.list_plugins
    )	r�listdirrr�join�stat�S_IXUSR�ST_MODE�append)Zplugin_list�retrZstat_fZexecute_bitrrrr�s


�r)r	r
)r	)r	N)�__doc__�loggingrr4�	getLogger�__name__�logrrrrrr&r(r)r-r0r1rrrrr�<module>s"



#



=