Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow datasource update and fixing broken delete function #272

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion grafana_backup/create_datasource.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from grafana_backup.dashboardApi import create_datasource
from grafana_backup.dashboardApi import create_datasource,update_datasource


def main(args, settings, file_path):
Expand All @@ -14,4 +14,6 @@ def main(args, settings, file_path):

datasource = json.loads(data)
result = create_datasource(json.dumps(datasource), grafana_url, http_post_headers, verify_ssl, client_cert, debug)
if result[0] != 200:
result = update_datasource(datasource['uid'],json.dumps(datasource), grafana_url, http_post_headers, verify_ssl, client_cert, debug)
print("create datasource: {0}, status: {1}, msg: {2}".format(datasource['name'], result[0], result[1]))
3 changes: 3 additions & 0 deletions grafana_backup/dashboardApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ def create_snapshot(payload, grafana_url, http_post_headers, verify_ssl, client_
def create_datasource(payload, grafana_url, http_post_headers, verify_ssl, client_cert, debug):
return send_grafana_post('{0}/api/datasources'.format(grafana_url), payload, http_post_headers, verify_ssl,
client_cert, debug)
def update_datasource(uid, payload, grafana_url, http_post_headers, verify_ssl, client_cert, debug):
return send_grafana_put('{0}/api/datasources/uid/{1}'.format(grafana_url,uid), payload, http_post_headers, verify_ssl,
client_cert, debug)


def delete_datasource_by_uid(uid, grafana_url, http_post_headers, verify_ssl, client_cert, debug):
Expand Down
2 changes: 1 addition & 1 deletion grafana_backup/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def main(args, settings):
'team-members': delete_team_members}

(status, json_resp, dashboard_uid_support,
datasource_uid_support, paging_support) = api_checks(settings)
datasource_uid_support, paging_support, is_contact_point_available) = api_checks(settings)

# Do not continue if API is unavailable or token is not valid
if not status == 200:
Expand Down