2016-10-21 18:36:50 -04:00
|
|
|
{%- from "grafana/map.jinja" import client with context %}
|
|
|
|
{%- if client.enabled %}
|
|
|
|
|
|
|
|
/etc/salt/minion.d/_grafana.conf:
|
|
|
|
file.managed:
|
|
|
|
- source: salt://grafana/files/_grafana.conf
|
|
|
|
- template: jinja
|
|
|
|
- user: root
|
|
|
|
- group: root
|
|
|
|
|
|
|
|
{%- for datasource_name, datasource in client.datasource.iteritems() %}
|
|
|
|
|
|
|
|
grafana_client_datasource_{{ datasource_name }}:
|
2016-10-29 18:27:24 -04:00
|
|
|
grafana3_datasource.present:
|
2016-10-21 18:36:50 -04:00
|
|
|
- name: {{ datasource_name }}
|
|
|
|
- type: {{ datasource.type }}
|
|
|
|
- url: http://{{ datasource.host }}:{{ datasource.get('port', 80) }}
|
|
|
|
{%- 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 %}
|
|
|
|
{%- if datasource.get('is_default', false) %}
|
|
|
|
- is_default: {{ datasource.is_default }}
|
|
|
|
{%- endif %}
|
|
|
|
{%- if datasource.database is defined %}
|
|
|
|
- database: {{ datasource.database }}
|
2016-10-21 18:36:50 -04:00
|
|
|
{%- endif %}
|
|
|
|
|
|
|
|
{%- endfor %}
|
|
|
|
|
2016-10-22 06:30:30 -04:00
|
|
|
{%- set raw_dict = {} %}
|
|
|
|
{%- set final_dict = {} %}
|
|
|
|
|
|
|
|
{%- if client.remote_data.engine == 'salt_mine' %}
|
|
|
|
{%- for node_name, node_grains in salt['mine.get']('*', 'grains.items').iteritems() %}
|
|
|
|
{%- if node_grains.grafana is defined %}
|
|
|
|
{%- set raw_dict = salt['grains.filter_by']({'default': raw_dict}, merge=node_grains.grafana.get('dashboard', {})) %}
|
|
|
|
{%- endif %}
|
|
|
|
{%- endfor %}
|
|
|
|
{%- endif %}
|
|
|
|
|
|
|
|
{%- if client.dashboard is defined %}
|
|
|
|
{%- set raw_dict = salt['grains.filter_by']({'default': raw_dict}, merge=client.dashboard) %}
|
|
|
|
{%- endif %}
|
|
|
|
|
|
|
|
{%- for dashboard_name, dashboard in raw_dict.iteritems() %}
|
|
|
|
{%- 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}) %}
|
|
|
|
{%- do final_dict.update({dashboard_name: dashboard}) %}
|
|
|
|
{%- endfor %}
|
|
|
|
|
|
|
|
{%- for dashboard_name, dashboard in final_dict.iteritems() %}
|
|
|
|
|
2016-10-29 18:27:24 -04: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 }}
|
|
|
|
- dashboard: {{ dashboard }}
|
|
|
|
|
2016-10-29 18:27:24 -04:00
|
|
|
{%- else %}
|
|
|
|
|
|
|
|
grafana_client_dashboard_{{ dashboard_name }}:
|
|
|
|
grafana3_dashboard.absent:
|
|
|
|
- name: {{ dashboard_name }}
|
|
|
|
|
|
|
|
{%- endif %}
|
|
|
|
|
2016-10-22 06:30:30 -04:00
|
|
|
{%- endfor %}
|
|
|
|
|
2016-10-21 18:36:50 -04:00
|
|
|
{%- endif %}
|