Skip to content

Table of Contents

datasource

Datasource Objects

class Datasource()

The class includes all necessary methods to access the Grafana datasource API endpoints. It's required that the API token got the corresponding datasource access rights. Please check the used methods docstring for the necessary access rights

HINT: Note Grafana Enterprise API need required permissions if fine-grained access control is enabled

Arguments:

  • grafana_api_model APIModel - Inject a Grafana API model object that includes all necessary values and information

Attributes:

  • grafana_api_model APIModel - This is where we store the grafana_api_model

get_all_datasources

def get_all_datasources() -> list

The method includes a functionality to get all datasources

Required Permissions: Action: datasources:read Scope: datasources:*

Raises:

  • Exception - Unspecified error by executing the API call

Returns:

  • api_call list - Returns the list of all datasources

get_datasource_by_id

def get_datasource_by_id(datasource_id: int) -> dict

The method includes a functionality to get the datasource specified by the datasource id

Arguments:

  • datasource_id int - Specify the id of the datasource

Required Permissions: - Action - datasources:read - Scope - [datasources:, datasources:id:, datasources:id:]

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call dict - Returns a datasource

get_datasource_by_uid

def get_datasource_by_uid(uid: str) -> dict

The method includes a functionality to get the datasource specified by the datasource uid

Arguments:

  • uid str - Specify the uid of the datasource

Required Permissions: - Action - datasources:read - Scope - [datasources:, datasources:uid:, datasources:uid:]

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call dict - Returns a datasource

get_datasource_by_name

def get_datasource_by_name(name: str) -> dict

The method includes a functionality to get the datasource specified by the datasource name

Arguments:

  • name str - Specify the name of the datasource

Required Permissions: - Action - datasources:read - Scope - [datasources:, datasources:name:, datasources:name:]

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call dict - Returns a datasource

get_datasource_id_by_name

def get_datasource_id_by_name(name: str) -> int

The method includes a functionality to get the datasource id specified by the datasource name

Arguments:

  • name str - Specify the name of the datasource

Required Permissions: - Action - datasources:read - Scope - [datasources:, datasources:name:, datasources:name:]

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call int - Returns a datasource id

create_datasource

def create_datasource(data_source: dict)

The method includes a functionality to create a datasource specified by the datasource as dict

Arguments:

  • data_source dict - Specify the datasource as dict

Required Permissions: - Action - datasources:create

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

None

update_datasource

def update_datasource(datasource_id: int, data_source: dict)

The method includes a functionality to update a datasource specified by the datasource as dict and the datasource id

Arguments:

  • datasource_id int - Specify the id of the datasource
  • data_source dict - Specify the datasource as dict

Required Permissions: - Action - datasources:write - Scope - [datasources:, datasources:id:, datasources:id:]

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

None

delete_datasource_by_id

def delete_datasource_by_id(datasource_id: int)

The method includes a functionality to delete a datasource specified by the datasource id

Arguments:

  • datasource_id int - Specify the id of the datasource

Required Permissions: - Action - datasources:delete - Scope - [datasources:, datasources:id:, datasources:id:]

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

None

delete_datasource_by_uid

def delete_datasource_by_uid(uid: str)

The method includes a functionality to delete a datasource specified by the datasource uid

Arguments:

  • uid str - Specify the uid of the datasource

Required Permissions: - Action - datasources:delete - Scope - [datasources:, datasources:uid:, datasources:uid:]

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

None

delete_datasource_by_name

def delete_datasource_by_name(name: str)

The method includes a functionality to delete a datasource specified by the datasource name

Arguments:

  • name str - Specify the name of the datasource

Required Permissions: - Action - datasources:delete - Scope - [datasources:, datasources:name:, datasources:name:]

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

None

query_datasource_by_id

def query_datasource_by_id(time: str, to: str,
                           datasource_queries: list) -> dict

The method includes a functionality to execute a queries inside the datasource itself specified by the datasource id

Arguments:

  • from str - Specify the name of the absolute in epoch timestamps in milliseconds or relative using Grafana time units. For example, now-1h
  • to str - Specify the name of the absolute in epoch timestamps in milliseconds or relative using Grafana time units. For example, now-1h
  • datasource_queries list - Specify a list of execution queries based on the DatasourceQuery class

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call dict - Returns the result of the specified query

DatasourcePermissions Objects

class DatasourcePermissions()

The class includes all necessary methods to access the Grafana datasource permissions API endpoints. It's required that the API token got the corresponding datasource access rights. Please check the used methods docstring for the necessary access rights

HINT: Note Grafana Enterprise API need required permissions if fine-grained access control is enabled

Arguments:

  • grafana_api_model APIModel - Inject a Grafana API model object that includes all necessary values and information

Attributes:

  • grafana_api_model APIModel - This is where we store the grafana_api_model

get_datasource_permissions_by_uid

def get_datasource_permissions_by_uid(uid: str) -> list

The method includes a functionality to get the datasource permissions specified by the datasource uid. The functionality is a Grafana ENTERPRISE feature

Arguments:

  • uid str - Specify the uid of the datasource

Required Permissions: - Action - datasources.permissions:read - Scope - [datasources:, datasources:uid:, datasources:uid:]

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call list - Returns the datasource permissions

update_datasource_user_access_by_uid

def update_datasource_user_access_by_uid(
        uid: str, id: int, datasource_user_permission: DatasourcePermission)

The method includes a functionality to update the datasource permission specified by the datasource uid and the user id. The functionality is a Grafana ENTERPRISE feature

Arguments:

  • uid str - Specify the uid of the datasource
  • id int - Specify the id of the user
  • datasource_user_permission DatasourcePermission - Specify the datasource user permission

Required Permissions: - Action - datasources.permissions:write - Scope - [datasources:, datasources:uid:, datasources:uid:]

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

None

update_datasource_team_access_by_uid

def update_datasource_team_access_by_uid(
        uid: str, id: int, datasource_team_permission: DatasourcePermission)

The method includes a functionality to update the datasource permission specified by the datasource uid and the team id. The functionality is a Grafana ENTERPRISE feature

Arguments:

  • uid str - Specify the uid of the datasource
  • id int - Specify the id of the team
  • datasource_team_permission DatasourcePermission - Specify the datasource team permission

Required Permissions: - Action - datasources.permissions:write - Scope - [datasources:, datasources:uid:, datasources:uid:]

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

None

update_datasource_basic_role_access_by_uid

def update_datasource_basic_role_access_by_uid(
        uid: str, build_in_role_name: str,
        datasource_team_permission: DatasourcePermission)

The method includes a functionality to update the datasource permission specified by the datasource uid and the build in role name. The functionality is a Grafana ENTERPRISE feature

Arguments:

  • uid str - Specify the uid of the datasource
  • build_in_role_name str - Specify the build in role name
  • datasource_team_permission DatasourcePermission - Specify the datasource team permission

Required Permissions: - Action - datasources.permissions:write - Scope - [datasources:, datasources:uid:, datasources:uid:]

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

None

DatasourceLegacyPermissions Objects

class DatasourceLegacyPermissions()

The class includes all necessary methods to access the Grafana legacy datasource permissions API endpoints. It's required that the API token got the corresponding datasource access rights. Please check the used methods docstring for the necessary access rights

HINT: Note Grafana Enterprise API need required permissions if fine-grained access control is enabled

Arguments:

  • grafana_api_model APIModel - Inject a Grafana API model object that includes all necessary values and information

Attributes:

  • grafana_api_model APIModel - This is where we store the grafana_api_model

enable_datasource_permissions

def enable_datasource_permissions(datasource_id: int)

The method includes a functionality to enable datasource permissions specified by the datasource id. The functionality is a Grafana ENTERPRISE feature

Arguments:

  • datasource_id int - Specify the id of the datasource

Required Permissions: - Action - datasources.permissions:write - Scope - [datasources:, datasources:id:, datasources:id:]

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

None

disable_datasource_permissions

def disable_datasource_permissions(datasource_id: int)

The method includes a functionality to disable datasource permissions specified by the datasource id. The functionality is a Grafana ENTERPRISE feature

Arguments:

  • datasource_id int - Specify the id of the datasource

Required Permissions: - Action - datasources.permissions:write - Scope - [datasources:, datasources:id:, datasources:id:]

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

None

get_datasource_permissions

def get_datasource_permissions(datasource_id: int) -> dict

The method includes a functionality to get the datasource permissions specified by the datasource id. The functionality is a Grafana ENTERPRISE feature

Arguments:

  • datasource_id int - Specify the id of the datasource

Required Permissions: - Action - datasources.permissions:read - Scope - [datasources:, datasources:id:, datasources:id:]

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call dict - Returns the datasource permissions

add_datasource_permissions

def add_datasource_permissions(datasource_id: int,
                               datasource_permission: dict)

The method includes a functionality to add datasource permission specified by the datasource id and the datasource permission dict. The functionality is a Grafana ENTERPRISE feature

Arguments:

  • datasource_id int - Specify the id of the datasource
  • datasource_permission dict - Specify the permission of the datasource

Required Permissions: - Action - datasources.permissions:write - Scope - [datasources:, datasources:id:, datasources:id:]

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

None

delete_datasource_permissions

def delete_datasource_permissions(datasource_id: int, permission_id: int)

The method includes a functionality to delete datasource permission specified by the datasource id and the permission id. The functionality is a Grafana ENTERPRISE feature

Arguments:

  • datasource_id int - Specify the id of the datasource
  • permission_id id - Specify the permission id

Required Permissions: - Action - datasources.permissions:write - Scope - [datasources:, datasources:id:, datasources:id:]

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

None

DatasourceQueryResourceCaching Objects

class DatasourceQueryResourceCaching()

The class includes all necessary methods to access the Grafana datasource query and resource caching API endpoints. It's required that the API token got the corresponding datasource access rights. Please check the used methods docstring for the necessary access rights. The functionality is a Grafana ENTERPRISE feature

HINT: Note Grafana Enterprise API need required permissions if fine-grained access control is enabled

Arguments:

  • grafana_api_model APIModel - Inject a Grafana API model object that includes all necessary values and information

Attributes:

  • grafana_api_model APIModel - This is where we store the grafana_api_model

get_datasource_cache

def get_datasource_cache(uid: str) -> dict

The method includes a functionality to get the datasource cache config specified by the datasource uid

Arguments:

  • uid str - Specify the uid of the datasource

Required Permissions: - Action - datasources.caching:write - Scope - datasources:*

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call dict - Returns a datasource

enable_datasource_cache

def enable_datasource_cache(uid: str) -> dict

The method includes a functionality to enable the datasource cache specified by the datasource uid

Arguments:

  • uid str - Specify the uid of the datasource

Required Permissions: - Action - datasources.caching:read - Scope - datasources:*

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call dict - Returns a datasource

disable_datasource_cache

def disable_datasource_cache(uid: str) -> dict

The method includes a functionality to disable the datasource cache specified by the datasource uid

Arguments:

  • uid str - Specify the uid of the datasource

Required Permissions: - Action - datasources.caching:write - Scope - datasources:*

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call dict - Returns a datasource

clean_datasource_cache

def clean_datasource_cache(uid: str) -> dict

The method includes a functionality to clean the datasource cache of all data sources with caching enabled. The uid of the datasource will only be used to return the configuration for that data source

Arguments:

  • uid str - Specify the uid of the datasource

Required Permissions: - Action - datasources.caching:write - Scope - datasources:*

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call dict - Returns a datasource

update_datasource_cache

def update_datasource_cache(uid: str,
                            datasource_cache: DatasourceCache) -> dict

The method includes a functionality to update the datasource cache specified by the datasource uid

Arguments:

  • uid str - Specify the uid of the datasource
  • datasource_cache DatasourceCache - Specif the datasource cache object

Required Permissions: - Action - datasources.caching:write - Scope - datasources:*

Raises:

  • ValueError - Missed specifying a necessary value
  • Exception - Unspecified error by executing the API call

Returns:

  • api_call dict - Returns a datasource