This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
716 additions
and
660 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from .base import Base | ||
from .admin import Admin | ||
from .dashboard import Dashboard | ||
from .datasource import Datasource | ||
from .folder import Folder | ||
from .organisation import Organisation, Organisations | ||
from .search import Search | ||
from .user import User, Users |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from .base import Base | ||
|
||
|
||
class Admin(Base): | ||
def __init__(self, api): | ||
super().__init__(api) | ||
self.api = api | ||
self.path = '/admin' | ||
|
||
def settings(self): | ||
path = 'settings' | ||
r = self.api.GET('/'.join([self.path, path])) | ||
return r | ||
|
||
def stats(self): | ||
path = 'stats' | ||
r = self.api.GET('/'.join([self.path, path])) | ||
return r | ||
|
||
def create_user(self, user): | ||
create_user_path = 'users' | ||
r = self.api.POST(create_user_path, json=user) | ||
return r | ||
|
||
def change_user_password(self, user_id, password): | ||
change_user_password_path = self.path + '/users/%s/password' % (user_id) | ||
r = self.api.PUT(change_user_password_path, json={'password': password}) | ||
return r | ||
|
||
def change_user_permissions(self, user_id, is_grafana_admin): | ||
change_user_permissions = self.path + '/users/%s/permissions' % (user_id) | ||
r = self.api.PUT(change_user_permissions, json={'isGrafanaAdmin': is_grafana_admin}) | ||
return r | ||
|
||
def delete_user(self, user_id): | ||
delete_user_path = '/admin/users/%s' % (user_id) | ||
r = self.api.DELETE(delete_user_path) | ||
return r | ||
|
||
def pause_all_alerts(self, pause): | ||
change_user_permissions = self.path + '/pause-all-alerts' | ||
r = self.api.POST(change_user_permissions, json={'paused': pause}) | ||
return r |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Base(object): | ||
def __init__(self, api): | ||
self.api = api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from .base import Base | ||
|
||
|
||
class Dashboard(Base): | ||
def __init__(self, api): | ||
super().__init__(api) | ||
self.api = api | ||
self.path = '/users' | ||
|
||
def get_dashboard(self, dashboard_uid): | ||
get_dashboard_path = '/dashboards/uid/%s' % (dashboard_uid) | ||
r = self.api.GET(get_dashboard_path) | ||
return r | ||
|
||
def update_dashboard(self, dashboard): | ||
""" | ||
:param dashboard: | ||
:return: | ||
""" | ||
put_dashboard_path = '/dashboards/db' | ||
r = self.api.POST(put_dashboard_path, json=dashboard) | ||
return r | ||
|
||
def delete_dashboard(self, dashboard_uid): | ||
delete_dashboard_path = '/dashboards/uid/%s' % (dashboard_uid) | ||
r = self.api.DELETE(delete_dashboard_path) | ||
return r | ||
|
||
def get_home_dashboard(self): | ||
""" | ||
:return: | ||
""" | ||
get_home_dashboard_path = '/dashboards/home' | ||
r = self.api.GET(get_home_dashboard_path) | ||
return r | ||
|
||
def get_dashboards_tags(self): | ||
""" | ||
:return: | ||
""" | ||
get_dashboards_tags_path = '/dashboards/tags' | ||
r = self.api.GET(get_dashboards_tags_path) | ||
return r | ||
|
||
def get_dashboard_permissions(self, dashboardId): | ||
""" | ||
Gets all existing permissions for the dashboard with the given dashboardId. | ||
:param dashboardId: | ||
""" | ||
return self.api.GET('/dashboards/id/%s/permissions' % dashboardId) | ||
|
||
def update_dashboard_permissions(self, dashboardId, items): | ||
""" | ||
Updates permissions for a dashboard. | ||
This operation will remove existing permissions if they’re not included in the request. | ||
:param dashboardId: Dashboard id | ||
""" | ||
# TODO really relevant to return something? | ||
return self.api.POST('/dashboards/id/%s/permissions' % dashboardId, json=dict(items=items)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
from .base import Base | ||
|
||
|
||
class Datasource(Base): | ||
def __init__(self, api): | ||
super().__init__(api) | ||
self.api = api | ||
self.path = '/users' | ||
|
||
def find_datasource(self, datasource_name): | ||
""" | ||
:param datasource_name: | ||
:return: | ||
""" | ||
get_datasource_path = '/datasources/name/%s' % (datasource_name) | ||
r = self.api.GET(get_datasource_path) | ||
if 'id' in r: | ||
return r['id'] | ||
return -1 | ||
|
||
def get_datasource_by_id(self, datasource_id): | ||
""" | ||
:param datasource_id: | ||
:return: | ||
""" | ||
get_datasource_path = '/datasources/%s' % (datasource_id) | ||
r = self.api.GET(get_datasource_path) | ||
return r | ||
|
||
def get_datasource_by_name(self, datasource_name): | ||
""" | ||
:param datasource_name: | ||
:return: | ||
""" | ||
get_datasource_path = '/datasources/name/%s' % (datasource_name) | ||
r = self.api.GET(get_datasource_path) | ||
return r | ||
|
||
def get_datasource_id_by_name(self, datasource_name): | ||
""" | ||
:param datasource_name: | ||
:return: | ||
""" | ||
get_datasource_path = '/datasources/id/%s' % (datasource_name) | ||
r = self.api.GET(get_datasource_path) | ||
return r | ||
|
||
def create_datasource(self, datasource): | ||
""" | ||
:param datasource: | ||
:return: | ||
""" | ||
create_datasources_path = '/datasources' | ||
r = self.api.POST(create_datasources_path, json=datasource) | ||
return r | ||
|
||
def update_datasource(self, datasource_id, datasource): | ||
""" | ||
:param datasource_id: | ||
:param datasource: | ||
:return: | ||
""" | ||
update_datasource = '/datasources/%s' % (datasource_id) | ||
r = self.api.PUT(update_datasource, json=datasource) | ||
return r | ||
|
||
def list_datasources(self): | ||
""" | ||
:return: | ||
""" | ||
list_datasources_path = '/datasources' | ||
r = self.api.GET(list_datasources_path) | ||
return r | ||
|
||
def delete_datasource_by_id(self, datasource_id): | ||
""" | ||
:param datasource_id: | ||
:return: | ||
""" | ||
delete_datasource = '/datasources/%s' % (datasource_id) | ||
r = self.api.DELETE(delete_datasource) | ||
return r | ||
|
||
def delete_datasource_by_name(self, datasource_name): | ||
""" | ||
:param datasource_name: | ||
:return: | ||
""" | ||
delete_datasource = '/datasources/name/%s' % (datasource_name) | ||
r = self.api.DELETE(delete_datasource) | ||
return r |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from .base import Base | ||
|
||
|
||
class Folder(Base): | ||
def __init__(self, api): | ||
super().__init__(api) | ||
self.api = api | ||
self.path = '/users' | ||
|
||
def get_all_folders(self): | ||
path = '/folders' | ||
r = self.api.GET(path) | ||
return r | ||
|
||
def get_folder(self, uid): | ||
path = '/folders/%s' % (uid) | ||
r = self.api.GET(path) | ||
return r | ||
|
||
def create_folder(self, title, uid=None): | ||
""" | ||
Creates a new folder. | ||
:param title: The title of the folder. | ||
:param uid: Optional unique identifier. | ||
""" | ||
json_data = dict(title=title) | ||
if uid is not None: | ||
json_data['uid'] = uid | ||
return self.api.POST('/folders', json=json_data) | ||
|
||
def update_folder(self, uid, title): | ||
path = '/folders' % (uid) | ||
r = self.api.PUT(path, json={ | ||
"title": title | ||
}) | ||
return r | ||
|
||
def delete_folder(self, uid): | ||
path = '/folders/%s' % (uid) | ||
r = self.api.DELETE(path) | ||
return r | ||
|
||
def get_folder_by_id(self, id): | ||
path = '/folders/id/%s' % (id) | ||
r = self.api.GET(path) | ||
return r | ||
|
||
def get_folder_permissions(self): | ||
path = '/folders/%s/permissions' | ||
r = self.api.GET(path) | ||
return r | ||
|
||
def update_folder_permissions(self, uid, items): | ||
""" | ||
Updates permissions for a folder. | ||
This operation will remove existing permissions if they’re not included in the request. | ||
:param uid: Folder uid | ||
""" | ||
# TODO really relevant to return something? | ||
return self.api.POST('/folders/%s/permissions' % uid, json=dict(items=items)) |
Oops, something went wrong.