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

Allow basic auth when datasource is adding

This patch fixes an issue to use basic auth when the datasource is
adding for the first time. It also adds a delay when service is started.
This commit is contained in:
Guillaume Thouvenin 2016-11-02 09:04:42 +01:00
parent 3f044b20d6
commit 22a78bd9b5
2 changed files with 17 additions and 6 deletions

View file

@ -127,12 +127,20 @@ def present(name,
ret['changes'] = None ret['changes'] = None
ret['comment'] = 'Data source {0} already up-to-date'.format(name) ret['comment'] = 'Data source {0} already up-to-date'.format(name)
else: else:
if profile.get('grafana_token', False):
requests.post( requests.post(
'{0}/api/datasources'.format(profile['grafana_url']), '{0}/api/datasources'.format(profile['grafana_url']),
data, data,
headers=_get_headers(profile), headers=_get_headers(profile),
timeout=profile.get('grafana_timeout', 3), timeout=profile.get('grafana_timeout', 3),
) )
else:
requests.put(
'{0}/api/datasources'.format(profile['grafana_url']),
data,
auth=_get_auth(profile),
timeout=profile.get('grafana_timeout', 3),
)
ret['result'] = True ret['result'] = True
ret['comment'] = 'New data source {0} added'.format(name) ret['comment'] = 'New data source {0} added'.format(name)
ret['changes'] = data ret['changes'] = data

View file

@ -59,6 +59,9 @@ grafana_service:
service.running: service.running:
- name: {{ server.service }} - name: {{ server.service }}
- enable: true - enable: true
# It is needed if client is trying to set datasource or dashboards before
# server is ready.
- init_delay: 5
- watch: - watch:
- file: /etc/grafana/grafana.ini - file: /etc/grafana/grafana.ini