From d7cfa745e5c41800fb1002eabc7f55e8f37c4108 Mon Sep 17 00:00:00 2001 From: peekjef72 <67902897+peekjef72@users.noreply.github.com> Date: Sat, 24 Oct 2020 14:45:55 +0200 Subject: [PATCH 1/3] add health and datasource proxy --- grafana_api/grafana_face.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/grafana_api/grafana_face.py b/grafana_api/grafana_face.py index 8662af7..7271364 100644 --- a/grafana_api/grafana_face.py +++ b/grafana_api/grafana_face.py @@ -12,7 +12,8 @@ Teams, Snapshots, Annotations, - Notifications + Notifications, + Health ) @@ -49,3 +50,4 @@ def __init__( self.annotations = Annotations(self.api) self.snapshots = Snapshots(self.api) self.notifications = Notifications(self.api) + self.health = Health(self.api) From e674fa2422c81cfe692f309c779c73115fb2a3f0 Mon Sep 17 00:00:00 2001 From: peekjef72 <67902897+peekjef72@users.noreply.github.com> Date: Sat, 24 Oct 2020 14:46:49 +0200 Subject: [PATCH 2/3] add health and datasource proxy --- grafana_api/api/__init__.py | 2 +- grafana_api/api/datasource.py | 30 ++++++++++++++++++++++++++++++ grafana_api/api/health.py | 18 ++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 grafana_api/api/health.py diff --git a/grafana_api/api/__init__.py b/grafana_api/api/__init__.py index 91e15d8..840075e 100644 --- a/grafana_api/api/__init__.py +++ b/grafana_api/api/__init__.py @@ -10,4 +10,4 @@ from .annotations import Annotations from .snapshots import Snapshots from .notifications import Notifications - +from .health import Health diff --git a/grafana_api/api/datasource.py b/grafana_api/api/datasource.py index a96549a..9d5f95c 100644 --- a/grafana_api/api/datasource.py +++ b/grafana_api/api/datasource.py @@ -95,3 +95,33 @@ def delete_datasource_by_name(self, datasource_name): delete_datasource = "/datasources/name/%s" % datasource_name r = self.api.DELETE(delete_datasource) return r + + def get_datasource_proxy_data(self, datasource_id + , query_type='query' + , version='v1' + , expr=None + , time=None + , start=None + , end=None + , step=None + ): + """ + + :param datasource_id: + :param version: api_version currently v1 + :param query_type: query_range |query + :param expr: expr to query + + :return: + """ + get_datasource_path = "/datasources/proxy/{}" \ + '/api/{}/{}?query={}'.format( datasource_id, version, query_type, expr) + if query_type == 'query_range': + get_datasource_path = get_datasource_path + '&start={}&end={}&step={}'.format( + start, end, step) + else: + get_datasource_path = get_datasource_path + '&time={}'.format(time) + r = self.api.GET(get_datasource_path) + return r + + diff --git a/grafana_api/api/health.py b/grafana_api/api/health.py new file mode 100644 index 0000000..d0831ca --- /dev/null +++ b/grafana_api/api/health.py @@ -0,0 +1,18 @@ +from .base import Base + + +class Health(Base): + def __init__(self, api): + super(Health, self).__init__(api) + self.api = api + + def check(self): + """ + + :return: + """ + path = "/health" + r = self.api.GET(path) + return r + + From 281f5ae03f6a9fd957c6155aed0d71cb8a148d3c Mon Sep 17 00:00:00 2001 From: peekjef72 <67902897+peekjef72@users.noreply.github.com> Date: Sat, 24 Oct 2020 14:51:49 +0200 Subject: [PATCH 3/3] replace blank => tab --- grafana_api/api/datasource.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grafana_api/api/datasource.py b/grafana_api/api/datasource.py index 9d5f95c..7b613ce 100644 --- a/grafana_api/api/datasource.py +++ b/grafana_api/api/datasource.py @@ -98,8 +98,8 @@ def delete_datasource_by_name(self, datasource_name): def get_datasource_proxy_data(self, datasource_id , query_type='query' - , version='v1' - , expr=None + , version='v1' + , expr=None , time=None , start=None , end=None