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__/win_snmp.cpython-310.pyc
o

�N�gn5�@s�dZddlZddlZddlmZmZdZdZe�d�Z	e�d�Z
dZe�d�Zd	d
ddd
d�Z
dd	d
dddd�Ze�e�ZdZdd�Zdd�Zdd�Zdd�Zd%dd�Zdd�Zd&dd �Zd!d"�Zd#d$�ZdS)'zu
Module for managing SNMP service settings on Windows servers.
The Windows feature 'SNMP-Service' must be installed.
�N)�CommandExecutionError�SaltInvocationErrorZHKLMz1SYSTEM\CurrentControlSet\Services\SNMP\Parametersz
\RFC1156Agentz\ValidCommunitiesz!SOFTWARE\Policies\SNMP\Parameters�����)�NoneZNotifyz	Read Onlyz
Read WritezRead Create�@)r	ZPhysicalzDatalink and subnetworkZInternetz
End-to-endZApplicationsZwin_snmpcCs&tjj��sdStdtt�sdStS)z(
    Only works on Windows systems.
    )Fz!Module win_snmp: Requires Windows�reg.key_exists)Fz#Module win_snmp: SNMP not installed)�salt�utils�platformZ
is_windows�	__utils__�_HKEY�	_SNMP_KEY�__virtualname__�rr�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/win_snmp.py�__virtual__*s
rcC�tt�S)z�
    Get the sysServices types that can be configured.

    Returns:
        list: A list of service types.

    CLI Example:

    .. code-block:: bash

        salt '*' win_snmp.get_agent_service_types
    )�list�_SERVICE_TYPESrrrr�get_agent_service_types7�
rcCr)z�
    Get the permission types that can be configured for communities.

    Returns:
        list: A list of permission types.

    CLI Example:

    .. code-block:: bash

        salt '*' win_snmp.get_permission_types
    )r�_PERMISSION_TYPESrrrr�get_permission_typesGrrcCs�t�}tt��dd�d�}t�|d<tdttd�d|d<tdttd	�d|d
<tdttd�d}|dkrD|d�|d
d�n!|D]\}}|durd|dkrd||}|dkrc|}|d�|�qFt|d�|d<|S)z�
    Determine the value of the SNMP sysContact, sysLocation, and sysServices
    settings.

    Returns:
        dict: A dictionary of the agent settings.

    CLI Example:

    .. code-block:: bash

        salt '*' win_snmp.get_agent_settings
    cSs|d|dfS)Nrrr)�xrrr�<lambda>fsz$get_agent_settings.<locals>.<lambda>)�key�services�reg.read_value�
sysContact�vdata�contact�sysLocation�location�sysServicesr���N)	�dict�sortedr�itemsrrr�
_AGENT_KEY�append)�retZsorted_typesZcurrent_bitmask�serviceZbitmaskZremaining_bitmaskrrr�get_agent_settingsWs0
����r0cCsh|durtt|��}|D]}|tvrd�|t��}t|��q|||d�}t�}||kr2t�d�dS|durF||dkrFt	dt
td|d	�|durZ||d
krZt	dt
td|d	�|dur�t|�t|d�kr�td
d�|D��}t�d|�t	dt
td|d�t�}t
�}	|D]}
||
dur�||
||
kr�||
|	|
<q�|	r�t�d|	�dSt�d|���dS)a
    Manage the SNMP sysContact, sysLocation, and sysServices settings.

    Args:
        contact (str, optional): The SNMP contact.

        location (str, optional): The SNMP location.

        services (list, optional): A list of selected services. The possible
            service names can be found via ``win_snmp.get_agent_service_types``.
            To disable all services pass a list of None, ie: ['None']

    Returns:
        bool: True if successful, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' win_snmp.set_agent_settings contact='Contact Name' location='Place' services="['Physical']"
    Nz2Invalid service '{}' specified. Valid services: {})r$r&r z3Agent settings already contain the provided values.Tr$�
reg.set_valuer"ZREG_SZr&r%r css�|]}t|VqdS)N)r)�.0r/rrr�	<genexpr>�s�z%set_agent_settings.<locals>.<genexpr>z Setting sysServices vdata to: %sr'�	REG_DWORDz&Unable to configure agent settings: %sFz*Agent settings configured successfully: %s)r*�setr�formatrrr0�_LOG�debugrrr,�sumr)�error�keys)r$r&r r/�messageZsettingsZcurrent_settingsr#Znew_settingsZfailed_settingsZsettingrrr�set_agent_settings�sT��

�
�
��r=cCs0tdttd�}|ddkrdSt|dpd�S)z�
    Determine whether the host is configured to send authentication traps.

    Returns:
        bool: True if traps are enabled, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' win_snmp.get_auth_traps_enabled
    r!�EnableAuthenticationTrapsr#z(value not set)Fr)rrr�bool)Zreg_retrrr�get_auth_traps_enabled�s
r@TcCstd}t�}t|�|krt�d|�dSt|�}tdtt||d�t�}||kr1t�d||�dSt�d||�dS)	a+
    Manage the sending of authentication traps.

    Args:
        status (bool): True to enable traps. False to disable.

    Returns:
        bool: True if successful, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' win_snmp.set_auth_traps_enabled status='True'
    r>z'%s already contains the provided value.Tr1r4z&Setting %s configured successfully: %sz%Unable to configure %s with value: %sF)	r@r?r7r8�intrrrr:)�status�vnameZcurrent_statusr#Z
new_statusrrr�set_auth_traps_enabled�srDcCs�t�}tdtt�r,t�d�tdtt�}t|t�r,|D]}t|t�s%qd||d<q|sct�d�tdtt�}t|t�rc|D]!}t|t�sIqAd}t	D]}|dt	|kr[|}nqM|||d<qA|sjt�d	�|S)
aE
    Get the current accepted SNMP community names and their permissions.

    If community names are being managed by Group Policy, those values will be
    returned instead like this:

    .. code-block:: bash

        TestCommunity:
            Managed by GPO

    Community names managed normally will denote the permission instead:

    .. code-block:: bash

        TestCommunity:
            Read Only

    Returns:
        dict: A dictionary of community names and permissions.

    CLI Example:

    .. code-block:: bash

        salt '*' win_snmp.get_community_names
    rz.Loading communities from Group Policy settingszreg.list_valueszManaged by GPOr#z&Loading communities from SNMP settings�rCz$Unable to find existing communities.)
r)rr�_COMMUNITIES_GPO_KEYr7r8�
isinstancer�_COMMUNITIES_KEYr)r.Zcurrent_valuesZ
current_valueZpermissionsZpermission_namerrr�get_community_namess4





�
rIc	
Cs�t�}tdtt�rt�d�td��t�}||kr!t�d�dS|D]*}||s-d||<zt||}Wnt	yHt
d�||t�����w|||<q#|D]#}||vrk||||krjtdtt
|||d�qPtd	tt
|�qP|D]}||vr�tdtt
|||d�qvt�}t�}|D]
}||vr�d
||<q�|D]}||||kr�||||<q�|r�t�d|�dSt�d
|���dS)a(
    Manage the SNMP accepted community names and their permissions.

    .. note::
        Settings managed by Group Policy will always take precedence over those
        set using the SNMP interface. Therefore if this function finds Group
        Policy settings it will raise a CommandExecutionError

    Args:
        communities (dict): A dictionary of SNMP community names and
            permissions. The possible permissions can be found via
            ``win_snmp.get_permission_types``.

    Returns:
        bool: True if successful, otherwise False

    Raises:
        CommandExecutionError:
            If SNMP settings are being managed by Group Policy

    CLI Example:

    .. code-block:: bash

        salt '*' win_snmp.set_community_names communities="{'TestCommunity': 'Read Only'}'
    rz6Communities on this system are managed by Group Policyz0Communities already contain the provided values.Tr	z8Invalid permission '{}' specified. Valid permissions: {}r1r4zreg.delete_valueNz#Unable to configure communities: %sFz'Communities configured successfully: %s)r)rrrFr7r8rrIr�KeyErrorrr6r;rHr:)	Zcommunities�valuesZcurrent_communitiesrCr#Z
current_vnameZnew_communitiesZfailed_communitiesZ	new_vnamerrr�set_community_namesrsp
�
���
��	����rL)NNN)T)�__doc__�loggingZsalt.utils.platformrZsalt.exceptionsrrrrr,rHZ
_SNMP_GPO_KEYrFrr�	getLogger�__name__r7rrrrr0r=r@rDrIrLrrrr�<module>sD


��
	

0T
#`