%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_template.pyo

�
���^c@@sdZddlmZddlmZddlZddlZy*ddlmZddlm	Z	e
ZWnek
r�e
ZnXeje�Zddd	gZd
ddd
ddddfZddddfZiidd6dd6dd6dd6dd6d d!6d"d#6id$d%6d&d'6d%6d(d(6e
d)6d*d+6dd,dgd-6d
6id.d6d/d6dd6dd6dd6d d!6d0d#6id$d%6d$d16d&d'6d%6d(d(6e
d)6d*d+6d/d2d,d3d4d5d6d7dg	d-6d6id8d6d9d6dd6dd6dd6ed!6d:d#6id$d%6d;d<6d&d'6d&d=6d%6d(d(6e
d)6d>d+6d2d,d?d7dd@gd-6d6idAd6dBd6dd6dd6dd6ed!6dCd#6id$d%6d$dD6d&d'6d%6d(d(6e
d)6d*d+6dBd,dgd-6d
6idEd6d/d6dCd6dAd6dBd6ed!6ed#6id$d%6d%6d(d(6e
d)6d*d+6dFgd-6d6idGd6dHd6dd6dd6dd6dd!6dId#6id$d%6d$dJ6d$dK6d$dL6d&dM6d%6dMd(6e
d)6d*d+6dHgd-6d6idNd6d/d6dd6dd6dd6d d!6d0d#6id$d%6d$dO6d&d'6d%6d(d(6e
d)6dPd+6d/d2d7dgd-6d6idQd6dRd6dd6dd6dd6d d!6dSd#6id$d%6d$dT6d&d'6d%6d(d(6e
d)6d*d+6dRdUdgd-6d6i
dVd6d/d6dWd6dNd6d/d6dXd!6d dY6d0d#6id$d%6d$dT6d$d16d&d'6d%6e
d)6d(d(6d*d+6d/dgd-6d6idZd6d9d6dWd6dNd6d/d6ed!6d:d#6id$d%6d$d[6d$d<6d&d'6d&d=6d%6d(d(6e
d)6d>d+6d9dgd-6d6id\d6dBd6dWd6dNd6d/d6ed!6dCd#6id$d%6d$dD6d&d'6d%6d(d(6e
d)6d*d+6dBdgd-6d6id]d6d d6dWd6dNd6d/d6dXd!6d^d#6id$d%6d;d_6d;d`6d;da6d%6d(d(6e
d)6dbd+6d dgd-6d6ZgZdc�Zdd�Zde�Zdf�Zedg�Zdh�Ze
di�Zdj�ZdS(ku�
.. versionadded:: 2017.7

Management of Zabbix Template object over Zabbix API.

:codeauthor: Jakub Sliva <jakub.sliva@ultimum.io>
i(tabsolute_import(tunicode_literalsN(tsix(t
SaltExceptionugroupsuhostsumacrosuapplicationsuitemsugitemsugraphsuscreensu	httpTestsutriggersudiscoveriesuitemprototypesutriggerprototypesugraphprototypesuhostprototypesuapplicationuqtypeu
applicationiduqidnameutemplateidsu
qselectpidutemplateuptypeu
templateidupiduhostidupid_ref_nameuapplicationidsures_id_nameuextenduoutpututrueu	templatedu	inheriteduadjustunameufilteruflagsuro_attrsuitemuitemiduitemidsuselectApplicationsuerroru	lastclockulastnsu	lastvalueu	prevvalueustateutriggeru	triggeridu
triggeridsuexpanduselectDependenciesuexpandExpressionudescriptionu
lastchangeuvalueugraphugraphidugraphidsuselectGraphItemsu	graphitemugitemidutemplatescreenuscreenidu	screenidsuselectUsersuselectUserGroupsuselectScreenItemsu
noInheritanceu
discoveryruleuselectFilterukey_uhttptestu
httptestiduhttptestidsuselectStepsu	nextchecku
itemprototypeudiscoveryidsuruleidu
pid_ref_name2utriggerprototypeu
selectTagsugraphprototypeu
hostprototypeuhostidsuselectGroupLinksuselectGroupPrototypesuselectTemplatesuhostcC@s dtkrtrtStdfS(u�
    Only make these states available if Zabbix module and run_query function is available
    and all 3rd party modules imported.
    uzabbix.run_queryu-Import zabbix or other needed modules failed.(t__salt__t
IMPORTS_OKtTruetFalse(((s?/usr/lib/python2.7/site-packages/salt/states/zabbix_template.pyt__virtual__�scC@s�yJtg|D]}|d^q
�}tg|D]}|d^q0�}Wntk
ritd��nX||}|r�g||BD] }itj|�d6^q�SgS(uX
    If Zabbix template is to be updated then list of assigned hosts must be provided in all or nothing manner to prevent
    some externally assigned hosts to be detached.

    :param defined: list of hosts defined in sls
    :param existing: list of hosts taken from live Zabbix
    :return: list to be updated (combinated or empty list)
    uhostidu0List of hosts in template not defined correctly.(tsettKeyErrorRRt	text_type(tdefinedtexistingthosttdefined_host_idstexisting_host_idstdiffthostid((s?/usr/lib/python2.7/site-packages/salt/states/zabbix_template.pyt_diff_and_merge_host_list�s	#'

cK@s�t|}t|d�}|ji||d6�td|dd||�}|ddkr�|jid|d6�td|dd||�}ng}|r�g|D]}||kr�|^q�S|S(u�
    Make a list of given component type not inherited from other templates because Zabbix API returns only list of all
    and list of inherited component items so we have to do a difference list.

    :param component: Template component (application, item, etc...)
    :param parent_id: ID of existing template the component is assigned to
    :return List of non-inherited (own) components
    uoutputu
qselectpiduzabbix.run_queryuqtypeu.getu	inheritedutrue(tTEMPLATE_COMPONENT_DEFtdicttupdateR(t	componentt	parent_idtkwargstc_deftq_paramstexisting_clist_alltexisting_clist_inheritedtc_all((s?/usr/lib/python2.7/site-packages/salt/states/zabbix_template.pyt_get_existing_template_c_list�s	
!#cC@s_xXtD]P}||krt|drg||D]}|t|d^q2||<qqWdS(u�
    For creation or update of object that have attribute which contains a list Zabbix awaits plain list of IDs while
    querying Zabbix for same object returns list of dicts

    :param obj: Zabbix object parameters
    uadjustuqidnameN(R(tobjtsubcomptitem((s?/usr/lib/python2.7/site-packages/salt/states/zabbix_template.pyt_adjust_object_listss
c@s�td�}td}t|}|d�tg|D]}	|	�^q5�}
tg|D]}	|	�^qX�}|
|}|
|@}
||
}g|D]}	|	�|kr�|	^q�}x|D]}|r�|ji||d6�nd|kr
|ji||d6�nt|�|s�td|dd||�}|r�||d	}tji|d
6dd6|d
6||d|d6|d6�q�q�tji|d
6dd6|d
6dt|ddd6�q�Wg|D]}	|	�|kr�|	^q�}xq|D]i}||d}tji|d
6dd6||gd
6�|s�td|dd||g|�q�q�Wx$|
D]�t��fd�|D�d�}t��fd�|D�d�}td||t
�}|drr|||d|d||d<|||d|d||d<t|d�t|d�tji|d
6dd6|dd
6�|s�td|dd|d|�q�qrqrWdS(u�
    Takes particular component list, compares it with existing, call appropriate API methods - create, update, delete.

    :param component: component name
    :param parent_id: ID of parent entity under which component should be created
    :param defined: list of defined items of named component
    :param existing: list of existing items of named component
    :param template_id: In case that component need also template ID for creation (although parent_id is given?!?!?)
    uzabbix.get_zabbix_id_mapperutestufilterupid_ref_nameu
pid_ref_name2uzabbix.run_queryuqtypeu.createures_id_nameu	componentucreateuactionuparamsu	object_iduCREATED u IDudeleteu.deletec3@s%|]}|��kr|VqdS(N((t.0R"(tcompare_keytobject_name(s?/usr/lib/python2.7/site-packages/salt/states/zabbix_template.pys	<genexpr>Gsc3@s%|]}|��kr|VqdS(N((R$R"(R%R&(s?/usr/lib/python2.7/site-packages/salt/states/zabbix_template.pys	<genexpr>Hsuzabbix.compare_paramsunewuolduupdateu.updateN(Rt__opts__RR	RR#tCHANGE_STACKtappendtnexttNoneR(RRRR
ttemplate_idRtzabbix_id_mappertdry_runRR"tdefined_settexisting_sett
create_sett
update_sett
delete_settcreate_listt
object_paramst
object_createt
object_idstdelete_listt
object_deltobject_id_nametditemteitemtdiff_params((R%R&s?/usr/lib/python2.7/site-packages/salt/states/zabbix_template.pyt_manage_componentsT




##


)

$)
)*
""
""&cK@s�i|d6td6dd6id6}y(tddii|d6d6|�}Wntk
rct}nX|s�t|d<d	j|�|d<nt|d<d
j|�|d<|S(uJ
    Check if Zabbix Template already exists.

    :param name: Zabbix Template name
    :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

        does_zabbix-template-exist:
            zabbix_template.is_present:
                - name: Template OS Linux
    unameuresultuucommentuchangesuzabbix.get_object_id_by_paramsutemplateufilteru%Zabbix Template "{0}" does not exist.uZabbix Template "{0}" exists.(RRRtformatR(tnameRtrett	object_id((s?/usr/lib/python2.7/site-packages/salt/states/zabbix_template.pyt
is_presentVs"(



c)K@s	td�}td}i|d6td6dd6id6}||d<t2i}i}g}	x|D]�}
|
tkr�tj|
�d	kr�||
||
<q`tj|
�d	krKg}x�||
D]|}ii|
d
6|t|
dd6d
6}
x2tD]*}||kr�|||
|<||=q�q�W|	j	|
�|j	|�q�W|||
<q`||
||
<q`Wx'tD]}
|
|krdg||
<qdqdWx8t
D]0}
|
|kr�||
r�||
ng||
<q�Wtd||�}tjdtjt
j|dd���tddidd6dd6dd6dd6dd6i|d6d6|�}tjdtjt
j|dd���|r�t|�dkr�td|d|�nt}|rB||d }|sn|}d!|kr�|d!}|d!=ng}|}d!|kr
|d!}|d!=ng}t||�}td"||t�}d#|krTd!|d#ksZ|r�||d#d!<q�ntd"||t�}|d#r�||d#|d <||d$|d <tjd%tjt
j|dd���tj	id d
6d&d'6|d#d(6�|s?tdd)|d#|�}tjd*tj|��q?q�nrtj	id d
6d+d'6|d(6�|s�tdd,||�}tjd-tj|��|r�|d.d}q�ntjd/t
j|dd��tjd0t
j|	dd��tjd1tjt
jtdd���|s'|rlx�tD]�}tjd2tjt
j|���t|||�}|r�td||�ng}||kr�td||d3i|t|d46d5t|d|�}ng}t|||||�q.Wtjd1tjt
jtdd���xQ|	D]F}|d
} t| d
}!|!d6}"t|!d�}#|#ji||!d46�|#jii| d|!d6d6�td7|"|#|�}$x�tD]�}tjd8tjt
j|���t||$|�}%|%rtd|%|�ng}&||kr?td||d3i||!d46|�}'ng}'t||$|'|&d9||�q�WqWntjd1tjt
jtdd���ts�t|d<d:j|�|d<nXtd;�tD�dH�}(|(rwt|d<|r0d<j|�|d<iid=j|�d$6d>j|�d#6|6|d<q	d?j|�|d<iid@j|�d$6dAj|�d#6|6|d<n�t|d<|r�dBj|�|d<iidCj|�d$6dDj|�d#6|6|d<nDdEj|�|d<iidFj|�d$6dGj|�d#6|6|d<|S(IuJ
    Creates Zabbix Template object or if differs update it according defined parameters. See Zabbix API documentation.

    Zabbix API version: >3.0

    :param name: Zabbix Template name
    :param params: Additional parameters according to Zabbix API documentation
    :param static_host_list: If hosts assigned to the template are controlled
        only by this state or can be also assigned externally
    :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)

    .. note::

        If there is a need to get a value from current zabbix online (e.g. ids of host groups you want the template
        to be associated with), put a dictionary with two keys "query_object" and "query_name" instead of the value.
        In this example we want to create template named "Testing Template", assign it to hostgroup Templates,
        link it to two ceph nodes and create a macro.

    .. note::

        IMPORTANT NOTE:
        Objects (except for template name) are identified by name (or by other key in some exceptional cases)
        so changing name of object means deleting old one and creating new one with new ID !!!

    .. note::

        NOT SUPPORTED FEATURES:
            - linked templates
            - trigger dependencies
            - groups and group prototypes for host prototypes

    SLS Example:

    .. code-block:: yaml

        zabbix-template-present:
            zabbix_template.present:
                - name: Testing Template
                # Do not touch existing assigned hosts
                # True will detach all other hosts than defined here
                - static_host_list: False
                - params:
                    description: Template for Ceph nodes
                    groups:
                        # groups must already exist
                        # template must be at least in one hostgroup
                        - groupid:
                            query_object: hostgroup
                            query_name: Templates
                    macros:
                        - macro: "{$CEPH_CLUSTER_NAME}"
                          value: ceph
                    hosts:
                        # hosts must already exist
                        - hostid:
                            query_object: host
                            query_name: ceph-osd-01
                        - hostid:
                            query_object: host
                            query_name: ceph-osd-02
                    # templates:
                    # Linked templates - not supported by state module but can be linked manually (will not be touched)

                    applications:
                        - name: Ceph OSD
                    items:
                        - name: Ceph OSD avg fill item
                          key_: ceph.osd_avg_fill
                          type: 2
                          value_type: 0
                          delay: 60
                          units: '%'
                          description: 'Average fill of OSD'
                          applications:
                              - applicationid:
                                  query_object: application
                                  query_name: Ceph OSD
                    triggers:
                        - description: "Ceph OSD filled more that 90%"
                          expression: "{{'{'}}Testing Template:ceph.osd_avg_fill.last(){{'}'}}>90"
                          priority: 4
                    discoveries:
                        - name: Mounted filesystem discovery
                          key_: vfs.fs.discovery
                          type: 0
                          delay: 60
                          itemprototypes:
                              - name: Free disk space on {{'{#'}}FSNAME}
                                key_: vfs.fs.size[{{'{#'}}FSNAME},free]
                                type: 0
                                value_type: 3
                                delay: 60
                                applications:
                                    - applicationid:
                                        query_object: application
                                        query_name: Ceph OSD
                          triggerprototypes:
                              - description: "Free disk space is less than 20% on volume {{'{#'}}FSNAME{{'}'}}"
                                expression: "{{'{'}}Testing Template:vfs.fs.size[{{'{#'}}FSNAME},free].last(){{'}'}}<20"
                    graphs:
                        - name: Ceph OSD avg fill graph
                          width: 900
                          height: 200
                          graphtype: 0
                          gitems:
                              - color: F63100
                                itemid:
                                  query_object: item
                                  query_name: Ceph OSD avg fill item
                    screens:
                        - name: Ceph
                          hsize: 1
                          vsize: 1
                          screenitems:
                              - x: 0
                                y: 0
                                resourcetype: 0
                                resourceid:
                                    query_object: graph
                                    query_name: Ceph OSD avg fill graph
    uzabbix.get_zabbix_id_mapperutestunameuresultuucommentuchangesuhostudiscoveriesu	componentufilteru
filter_valu	query_piduzabbix.substitute_paramsu#SUBSTITUTED template_definition: %stindentiuzabbix.run_queryutemplate.getuextenduoutputugroupiduselectGroupsuhostiduselectHostsu
templateiduselectTemplatesuselectMacrosuTEMPLATE get result: %siiutemplateuhostsuzabbix.compare_paramsunewuolduTEMPLATE: update params: %suupdateuactionuparamsutemplate.updateuTEMPLATE update result: %sucreateutemplate.createuTEMPLATE create result: utemplateidsu

template_components: %su

discovery_components: %su

Current CHANGE_STACK: %su




COMPONENT: %s

t
extend_paramsu
qselectpidt
filter_keyuqtypeuzabbix.get_object_id_by_paramsu




PROTOTYPE_NAME: %s

R,uEZabbix Template "{0}" already exists and corresponds to a definition.cs@s5|]+}|ddkr|ddkr|VqdS(u	componentutemplateuactionucreateN((R$R"((s?/usr/lib/python2.7/site-packages/salt/states/zabbix_template.pys	<genexpr>�su'Zabbix Template "{0}" would be created.u%Zabbix Template "{0}" does not exist.u<Zabbix Template "{0}" would be created according definition.uZabbix Template "{0}" created.u$Zabbix Template "{0}" did not exist.u3Zabbix Template "{0}" created according definition.u'Zabbix Template "{0}" would be updated.uZabbix Template "{0}" differs.u<Zabbix Template "{0}" would be updated according definition.uZabbix Template "{0}" updated.uZabbix Template "{0}" differed.u3Zabbix Template "{0}" updated according definition.N(RR'RR(tTEMPLATE_COMPONENT_ORDERRRRtDISCOVERYRULE_COMPONENT_ORDERR)tTEMPLATE_RELATIONStlogtinfotjsontdumpstlenRRRR>RRR?R*R+()R@tparamststatic_host_listRR-R.RAttemplate_definitionttemplate_componentstdiscovery_componentstattrtd_rulestd_ruletd_rule_componentst
proto_nametdefined_objttmpl_gettexisting_objR,tdefined_wo_hostst
defined_hoststexisting_wo_hoststexisting_hostst
hosts_listR=ttmpl_updatettmpl_createRtexisting_c_listtexisting_c_list_substdefined_c_list_substd_rule_componenttq_defRtq_objectRRtexisting_p_listtexisting_p_list_substdefined_p_list_substtmpl_action((s?/usr/lib/python2.7/site-packages/salt/states/zabbix_template.pytpresentws|

"

!





.(
	(5



"
(&""(

"
(


#
"
(
	

cK@s_td}i|d6td6dd6id6}y(tddii|d6d	6|�}Wntk
rmt}nX|s�t|d<d
j|�|d<n�|r�t|d<dj|�|d<iidj|�d
6dj|�d6|6|d<nptdd|g|�}|r[t|d<dj|�|d<iidj|�d
6dj|�d6|6|d<n|S(u]
    Makes the Zabbix Template to be absent (either does not exist or delete it).

    :param name: Zabbix Template name
    :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

        zabbix-template-absent:
            zabbix_template.absent:
                - name: Ceph OSD
    utestunameuresultuucommentuchangesuzabbix.get_object_id_by_paramsutemplateufilteru%Zabbix Template "{0}" does not exist.u'Zabbix Template "{0}" would be deleted.uZabbix Template "{0}" exists.uoldunewuzabbix.run_queryutemplate.deleteuZabbix Template "{0}" deleted.uZabbix Template "{0}" existed.(R'RRRRR?(R@RR.RARBttmpl_delete((s?/usr/lib/python2.7/site-packages/salt/states/zabbix_template.pytabsent�s*
"(




(t__doc__t
__future__RRtloggingRLtsalt.extRtsalt.exceptionsRRRtImportErrorRt	getLoggert__name__RJRIRGRHR+RR(RRRR#R>RCRmRo(((s?/usr/lib/python2.7/site-packages/salt/states/zabbix_template.pyt<module>sn


	











	
			B	!�H

Zerion Mini Shell 1.0