%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/grafana.pyo

�
���^c@@s�dZddlmZmZmZddlZddlZddlm	Z	ddl
mZddlm
Z
d�Zd�Zd	�Zddddd
d�Zdd
d�ZdS(
uC
Manage Grafana Dashboards

This module uses ``elasticsearch``, which can be installed via package, or pip.

You can specify elasticsearch hosts directly to the module, or you can use an
elasticsearch profile via pillars:

.. code-block:: yaml

    mygrafanaprofile:
      hosts:
        - es1.example.com:9200
        - es2.example.com:9200
      index: grafana-dash

.. code-block:: yaml

    # Basic usage (uses default pillar profile key 'grafana')
    Ensure myservice dashboard is managed:
      grafana.dashboard_present:
        - name: myservice
        - dashboard_from_pillar: default
        - rows_from_pillar:
            - systemhealth
            - requests

    # Passing hosts in
    Ensure myservice dashboard is managed:
      grafana.dashboard_present:
        - name: myservice
        - dashboard_from_pillar: default
        - rows:
            - collapse: false
              editable: true
              height: 150px
              title: System Health
              panels:
                - aliasColors: {}
                  id: 200000
                  annotate:
                    enable: false
                  bars: false
                  datasource: null
                  editable: true
                  error: false
                  fill: 7
                  grid:
                    leftMax: 100
                    leftMin: null
                    rightMax: null
                    rightMin: null
                    threshold1: 60
                    threshold1Color: rgb(216, 27, 27)
                    threshold2: null
                    threshold2Color: rgba(234, 112, 112, 0.22)
                  leftYAxisLabel: ''
                  legend:
                    avg: false
                    current: false
                    max: false
                    min: false
                    show: false
                    total: false
                    values: false
                  lines: true
                  linewidth: 1
                  nullPointMode: connected
                  percentage: false
                  pointradius: 5
                  points: false
                  renderer: flot
                  resolution: 100
                  scale: 1
                  seriesOverrides: []
                  span: 4
                  stack: false
                  steppedLine: false
                  targets:
                    - target: cloudwatch.aws.ec2.mysrv.cpuutilization.average
                  title: CPU (asg average)
                  tooltip:
                    query_as_alias: true
                    shared: false
                    value_type: cumulative
                  type: graph
                  x-axis: true
                  y-axis: true
                  y_formats:
                    - short
                    - short
                  zerofill: true
        - rows_from_pillar:
          - systemhealth
          - requests
        - profile:
            hosts:
              - es1.example.com:9200
              - es2.example.com:9200
            index: grafana-dash

    # Using a profile from pillars
    Ensure myservice dashboard is managed:
      grafana.dashboard_present:
        - name: myservice
        - dashboard:
            annotations:
              enable: true
              list: []
            editable: true
            hideAllLegends: false
            hideControls: false
            nav:
              - collapse: false
                enable: true
                notice: false
                now: true
                refresh_intervals:
                  - 10s
                  - 30s
                  - 1m
                  - 5m
                  - 15m
                  - 30m
                  - 1h
                  - 2h
                  - 1d
                status: Stable
                time_options:
                  - 5m
                  - 15m
                  - 1h
                  - 2h
                  - 3h
                  - 4h
                  - 6h
                  - 12h
                  - 1d
                  - 2d
                  - 4d
                  - 7d
                  - 16d
                  - 30d
                type: timepicker
            originalTitle: dockerregistry
            refresh: 1m
            rows: []
            sharedCrosshair: false
            style: dark
            tags: []
            templating:
              enable: true
              list: []
            time:
              from: now-2h
              to: now
            timezone: browser
        - rows_from_pillars:
          - systemhealth
          - requests
        - profile: mygrafanaprofile

The behavior of this module is to create dashboards if they do not exist, to
add rows if they do not exist in existing dashboards, and to update rows if
they exist in dashboards. The module will not manage rows that are not defined,
allowing users to manage their own custom rows.
i(tabsolute_importtprint_functiontunicode_literalsN(tSaltInvocationError(t
DictDiffer(tstring_typescC@sdtkrdStS(u,
    Only load if grafana is available.
    uelasticsearch.existsugrafana(t__salt__tFalse(((s7/usr/lib/python2.7/site-packages/salt/states/grafana.pyt__virtual__�scC@stt|t�rFtd|�}|sLdj|�}t|��qLn|}|jd�}|jd�}||fS(uI
    From a pillar key, or a dictionary, return index and host keys.
    u
config.optionu%Pillar key for profile {0} not found.uhostsuindex(t
isinstanceRRtformatRtget(tprofilet_profiletmsgthoststindex((s7/usr/lib/python2.7/site-packages/salt/states/grafana.pyt_parse_profile�scC@s�tj|�}tj|�}x(|dD]}d|kr)|d=q)q)Wx(|dD]}d|krT|d=qTqTWt||�}|j�p�|j�p�|j�S(u8
    Check if grafana dashboard row and _row differ
    upanelsuid(tcopytdeepcopyRtchangedtaddedtremoved(trowt_rowtrow_copyt	_row_copytpanelt_paneltdiff((s7/usr/lib/python2.7/site-packages/salt/states/grafana.pyt_rows_differ�sugrafanacC@s�i|d6d(d6dd6id6}|s7td��n|rR|rRtd��nt|�\}}|sytd��n|s�td	|�}n|s�g}n|rx^|D]S}	td	|	�}
t|
t�r�x+|
D]}|j|�q�Wq�|j|
�q�Wntd
d|d|d
dd|�}|r�tdd|d|d
dd|�}
|
jdi�jd�}
tj	j
j|
�}
nF|s�td��ntdr�dj
|�|d<d(|d<|S|}
g}g}i}xpt|
d�D]^\}}x2|dD]&}d|kr|j|d�qqWd|kr�|||d<q�q�W|j�|srdg}nx�|D]�}d|kr�td��nx5|dD])}|j|dd�|d|d<q�W|d}||kr|j|�|
dj|�qyn||}t||
d|�ry||
d|<|j|�qyqyW|svt|d<dj
|�|d<|Stdr�dj
|�}|r�dj
||�}n||d<|Sidd 6dd!6|d6tj	j
j|
�d6}td"d|d
dd#|d|d|�}|rit|d<||dd$<d%j
|�}|r\d&j
||�}n||d<n#t|d<d'j
|�}||d<|S()u�
    Ensure the grafana dashboard exists and is managed.

    name
        Name of the grafana dashboard.

    dashboard
        A dict that defines a dashboard that should be managed.

    dashboard_from_pillar
        A pillar key that contains a grafana dashboard dict. Mutually exclusive
        with dashboard.

    rows
        A list of grafana rows.

    rows_from_pillar
        A list of pillar keys that contain lists of grafana dashboard rows.
        Rows defined in the pillars will be appended to the rows defined in the
        state.

    profile
        A pillar key or dict that contains a list of hosts and an
        elasticsearch index to use.
    unameuresultuucommentuchangesuprofile is a required argument.uEdashboard and dashboard_from_pillar are mutually exclusive arguments.u'index is a required key in the profile.u
pillar.getuelasticsearch.existsRtidtdoc_typeu	dashboardRuelasticsearch.getu_sourceuHGrafana dashboard does not exist and no dashboard template was provided.utestu#Dashboard {0} is set to be created.urowsupanelsuidutitleiu!title is a required key for rows.i����uDashboard {0} is up to dateu#Dashboard {0} is set to be updated.u-{0} The following rows set to be updated: {1}uguestuuserugroupuelasticsearch.indextbodyuchangeduUpdated dashboard {0}.u({0} The following rows were updated: {1}uFailed to update dashboard {0}.N(tNoneRRRR	tlisttappendRtsalttutilstjsontloadst__opts__R
t	enumeratetsortRtTruetdumpsR(tnamet	dashboardtdashboard_from_pillartrowstrows_from_pillarRtretRRtkeytpillar_rowsRtexistst
_dashboardtupdate_rowst_idst_datat_nRRRttitleRR!tupdated((s7/usr/lib/python2.7/site-packages/salt/states/grafana.pytdashboard_present�s� "	















	



c	C@s*i|d6dd6dd6id6}t|�\}}|sItd��ntdd|d	|d
dd|�}|r	td
r�dj|�|d<|Stdd|d
dd	|d|�}|r�t|d<||dd<d|dd<q&t|d<dj|�|d<nt|d<dj|�|d<|S(u�
    Ensure the named grafana dashboard is deleted.

    name
        Name of the grafana dashboard.

    profile
        A pillar key or dict that contains a list of hosts and an
        elasticsearch index to use.
    unameuresultuucommentuchangesu'index is a required key in the profile.uelasticsearch.existsRRR u	dashboardRutestu#Dashboard {0} is set to be removed.uelasticsearch.deleteuoldunewuFailed to delete {0} dashboard.uDashboard {0} does not exist.N(R"RRRR)R
R,R(R.RRR3RR6tdeleted((s7/usr/lib/python2.7/site-packages/salt/states/grafana.pytdashboard_absentts,"






(t__doc__t
__future__RRRRtsalt.utils.jsonR%tsalt.exceptionsRtsalt.utils.dictdifferRtsalt.ext.sixRRRRR"R>R@(((s7/usr/lib/python2.7/site-packages/salt/states/grafana.pyt<module>�s 			�

Zerion Mini Shell 1.0