2016-10-21 18:36:50 -04:00
|
|
|
{%- from "grafana/map.jinja" import client with context %}
|
2016-11-17 08:20:02 -05:00
|
|
|
{%- if client.get('enabled', False) %}
|
2016-10-21 18:36:50 -04:00
|
|
|
|
2017-05-24 04:33:54 -04:00
|
|
|
{%- set datasources = [] %}
|
2016-10-21 18:36:50 -04:00
|
|
|
{%- for datasource_name, datasource in client.datasource.iteritems() %}
|
|
|
|
|
2017-05-24 04:33:54 -04:00
|
|
|
{%- do datasources.append(datasource.type) %}
|
2016-10-21 18:36:50 -04:00
|
|
|
grafana_client_datasource_{{ datasource_name }}:
|
2016-10-29 18:27:24 -04:00
|
|
|
grafana3_datasource.present:
|
2017-05-02 08:00:09 -04:00
|
|
|
- name: {{ datasource.name|default(datasource_name) }}
|
2016-10-21 18:36:50 -04:00
|
|
|
- type: {{ datasource.type }}
|
2018-08-13 12:27:30 -04:00
|
|
|
{%- if datasource.port is defined %}
|
|
|
|
- url: {{ datasource.get('protocol', 'http') }}://{{ datasource.host }}:{{ datasource.port }}{{ datasource.get('url_path', '') }}
|
|
|
|
{%- else %}
|
|
|
|
- url: {{ datasource.get('protocol', 'http') }}://{{ datasource.host }}{{ datasource.get('url_path', '') }}
|
|
|
|
{%- endif %}
|
2016-10-21 18:36:50 -04:00
|
|
|
{%- if datasource.access is defined %}
|
|
|
|
- access: proxy
|
|
|
|
{%- endif %}
|
|
|
|
{%- if datasource.user is defined %}
|
2016-11-02 10:50:17 -04:00
|
|
|
- user: {{ datasource.user }}
|
|
|
|
- password: {{ datasource.password }}
|
|
|
|
{%- endif %}
|
2016-11-17 08:20:02 -05:00
|
|
|
{%- if datasource.get('is_default', False) %}
|
2016-11-03 05:40:29 -04:00
|
|
|
- is_default: {{ datasource.is_default|lower }}
|
2016-11-02 10:50:17 -04:00
|
|
|
{%- endif %}
|
|
|
|
{%- if datasource.database is defined %}
|
|
|
|
- database: {{ datasource.database }}
|
2016-10-21 18:36:50 -04:00
|
|
|
{%- endif %}
|
2018-08-13 12:27:30 -04:00
|
|
|
{%- if datasource.mode is defined %}
|
|
|
|
- mode: {{ datasource.mode }}
|
|
|
|
{%- if datasource.mode == 'keystone' %}
|
|
|
|
- domain: {{ datasource.get('domain', 'default') }}
|
|
|
|
- project: {{ datasource.get('project', 'service') }}
|
|
|
|
{%- endif %}
|
|
|
|
{%- endif %}
|
2016-10-21 18:36:50 -04:00
|
|
|
|
|
|
|
{%- endfor %}
|
|
|
|
|
2016-10-22 06:30:30 -04:00
|
|
|
{%- set raw_dict = {} %}
|
|
|
|
{%- set final_dict = {} %}
|
2018-05-31 07:27:37 -04:00
|
|
|
{%- set parameters = {} %}
|
2016-10-22 06:30:30 -04:00
|
|
|
|
|
|
|
{%- if client.remote_data.engine == 'salt_mine' %}
|
|
|
|
{%- for node_name, node_grains in salt['mine.get']('*', 'grains.items').iteritems() %}
|
2016-11-08 05:55:55 -05:00
|
|
|
{%- if node_grains.grafana is defined %}
|
|
|
|
{%- set raw_dict = salt['grains.filter_by']({'default': raw_dict}, merge=node_grains.grafana.get('dashboard', {})) %}
|
2018-05-31 07:27:37 -04:00
|
|
|
{%- set parameters = salt['grains.filter_by']({'default': parameters}, merge=node_grains.grafana.get('parameters', {})) %}
|
2016-11-08 05:55:55 -05:00
|
|
|
{%- endif %}
|
2016-10-22 06:30:30 -04:00
|
|
|
{%- endfor %}
|
|
|
|
{%- endif %}
|
|
|
|
|
|
|
|
{%- if client.dashboard is defined %}
|
2016-11-08 05:55:55 -05:00
|
|
|
{%- set raw_dict = salt['grains.filter_by']({'default': raw_dict}, merge=client.dashboard) %}
|
2016-10-22 06:30:30 -04:00
|
|
|
{%- endif %}
|
2018-05-31 07:27:37 -04:00
|
|
|
{%- if client.parameters is defined %}
|
|
|
|
{%- set parameters = salt['grains.filter_by']({'default': parameters}, merge=client.parameters) %}
|
|
|
|
{%- endif %}
|
2016-10-22 06:30:30 -04:00
|
|
|
|
|
|
|
{%- for dashboard_name, dashboard in raw_dict.iteritems() %}
|
2016-11-08 05:55:55 -05:00
|
|
|
{%- if dashboard.get('format', 'yaml')|lower == 'yaml' %}
|
|
|
|
# Dashboards in JSON format are considered as blob
|
|
|
|
{%- set rows = [] %}
|
|
|
|
{%- for row_name, row in dashboard.get('row', {}).iteritems() %}
|
|
|
|
{%- set panels = [] %}
|
|
|
|
{%- for panel_name, panel in row.get('panel', {}).iteritems() %}
|
|
|
|
{%- set targets = [] %}
|
|
|
|
{%- for target_name, target in panel.get('target', {}).iteritems() %}
|
|
|
|
{%- do targets.extend([target]) %}
|
|
|
|
{%- endfor %}
|
|
|
|
{%- do panel.update({'targets': targets}) %}
|
|
|
|
{%- do panels.extend([panel]) %}
|
|
|
|
{%- endfor %}
|
|
|
|
{%- do row.update({'panels': panels}) %}
|
|
|
|
{%- do rows.extend([row]) %}
|
|
|
|
{%- endfor %}
|
|
|
|
{%- do dashboard.update({'rows': rows}) %}
|
|
|
|
{%- endif %}
|
|
|
|
|
|
|
|
{%- do final_dict.update({dashboard_name: dashboard}) %}
|
2016-10-22 06:30:30 -04:00
|
|
|
{%- endfor %}
|
|
|
|
|
|
|
|
{%- for dashboard_name, dashboard in final_dict.iteritems() %}
|
2017-05-24 04:33:54 -04:00
|
|
|
{%- if dashboard.datasource is not defined or dashboard.datasource in datasources %}
|
2016-11-08 05:55:55 -05:00
|
|
|
{%- if dashboard.get('enabled', True) %}
|
2016-10-22 06:30:30 -04:00
|
|
|
grafana_client_dashboard_{{ dashboard_name }}:
|
2016-10-29 18:27:24 -04:00
|
|
|
grafana3_dashboard.present:
|
2016-10-22 06:30:30 -04:00
|
|
|
- name: {{ dashboard_name }}
|
2016-11-08 05:55:55 -05:00
|
|
|
{%- if dashboard.get('format', 'yaml')|lower == 'json' %}
|
2018-05-31 07:27:37 -04:00
|
|
|
{%- import dashboard.template as dashboard_template with context %}
|
|
|
|
{%- set dash = dashboard_template|load_json %}
|
2016-11-08 05:55:55 -05:00
|
|
|
- dashboard: {{ dash|json }}
|
|
|
|
- dashboard_format: json
|
|
|
|
{%- else %}
|
2016-10-22 06:30:30 -04:00
|
|
|
- dashboard: {{ dashboard }}
|
2017-01-10 11:08:26 -05:00
|
|
|
{%- if dashboard.base_dashboards is defined %}
|
|
|
|
- base_dashboards_from_pillar: {{ dashboard.base_dashboards|yaml }}
|
|
|
|
{%- endif %}
|
|
|
|
{%- if dashboard.base_rows is defined %}
|
|
|
|
- base_rows_from_pillar: {{ dashboard.base_rows|yaml }}
|
|
|
|
{%- endif %}
|
|
|
|
{%- if dashboard.base_panels is defined %}
|
|
|
|
- base_panels_from_pillar: {{ dashboard.base_panels|yaml }}
|
|
|
|
{%- endif %}
|
2016-11-08 05:55:55 -05:00
|
|
|
{%- endif %}
|
|
|
|
{%- else %}
|
2016-10-29 18:27:24 -04:00
|
|
|
grafana_client_dashboard_{{ dashboard_name }}:
|
|
|
|
grafana3_dashboard.absent:
|
|
|
|
- name: {{ dashboard_name }}
|
2016-11-08 05:55:55 -05:00
|
|
|
{%- endif %}
|
2017-05-24 04:33:54 -04:00
|
|
|
{%- endif %}
|
2016-10-22 06:30:30 -04:00
|
|
|
{%- endfor %}
|
|
|
|
|
2016-10-21 18:36:50 -04:00
|
|
|
{%- endif %}
|