%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/states/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/states/zabbix_user.pyo

�
���^c@@s�dZddlmZmZmZddlmZmZddlm	Z	ddl
mZddlm
Z
d�Zdd�Zded	�Zd
�ZdS(uR
Management of Zabbix users.

:codeauthor: Jiri Kotlin <jiri.kotlin@ultimum.io>


i(tabsolute_importtprint_functiontunicode_literals(tloadstdumps(tdeepcopy(tsix(t
SaltExceptioncC@s
dtkS(uI
    Only make these states available if Zabbix module is available.
    uzabbix.user_create(t__salt__(((s;/usr/lib/python2.7/site-packages/salt/states/zabbix_user.pyt__virtual__scK@s|td}d}d}i|d6id6td6dd6}g}i}||d	<d
|krk|d
|d
<ntddd�}	|	r�|j|	�nd
|kr�|j|d
�n|r�|j|�nt�}
g|D]1}||
kr�|
j|�r�tj|�^q�}|j	�|s/d|d<|S|d}
|j|�x�|D]�}||d
<ytd||�}Wn4t
k
r�}dtj|�kr�t}q��nX|rM||
kr�t|d<d|d<|SPqMqMW|rx|s?td|ddd|
|�}|rut|d<dtj|
�d|dd<quqxd|d<dtj|�dtj|
�d|d<n|S(uR
    Initial change of Zabbix Admin password to password taken from one of the sources (only the most prioritized one):
        1. 'password' parameter
        2. '_connection_password' parameter
        3. pillar 'zabbix.password' setting

    1) Tries to log in as Admin with password found in state password parameter or _connection_password
       or pillar or default zabbix password in this precise order, if any of them is present.
    2) If one of above passwords matches, it tries to change the password to the most prioritized one.
    3) If not able to connect with any password then it fails.

    :param name: Just a name of state
    :param password: Optional - desired password for Admin to be set
    :param _connection_user: Optional - Ignored in this state (always assumed 'Admin')
    :param _connection_password: Optional - zabbix password (can also be set in opts or pillar, see module's docstring)
    :param _connection_url: Optional - url of zabbix frontend (can also be set in opts, pillar, see module's docstring)

    .. code-block:: yaml

        # password taken from pillar or _connection_password
        zabbix-admin-password:
            zabbix_user.admin_password_present

        # directly set password
        zabbix-admin-password:
            zabbix_user.admin_password_present:
                - password: SECRET_PASS
    utestuAdminuzabbixunameuchangesuresultuucommentu_connection_useru_connection_urlu
config.optionuzabbix.passwordu_connection_passworduDCould not find any Zabbix Admin password setting! See documentation.iuzabbix.user_getu#Login name or password is incorrectuAdmin password is correct.uzabbix.user_updateuuseridtpasswduchanged to 'u'upasswduPassword for user u
 updated to 'N(t__opts__tFalseRtNonetappendtsettaddRt	text_typetreverseRtTrue(tnametpasswordtkwargstdry_runtdefault_zabbix_usertdefault_zabbix_passwordtrett	passwordstconnection_argstconfig_passwordtseentxtunique_passwordstdesired_passwordtpwdtuser_getterrtuser_update((s;/usr/lib/python2.7/site-packages/salt/states/zabbix_user.pytadmin_password_presentsb
"
	>





	

	
%
/c%K@s�|d1krg}ni}d|kr8|d|d<nd|krU|d|d<nd|krr|d|d<ni|d6id6td6dd6}d	j|�}d
j|�}	dj|�}
dj|�}iid
j|�d6d	j|�d6|6}d�}
td||�}|r�td||�d}|d}t}t}tdd||�}t�}x%|D]}|jt|d��qrWt|�t|�kr�t}ntd||�}|
|�}|rjt	|�}x(|D] }|j
d�|j
d�q�Wg|D]}||kr|^qg|D]}||kr9|^q9}|r�t}q�q�|r�|r�t}q�ntdr�|r�|s�|s�|r�d1|d<|	|d<q�t|d<||d<q�d1|d<||d<ng}|rt|d<|s|s|r	|	|d<|r�td|d||�tdd||�}t�}x%|D]}|jt|d��q_Wtt|�t|��}|r�|jdj|��ntj
|�|dd<n|r%td|d||�} d | kr|j|d �q%d!|dd"<n|rxE|D]=}td#|d|�}!d |!kr2|j|!d �q2q2Wxv|D]n}"td$d|d%|"d&d'|"d(d)|"d*d+|"d,d-|"d.|�}#d |#krz|j|#d �qzqzWtj
|�|dd/<qq�||d<nktd0||||�}$d |$kr\t|d<||d<||d<n%t|d<|
tj
|$d �|d<|r�i|d<t|d<tj
|�|d<n|S(2ux
    Ensures that the user exists, eventually creates new user.
    NOTE: use argument firstname instead of name to not mess values with name from salt sls.

    .. versionadded:: 2016.3.0

    :param alias: user alias
    :param passwd: user's password
    :param usrgrps: user groups to add the user to
    :param medias: Optional - user's medias to create
    :param password_reset: whether or not to reset password at update
    :param _connection_user: Optional - zabbix user (can also be set in opts or pillar, see module's docstring)
    :param _connection_password: Optional - zabbix password (can also be set in opts or pillar, see module's docstring)
    :param _connection_url: Optional - url of zabbix frontend (can also be set in opts, pillar, see module's docstring)
    :param firstname: string with firstname of the user, use 'firstname' instead of 'name' parameter to not mess     with value supplied from Salt sls file.

    .. code-block:: yaml

        make_user:
            zabbix_user.present:
                - alias: George
                - passwd: donottellanyonE@456x
                - password_reset: True
                - usrgrps:
                    - 13
                    - 7
                - medias:
                    - me@example.com:
                        - mediatype: mail
                        - period: '1-7,00:00-24:00'
                        - severity: NIWAHD
                    - make_jabber:
                        - active: true
                        - mediatype: jabber
                        - period: '1-5,08:00-19:00'
                        - sendto: jabbera@example.com
                    - text_me_morning_disabled:
                        - active: false
                        - mediatype: sms
                        - period: '1-5,09:30-10:00'
                        - severity: D
                        - sendto: '+42032132588568'

    u_connection_useru_connection_passwordu_connection_urlunameuchangesuresultuucommentuUser {0} created.uUser {0} updated.uUnable to create user: {0}. uUser {0} already exists.uUser {0} does not exist.uoldunewcS@s$|s
t�Stt|��}d}idd6dd	6d
d6}d}t�}x{|D]s}xj|D]b}t�||<xL||D]@}x7|j�D])\}	}
|	|kr�|
|||	<q�q�Wq�WqcWqVWt�}xG|j�D]9\}	}
tj|
jdd��j�dkrdnd}tj|
jdd��j�}
tj|j|
d��}|
jdd�}|
jd|	�}|
jdd�}tj�}x1|D])}||kr�|d7}q�|d7}q�Wtjt	|d��}|j
i|d6|d6|d6|d6|d6�q�W|S(u�
        Formats medias from SLS file into valid JSON usable for zabbix API.
        Completes JSON with default values.

        :param medias_data: list of media data from SLS file

        uactiveu	mediatypeuperioduseverityusendtoiumailiujabberiusmsuDuHuAuWuIuNutrueu0u1u1-7,00:00-24:00uHDumediatypeid(uactiveu	mediatypeuperioduseverityusendto(uDuHuAuWuIuN(tlistRRtdicttitemsRRtgettlowertintR(tmedias_datatmedias_jsontmedias_attrt
media_typetmedia_severitiestmedias_dicttmediatmedtmedattrtkeytvaluetmedias_listtactivet
mediatype_slstmediatypeidtperiodtsendtotseverity_slstseverity_bintsevtseverity((s;/usr/lib/python2.7/site-packages/salt/states/zabbix_user.pyt
_media_format�sD	


!	3!

uzabbix.user_existsuzabbix.user_getiuuseriduzabbix.usergroup_gettuseridsuusrgrpiduzabbix.user_getmediaumediaidutestuzabbix.user_updatetusrgrpsuUnable to update grpup(s): {0}uusrgrpsR
uerroruupdatedupasswduzabbix.user_deletemediauzabbix.user_addmediaR9uactiveR;umediatypeidR<uperiodR=usendtoRAuseverityumediasuzabbix.user_createN(R
RtformatRR'RR,RRRtpopRRR(%taliasR
RDtmediastpassword_resetRRRtcomment_user_createdtcomment_user_updatedtcomment_user_notcreatedtcomment_user_existstchanges_user_createdRBtuser_existstusertuseridtupdate_usrgrpst
update_mediast
usergroupstcur_usrgrpst	usergrouptuser_mediastmedias_formatedtuser_medias_copytuser_medRtyt
media_diffterrortupdated_groupstusrgrp_difftupdated_passwordt
deletedmedR3t	updatemedtuser_create((s;/usr/lib/python2.7/site-packages/salt/states/zabbix_user.pytpresentys�.	"	1
	
	

"&









	






	






cK@s�i}d|kr#|d|d<nd|kr@|d|d<nd|kr]|d|d<ni|d6id6td6dd6}d	j|�}d
j|�}dj|�}iidj|�d
6dj|�d6|6}td||�}tdr4|st|d<||d<q4d|d<||d<||d<n|sQt|d<||d<n�y%|dd}	td|	|�}
Wntk
r�t}
nX|
r�d|
kr�t|d<||d<||d<n%t|d<|tj|
d�|d<|S(u/
    Ensures that the user does not exist, eventually delete user.

    .. versionadded:: 2016.3.0

    :param name: user alias
    :param _connection_user: Optional - zabbix user (can also be set in opts or pillar, see module's docstring)
    :param _connection_password: Optional - zabbix password (can also be set in opts or pillar, see module's docstring)
    :param _connection_url: Optional - url of zabbix frontend (can also be set in opts, pillar, see module's docstring)

    .. code-block:: yaml

        George:
            zabbix_user.absent

    u_connection_useru_connection_passwordu_connection_urlunameuchangesuresultuucommentuUSer {0} deleted.uUnable to delete user: {0}. uUser {0} does not exist.uUser {0} exists.uolduUser {0} deleted.unewuzabbix.user_getutestiuuseriduzabbix.user_deleteuerrorN(	RRERRRR
tKeyErrorRR(RRRRtcomment_user_deletedtcomment_user_notdeletedtcomment_user_notexiststchanges_user_deletedR#RQtuser_delete((s;/usr/lib/python2.7/site-packages/salt/states/zabbix_user.pytabsentcsH"













N(t__doc__t
__future__RRRtjsonRRtcopyRtsalt.extRtsalt.exceptionsRR	R
R&RRdRk(((s;/usr/lib/python2.7/site-packages/salt/states/zabbix_user.pyt<module>s	^�

Zerion Mini Shell 1.0