%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/modules/win_snmp.pyc

�
���^c@@swdZddlmZmZmZddlZddlZddlm	Z	m
Z
ddlmZdZ
dZdje�Zd	je�Zd
Zd	je�Zidd6d
d6dd6dd6dd6Zidd6dd6d
d6dd6dd6dd6Zeje�ZdZd�Zd�Zd�Zd�Zd �Zdddd!�Z d"�Z!e"d#�Z#d$�Z$d%�Z%dS(&uu
Module for managing SNMP service settings on Windows servers.
The Windows feature 'SNMP-Service' must be installed.
i(tabsolute_importtunicode_literalstprint_functionN(tSaltInvocationErrortCommandExecutionError(tsixuHKLMu1SYSTEM\CurrentControlSet\Services\SNMP\Parametersu{0}\RFC1156Agentu{0}\ValidCommunitiesu!SOFTWARE\Policies\SNMP\ParametersiuNoneiuNotifyiu	Read Onlyiu
Read WriteiuRead CreateuPhysicaluDatalink and subnetworkuInternetu
End-to-endi@uApplicationsuwin_snmpcC@s=tjjj�stdfStdtt�s9tdfStS(u(
    Only works on Windows systems.
    u!Module win_snmp: Requires Windowsureg.key_existsu#Module win_snmp: SNMP not installed(	tsalttutilstplatformt
is_windowstFalset__salt__t_HKEYt	_SNMP_KEYt__virtualname__(((s9/usr/lib/python2.7/site-packages/salt/modules/win_snmp.pyt__virtual__,s


cC@s6|dkst|tj�r"|Stj|d�SdS(u�
    Converts from current users character encoding to unicode.
    When instr has a value of None, the return value of the function
    will also be None.
    uutf8N(tNonet
isinstanceRt	text_type(tinstr((s9/usr/lib/python2.7/site-packages/salt/modules/win_snmp.pyt_to_unicode9scC@s
tt�S(u�
    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
    (tlistt_SERVICE_TYPES(((s9/usr/lib/python2.7/site-packages/salt/modules/win_snmp.pytget_agent_service_typesEs
cC@s
tt�S(u�
    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
    (Rt_PERMISSION_TYPES(((s9/usr/lib/python2.7/site-packages/salt/modules/win_snmp.pytget_permission_typesUs
cC@s*t�}ttj�dd��}t�|d<tdttd�d|d<tdttd�d|d	<tdttd
�d}|dkr�|dj|dd�ncx`|D]X\}}|d
k	r
|dkr
||}|dkr|}|dj|�qq�Pq�Wt|d�|d<|S(u�
    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
    tkeycS@s|d|dfS(Nii((tx((s9/usr/lib/python2.7/site-packages/salt/modules/win_snmp.pyt<lambda>tsuservicesureg.read_valueu
sysContactuvdataucontactusysLocationulocationusysServicesii����N(
tdicttsortedRtitemsRRRt
_AGENT_KEYtappendR(trettsorted_typestcurrent_bitmasktservicetbitmasktremaining_bitmask((s9/usr/lib/python2.7/site-packages/salt/modules/win_snmp.pytget_agent_settingses(	

cC@s9|dk	rbtt|��}xA|D]6}|tkr%dj|t��}t|��q%q%Wntjr�t	|�}t	|�}ni|d6|d6|d6}t
�}||kr�tjd�t
S|dk	r||dkrtdttd|d�qn|dk	r?||dkr?tdttd	|d�q?n|dk	r�t|�t|d�kr�td
�|D��}tjd|�tdttd|d
�q�nt
�}t�}	xC|D];}
||
dk	r�||
||
kr�||
|	|
<q�q�W|	rtjd|	�tStjd|j��t
S(u
    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']"
    u4Invalid service '{0}' specified. Valid services: {1}ucontactulocationuservicesu3Agent settings already contain the provided values.u
reg.set_valueu
sysContactuREG_SZusysLocationcs@s|]}t|VqdS(N(R(t.0R%((s9/usr/lib/python2.7/site-packages/salt/modules/win_snmp.pys	<genexpr>�su Setting sysServices vdata to: %susysServicesu	REG_DWORDu&Unable to configure agent settings: %su*Agent settings configured successfully: %sN(RRtsetRtformatRRRtPY2RR(t_LOGtdebugtTrueRRR tsumRterrorR
tkeys(tcontacttlocationtservicesR%tmessagetsettingstcurrent_settingstvdatatnew_settingstfailed_settingstsetting((s9/usr/lib/python2.7/site-packages/salt/modules/win_snmp.pytset_agent_settings�sP
		
		
cC@s>tdttd�}|ddkr*tSt|dp:d�S(u�
    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
    ureg.read_valueuEnableAuthenticationTrapsuvdatau(value not set)i(RRR
R
tbool(treg_ret((s9/usr/lib/python2.7/site-packages/salt/modules/win_snmp.pytget_auth_traps_enabled�s

cC@s�d}t�}t|�|kr5tjd|�tSt|�}tdtt||d�t�}||kr�tjd||�tStj	d||�t
S(u+
    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'
    uEnableAuthenticationTrapsu'%s already contains the provided value.u
reg.set_valueu	REG_DWORDu&Setting %s configured successfully: %su%Unable to configure %s with value: %s(R@R>R-R.R/tintRRR
R1R
(tstatustvnametcurrent_statusR9t
new_status((s9/usr/lib/python2.7/site-packages/salt/modules/win_snmp.pytset_auth_traps_enabled�s		cC@sUt�}tdtt�r�tjd�tdttdt�}t|t�r�x4|D])}t|t�ssqXnd||d<qXWq�n|s;tjd�tdtt	dt�}t|t�r;xo|D]d}t|t�s�q�nt
j�}x,tD]$}|dt|kr�|}Pq�q�W|||d<q�Wq;n|sQtjd	�n|S(
uE
    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
    ureg.key_existsu.Loading communities from Group Policy settingsureg.list_valuestinclude_defaultuManaged by GPOuvdatau&Loading communities from SNMP settingsuvnameu$Unable to find existing communities.(
RRRt_COMMUNITIES_GPO_KEYR-R.R
RRt_COMMUNITIES_KEYRRR(R"tcurrent_valuest
current_valuetpermissionstpermission_name((s9/usr/lib/python2.7/site-packages/salt/modules/win_snmp.pytget_community_namess6	




c
C@s+t�}tdtt�r8tjd�td��nt�}||kr^tjd�tSx}|D]u}||s�d||<nyt	||}Wn9t
k
r�dj||t	j��}t
|��nX|||<qeWxf|D]^}||kr/||||krCtdtt|||d�qCq�tdtt|�q�Wx;|D]3}||krNtdtt|||d�qNqNWt�}t�}x'|D]}	|	|kr�d||	<q�q�Wx3|D]+}||||kr�||||<q�q�W|rtjd	|�tStjd
|j��tS(u(
    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'}'
    ureg.key_existsu6Communities on this system are managed by Group Policyu0Communities already contain the provided values.uNoneu:Invalid permission '{0}' specified. Valid permissions: {1}u
reg.set_valueu	REG_DWORDureg.delete_valueu#Unable to configure communities: %su'Communities configured successfully: %sN(RRRRHR-R.RRNR/RtKeyErrorR+R2RRIRR1R
(
tcommunitiestvaluestcurrent_communitiesRCR9R6t
current_vnametnew_communitiestfailed_communitiest	new_vname((s9/usr/lib/python2.7/site-packages/salt/modules/win_snmp.pytset_community_names�sX	
	





	
		

(&t__doc__t
__future__RRRtloggingtsalt.utils.platformRtsalt.exceptionsRRtsalt.extRRR
R+R RIt
_SNMP_GPO_KEYRHRRt	getLoggert__name__R-RRRRRR(RR=R@R/RFRNRW(((s9/usr/lib/python2.7/site-packages/salt/modules/win_snmp.pyt<module>sD



	
				-U	#	b

Zerion Mini Shell 1.0