%PDF- %PDF-
Mini Shell

Mini Shell

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

�
���^c@@s�dZddlmZmZmZddlmZmZddlm	Z	ddl
mZd�Zd�Z
d�Zd	�Zd
S(uR
Management of Zabbix hosts.

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


i(tabsolute_importtprint_functiontunicode_literals(tloadstdumps(tdeepcopy(tsixcC@s
dtkS(uI
    Only make these states available if Zabbix module is available.
    uzabbix.host_create(t__salt__(((s;/usr/lib/python2.7/site-packages/salt/states/zabbix_host.pyt__virtual__sc-K@s�i}d|kr#|d|d<nd|kr@|d|d<nd|kr]|d|d<ni|d6id6td6dd6}d	j|�}d
j|�}dj|�}dj|�}	iid
j|�d6d	j|�d6|6}
d�}||�}g}
x�|D]�}t|tj�r�tdd||�}y|
jt|dd��Wq�tk
r~dj|�|d<|SXq
|
j|�q
W|
}d}d|kr�t|dtj�r;yKtddidd6dd6idj|d�d6d 6|�dd}Wq�tk
r7d!j|d�|d<|SXq�y=tddidj|d�d"6dd6|�dd}Wq�tk
r�d!j|d�|d<|SXnd#|kr�i}n
|d#}|dMkr�i}ni}x;|D]3}x*|j
�D]\}}t|�||<q�Wq�Wtd$||�}|rotd%d&||�d}|d'}t}t}t}t}|d(}||kr�t}ntdd)||�}t
�}x%|D]}|jt|d��q�Wt|�t|�kr�t}ntd*d)||�} | r�t| d+d,��} t| �}!x5|!D]-}"|"jd-�|"jd.�|"jd'�q?Wg|D]}#|#|!krw|#^qwg|!D]}$|$|kr�|$^q�}%|%r�t}q�n| r�|r�t}ntd/d)||�}&|&r5d0�|&j
�D�}&|&jd'dM�|&jd1dM�n|rK|&rKt}qot|&�t|�krot}qontd2r�|r�|s�|s�|s�|r�dM|d<||d<q�t|d<|	|d<ndM|d<||d<|
|d<|Sg}'|rGt|d<|s|s|s|r:|r�t|�}(|(j|�t|(d3<td4||(�})t|�|dd#<d5|)kr�|'j|)d5�q�n|r�td6|d7||�})tj|�|dd(<d5|)kr�|'j|)d5�q�n|r:td6|d8||�})tj|�|dd9<d5|)kr:|'j|)d5�q:n|r-| rrx)| D]}*td:d;|*d-|�qMWntd%d||�dd'}x�|D]x}*td<d=|d>|*d?d@|*dAdB|*dCdD|*dEdF|*dGdH|*dI|�}+d5|+kr�|'j|+d5�q�q�Wtj|�|ddJ<n||d<q�|	|d<nwtdK|||d7|dL||�},d5|,kr�t|d<||d<|
|d<n%t|d<|tj|,d5�|d<|'r�i|d<t|d<tj|'�|d<n|S(Nu`
    Ensures that the host exists, eventually creates new host.
    NOTE: please use argument visible_name instead of name to not mess with name from salt sls. This function accepts
    all standard host properties: keyword argument names differ depending on your zabbix version, see:
    https://www.zabbix.com/documentation/2.4/manual/api/reference/host/object#host

    .. versionadded:: 2016.3.0

    :param host: technical name of the host
    :param groups: groupids of host groups to add the host to
    :param interfaces: interfaces to be created for the host
    :param proxy_host: Optional proxy name or proxyid to monitor host
    :param inventory: Optional list of inventory names and values
    :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 visible_name: Optional - string with visible name of the host, use 'visible_name' instead of 'name'     parameter to not mess with value supplied from Salt sls file.

    .. code-block:: yaml

        create_test_host:
            zabbix_host.present:
                - host: TestHostWithInterfaces
                - proxy_host: 12345
                - groups:
                    - 5
                    - 6
                    - 7
                - interfaces:
                    - test1.example.com:
                        - ip: '192.168.1.8'
                        - type: 'Agent'
                        - port: 92
                    - testing2_create:
                        - ip: '192.168.1.9'
                        - dns: 'test2.example.com'
                        - type: 'agent'
                        - main: false
                    - testovaci1_ipmi:
                        - ip: '192.168.100.111'
                        - type: 'ipmi'
                - inventory:
                    - alias: some alias
                    - asset_tag: jlm3937


    u_connection_useru_connection_passwordu_connection_urlunameuchangesuresultuucommentuHost {0} created.uHost {0} updated.uUnable to create host: {0}. uHost {0} already exists.uHost {0} does not exist.uoldunewcS@s:|s
t�Sd}tt|��}t�}x�|D]y}xp|D]h}|}t�||<xL||D]@}x7|j�D])\}}	||kry|	|||<qyqyWqfWqBWq5Wt�}
iddgd	6d
dgd6d
dgd6ddgd6}x|j�D]\}}	||	dj�d}tj|	jdd��j�dkrSdnd}
tj|	jdd��j�dkr�dnd}|	jd�}|	jd|�}tj|	jd||	dj�d��}|
j	i|d6|
d6|d6|d6|d6|d6�qW|
}
t
|
dd�dt�}|S(u�
        Formats interfaces from SLS file into valid JSON usable for zabbix API.
        Completes JSON with default values.

        :param interfaces_data: list of interfaces data from SLS file

        uipudnsumainutypeuuseipuportu1u10050uagentu2u161usnmpu3u623uipmiu4u12345ujmxiutrueu0itkeycS@s|dS(Numain((tk((s;/usr/lib/python2.7/site-packages/salt/states/zabbix_host.pyt<lambda>�streverse(uipudnsumainutypeuuseipuport(tlistRRtdicttitemstlowerRt	text_typetgettappendtsortedtTrue(tinterfaces_datatinterface_attrstinterfaces_jsontinterfaces_dictt	interfacetintft	intf_nametintf_valR	tvaluetinterfaces_listtinterface_portstinterface_typetmaintuseiptinterface_iptdnstporttinterfaces_list_sorted((s;/usr/lib/python2.7/site-packages/salt/states/zabbix_host.pyt_interface_format[s@		


!	*33-uzabbix.hostgroup_gettnameiugroupiduInvalid group {0}u0u
proxy_hostuzabbix.run_queryu	proxy.getuproxyiduoutputuextenduselectInterfaceu{0}uhostufilteruInvalid proxy_host {0}uproxyidsu	inventoryuzabbix.host_existsuzabbix.host_getthostuhostiduproxy_hostidthostidsuzabbix.hostinterface_getR	cS@s|dS(Numain((R
((s;/usr/lib/python2.7/site-packages/salt/states/zabbix_host.pyR�suinterfaceidubulkuzabbix.host_inventory_getcS@s%i|]\}}|r||�qS(((t.0R
tv((s;/usr/lib/python2.7/site-packages/salt/states/zabbix_host.pys
<dictcomp>�s	uinventory_modeutestu	clear_olduzabbix.host_inventory_setuerroruzabbix.host_updatetproxy_hostidtgroupsugroupsuzabbix.hostinterface_deletetinterfaceidsuzabbix.hostinterface_createthostidtipuipR%udnsR"umainttypeutypeR#uuseipR&uportu
interfacesuzabbix.host_createt	inventoryN(tFalsetformatt
isinstanceRtstring_typesRRtintt	TypeErrortNoneRtstrRR
tsetRRtpopt__opts__RtupdateR(-R*R/t
interfacestkwargstconnection_argstrettcomment_host_createdtcomment_host_updatedtcomment_host_notcreatedtcomment_host_existstchanges_host_createdR(tinterfaces_formatedtgroupidstgrouptgroupidR.R4t
new_inventorytinv_itemR
R-thost_existsR1tupdate_proxytupdate_hostgroupstupdate_interfacestupdate_inventorytcur_proxy_hostidt
hostgroupstcur_hostgroupst	hostgroupthostinterfacesthostinterfaces_copythostintftxtytinterface_difft
cur_inventoryterrort
sum_kwargst
hostupdateRt
updatedintthost_create((s;/usr/lib/python2.7/site-packages/salt/states/zabbix_host.pytpresentsJ1"	2




	
	


		
	


"&
	
	

















	


	





cK@s�i|d6id6td6dd6}dj|�}dj|�}dj|�}iid	j|�d
6dj|�d6|6}i}d|kr�|d|d<nd
|kr�|d
|d
<nd|kr�|d|d<ntd||�}tdr+|st|d<||d<nd|d<||d<|Std||�}	|	s[t|d<||d<n�y%|	dd}
td|
|�}Wntk
r�t}nX|r�d|kr�t|d<||d<||d<n%t|d<|tj|d�|d<|S(uR
    Ensures that the host does not exists, eventually deletes host.

    .. versionadded:: 2016.3.0

    :param: name: technical name of the host
    :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

        TestHostWithInterfaces:
            zabbix_host.absent

    unameuchangesuresultuucommentuHost {0} deleted.uUnable to delete host: {0}. uHost {0} does not exist.uHost {0} exists.uoldunewu_connection_useru_connection_passwordu_connection_urluzabbix.host_existsutestuzabbix.host_getiuhostiduzabbix.host_deleteuerrorN(	R5R6RR?RR;tKeyErrorRR(R)RBRDtcomment_host_deletedtcomment_host_notdeletedtcomment_host_notexiststchanges_host_deletedRCRPthost_getR1thost_delete((s;/usr/lib/python2.7/site-packages/salt/states/zabbix_host.pytabsentTsJ"












cK@s�i}d|kr#|d|d<nd|kr@|d|d<nd|kr]|d|d<ni|d6id6td6dd6}d	}d
j|�}d}t}t�}	t�}
d}td||�}|s�t|d<||d<|Std
d||�d}
|
d}|st�}ntd
d|dddd|�}x'|ddD]}|	j|d�qPWxo|D]g}y/tdd||�dd}|
j|�Wqrtk
r�t|d<dj|�|d<|SXqrWtt|
��}
t|	�t|
�krt}niiddj|	�d6ddj|
�d6|6}t	dr�|rld!|d<||d<nt|d<||d<|St|d<|r�td|d |
|�}|tkr�t|d<||d<|S||d<||d<n
||d<|S("u�
    Ensures that templates are assigned to the host.

    .. versionadded:: 2017.7.0

    :param host: technical name of the host
    :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

        add_zabbix_templates_to_host:
            zabbix_host.assign_templates:
                - host: TestHost
                - templates:
                    - "Template OS Linux"
                    - "Template App MySQL"

    u_connection_useru_connection_passwordu_connection_urlunameuchangesuresultuucommentuTemplates updated.u(Unable to update templates on host: {0}.uTemplates already synced.uzabbix.host_existsuzabbix.host_getR*iuhostidR+toutputu[{"hostid"}]tselectParentTemplatesu["templateid"]uparentTemplatesu
templateiduzabbix.template_getuUnable to find template: {0}.uHost templates: u, uoldunewutestuzabbix.host_updatet	templatesN(R5R6R
RRR:R=RtjoinR?R;(R*RpRBRCRDtcomment_host_templates_updatedtcomment_host_templ_notupdatedtcomment_host_templates_in_synctupdate_host_templatestcurr_template_idstrequested_template_idsR1RPt	host_infothost_templatesttemplate_idttemplatetchanges_host_templates_modifiedt
update_output((s;/usr/lib/python2.7/site-packages/salt/states/zabbix_host.pytassign_templates�sz"		


	


		










N(t__doc__t
__future__RRRtjsonRRtcopyRtsalt.extRRReRmR~(((s;/usr/lib/python2.7/site-packages/salt/states/zabbix_host.pyt<module>s		�?	F

Zerion Mini Shell 1.0