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/states/__pycache__/probes.cpython-310.pyc
o

�N�g<�@s�dZddlZddlZddlZddlZe�e�ZdZ	dd�Z
dd�Zdd	�Zd
d�Z
dd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zddd�ZdS)ax
Network Probes
===============

Configure RPM (JunOS)/SLA (Cisco) probes on the device via NAPALM proxy.

:codeauthor: Mircea Ulinic <ping@mirceaulinic.net> & Jerome Fleury <jf@cloudflare.com>
:maturity:   new
:depends:    napalm
:platform:   unix

Dependencies
------------

- :mod:`napalm probes management module <salt.modules.napalm_probes>`

.. versionadded:: 2016.11.0
�N�probescCstjj�ttt�S)z_
    NAPALM library must be installed for this module to work and run in a (proxy) minion.
    )�salt�utilsZnapalmZvirtual�__opts__�__virtualname__�__file__�rr�F/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/probes.py�__virtual__,sr
cCs|didd�S)zh
    Returns a default structure of the dictionary to be returned as output of the state functions.
    F�)�name�result�changes�commentr)rrrr	�_default_ret8srcCs
td�S)zl
    Will retrieve the probes from the network device using salt module "probes" throught NAPALM proxy.
    z
probes.config)�__salt__rrrr	�_retrieve_rpm_probes@s
rc
Cs�i}|��D]A\}}||vri||<|�di�}|��D]*\}}|�di�}t�|�}	|	�|�|	�|�|	�|�|||vrF|	|||<qq|S)zP
    Updates the probes dictionary with different levels of default values.
    �defaults)�items�pop�copy�deepcopy�update)
rr�expected_probes�
probe_nameZ
probe_testZprobe_defaults�	test_nameZtest_detailsZ
test_defaultsZexpected_test_detailsrrr	�_expand_probesHs0������rcCspt|�}t�|�}|��D](\}}|s|�|�q
|��D]\}}|s*||�|�|�|�s4|�|�qq
dS)zJ
    Will remove empty and useless values from the probes dictionary.
    T)�_ordered_dict_to_dictrrrr�get)rZprobes_copyr�probe_testsr�test_paramsrrr	�
_clean_probesgs �



��r!cCszi}i}i}|sd|iS|sd|iSt|���}t|���}||}||}|D]	}	|�|	�||	<q(|D]	}	|�|	�||	<q4|��D]t\}	}
|�|	i�}t|���}t|
���}
|
|}||
}|D]}|	|vrli||	<||	�||
�|�i�qb|D]}|	|vr�i||	<||	�||�|�i�q{|
��D]\}}|�|i�}||kr�|	|vr�i||	<||	�||i�q�qB|||d�S)zo
    Compares configured probes on the device with the expected configuration and returns the differences.
    �add�remove)r"rr#)�set�keysrrrr)�configured_probesrZ
new_probes�
update_probes�
remove_probesZconfigured_probes_keys_setZexpected_probes_keys_setZnew_probes_keys_setZremove_probes_keys_setrrZconfigured_probe_testsZconfigured_tests_keys_setZexpected_tests_keys_setZnew_tests_keys_setZremove_tests_keys_setrr Zconfigured_test_paramsrrr	�_compare_probes}sP���r)cCstjj�tjj�|��S)zKMandatory to be dict type in order to be used in the NAPALM Jinja template.)rr�json�loads�dumps�rrrr	r�srcC�tdt|�dd�S)zO
    Calls the Salt module "probes" to configure the probes on the device.
    zprobes.set_probesF�Zcommit�rrr-rrr	�_set_rpm_probes���r1cCr.)zY
    Calls the Salt module "probes" to schedule the configured probes on the device.
    zprobes.schedule_probesFr/r0r-rrr	�_schedule_probes�r2r3cCr.)zJ
    Calls the Salt module "probes" to delete probes from the device.
    zprobes.delete_probesFr/r0r-rrr	�_delete_rpm_probes�s��r4cCs�t|�}d}d}t�}|�d�s!|�ddj|�d�d�d��|S|�d	i�}t|t�s.i}t||�}t|�t|�t	||�}	|	�d
�}
|	�d�}|	�d�}t
|
�t
|�t
|�d
�}
|�d|
i�tddurr|�ddd��|Sd}|
r�t|
�}|�d�r�d}n
d}|dj|�d�d�7}|r�t|�}|�d�r�d}n
d}|dj|�d�d�7}|r�t
|�}|�d�r�d}n
d}|dj|�d�d�7}|r�td�\}}t|
�}|�d�r�td�\}}|r�|r�|dkr�d}|�||d��|S)a�
    Ensure the networks device is configured as specified in the state SLS file.
    Probes not specified will be removed, while probes not confiured as expected will trigger config updates.

    :param probes: Defines the probes as expected to be configured on the
        device.  In order to ease the configuration and avoid repeating the
        same parameters for each probe, the next parameter (defaults) can be
        used, providing common characteristics.

    :param defaults: Specifies common parameters for the probes.

    SLS Example:

    .. code-block:: yaml

        rpmprobes:
            probes.managed:
                - probes:
                    probe_name1:
                        probe1_test1:
                            source: 192.168.0.2
                            target: 192.168.0.1
                        probe1_test2:
                            target: 172.17.17.1
                        probe1_test3:
                            target: 8.8.8.8
                            probe_type: http-ping
                    probe_name2:
                        probe2_test1:
                            test_interval: 100
                - defaults:
                    target: 10.10.10.10
                    probe_count: 15
                    test_interval: 3
                    probe_type: icmp-ping

    In the probes configuration, the only mandatory attribute is *target*
    (specified either in probes configuration, either in the defaults
    dictionary).  All the other parameters will use the operating system
    defaults, if not provided:

    - ``source`` - Specifies the source IP Address to be used during the tests.  If
      not specified will use the IP Address of the logical interface loopback0.

    - ``target`` - Destination IP Address.
    - ``probe_count`` - Total number of probes per test (1..15). System
      defaults: 1 on both JunOS & Cisco.
    - ``probe_interval`` - Delay between tests (0..86400 seconds). System
      defaults: 3 on JunOS, 5 on Cisco.
    - ``probe_type`` - Probe request type. Available options:

      - icmp-ping
      - tcp-ping
      - udp-ping

    Using the example configuration above, after running the state, on the device will be configured 4 probes,
    with the following properties:

    .. code-block:: yaml

        probe_name1:
            probe1_test1:
                source: 192.168.0.2
                target: 192.168.0.1
                probe_count: 15
                test_interval: 3
                probe_type: icmp-ping
            probe1_test2:
                target: 172.17.17.1
                probe_count: 15
                test_interval: 3
                probe_type: icmp-ping
            probe1_test3:
                target: 8.8.8.8
                probe_count: 15
                test_interval: 3
                probe_type: http-ping
        probe_name2:
            probe2_test1:
                target: 10.10.10.10
                probe_count: 15
                test_interval: 3
                probe_type: icmp-ping
    Trr
FzDCannot retrieve configurtion of the probes from the device: {reason}r)�reason)r
r�outr"rr#)�added�updated�removedr�testz,Testing mode: configuration was not changed!N)rr
z#Cannot define new probes: {reason}
zCannot update probes: {reason}
zCannot remove probes! {reason}
znet.config_controlzProbes updated successfully!)rrrr�format�
isinstance�dictrr!r)rrr1r4rr3)rrr�retr
rZrpm_probes_configr&r�diffZ
add_probesr'r(rZconfig_change_expectedr7r8r9Z
add_scheduledrrr	�managed�s�V�

���	

�



���
�
�
�
r@)N)�__doc__r�loggingZsalt.utils.jsonrZsalt.utils.napalm�	getLogger�__name__�logrr
rrrr!r)rr1r3r4r@rrrr	�<module>s$
>