1
0
Fork 0
mirror of synced 2024-11-22 00:45:34 -05:00

Rework grafana.client state

- add 'parameters' section loaded from grains to pass parameters
into dashboard template
- pass context into json dashboard template

Change-Id: I5848c315abe6951b5572b4c63db2d847395ae725
Related-PROD: PROD-18535
This commit is contained in:
Ildar Svetlov 2018-05-31 15:27:37 +04:00
parent d1d13a4c1f
commit 2d26b366a1

View file

@ -28,11 +28,13 @@ grafana_client_datasource_{{ datasource_name }}:
{%- set raw_dict = {} %} {%- set raw_dict = {} %}
{%- set final_dict = {} %} {%- set final_dict = {} %}
{%- set parameters = {} %}
{%- if client.remote_data.engine == 'salt_mine' %} {%- if client.remote_data.engine == 'salt_mine' %}
{%- for node_name, node_grains in salt['mine.get']('*', 'grains.items').iteritems() %} {%- for node_name, node_grains in salt['mine.get']('*', 'grains.items').iteritems() %}
{%- if node_grains.grafana is defined %} {%- if node_grains.grafana is defined %}
{%- set raw_dict = salt['grains.filter_by']({'default': raw_dict}, merge=node_grains.grafana.get('dashboard', {})) %} {%- set raw_dict = salt['grains.filter_by']({'default': raw_dict}, merge=node_grains.grafana.get('dashboard', {})) %}
{%- set parameters = salt['grains.filter_by']({'default': parameters}, merge=node_grains.grafana.get('parameters', {})) %}
{%- endif %} {%- endif %}
{%- endfor %} {%- endfor %}
{%- endif %} {%- endif %}
@ -40,6 +42,9 @@ grafana_client_datasource_{{ datasource_name }}:
{%- if client.dashboard is defined %} {%- if client.dashboard is defined %}
{%- set raw_dict = salt['grains.filter_by']({'default': raw_dict}, merge=client.dashboard) %} {%- set raw_dict = salt['grains.filter_by']({'default': raw_dict}, merge=client.dashboard) %}
{%- endif %} {%- endif %}
{%- if client.parameters is defined %}
{%- set parameters = salt['grains.filter_by']({'default': parameters}, merge=client.parameters) %}
{%- endif %}
{%- for dashboard_name, dashboard in raw_dict.iteritems() %} {%- for dashboard_name, dashboard in raw_dict.iteritems() %}
{%- if dashboard.get('format', 'yaml')|lower == 'yaml' %} {%- if dashboard.get('format', 'yaml')|lower == 'yaml' %}
@ -71,7 +76,8 @@ grafana_client_dashboard_{{ dashboard_name }}:
grafana3_dashboard.present: grafana3_dashboard.present:
- name: {{ dashboard_name }} - name: {{ dashboard_name }}
{%- if dashboard.get('format', 'yaml')|lower == 'json' %} {%- if dashboard.get('format', 'yaml')|lower == 'json' %}
{%- import_json dashboard.template as dash %} {%- import dashboard.template as dashboard_template with context %}
{%- set dash = dashboard_template|load_json %}
- dashboard: {{ dash|json }} - dashboard: {{ dash|json }}
- dashboard_format: json - dashboard_format: json
{%- else %} {%- else %}