Package: grafana-api-sdk
Grafana API SDKThe repository includes an SDK for the Grafana API. It's possible to interact with all publicly available Grafana HTTP API endpoints.Differences betweengrafana-client,grafana_apiand thegrafana_api_sdkThe grafana-client is only a fork of the non-maintained grafana_api repository. In general, the grafana-client project started at the same time, as I started this project. The corresponding SDK is a completely new project based on nonother projects and includes a few features that are currently not implemented inside the grafana-client.The core features that are implemented inside this library:All public Grafana API (HTTP) endpoints are supportedFull API support for Grafana legacy alerting, current alerting, alerting channels, and alert provisioningPossibility to specify custom and self-signed certificatesHTTP/2 supportIn general, my focus on this project is to implement and deliver old and new features from the Grafana API, to document all features and functionality clear,ly and to increase the overall test coverage of the project.Currently, supported featuresDashboardCreate/ Update a dashboardDelete a dashboardGet permissions of a dashboardGet permissions of a dashboard by uidUpdate the permissions of a dashboardUpdate the permissions of a dashboard by uidGet all dashboard versionsGet all dashboard versions by uidGet dashboard version of a specific dashboardGet dashboard version of a specific dashboard by uidRestore a dashboard version of a specific dashboardRestore a dashboard version of a specific dashboard by uidCompare two dashboard versions and extract the diff between booth dashboardsGet public dashboardsGet public dashboard by uidCreate public dashboardUpdate public dashboardDelete public dashboardFolderGet folder id by dashboard pathGet all folder ids and folder namesGet all foldersGet folder by uidGet folder by idCreate a folderUpdate a folderDelete a folderGet permissions for a folderUpdate permissions for a folderSearchExecute a custom query against the Grafana search endpointDatasourceGet all datasourcesGet the datasource by idGet the datasource by uidGet the datasource by nameGet the datasource id by nameCreate a new datasourceUpdate a datasourceDelete a datasource by idDelete a datasource by uidDelete a datasource by nameQuery a datasource by idEnabled datasource permissionsDisable datasource permissionsGet datasource permissionsAdd datasource permissionsDelete datasource permissionsDatasource query and resource cachingGet datasource cache by uidEnable datasource cache by uidDisable datasource cache by uidUpdate datasource cache by uidClean all datasource cachesLegacy AlertingGet alertsGet alerts by dashboard idsGet alert by idPause alert by idUnpause alert by idAlertingGet all Alertmanager alertsCreate or update Alertmanager alertsGet Alertmanager group alertsGet all Alertmanager silencesGet Alertmanager silence by idCreate or update Alertmanager silenceDelete Alertmanager silence by idGet Alertmanager statusGet the Alertmanager configCreate or update the Alertmanager configDelete the Alertmanager configTest the Alertmanager receiversGet Prometheus alertsGet Prometheus rulesGet Ruler rulesGet a Ruler groupGet Ruler groups by the namespaceCreate or update the Ruler group by the namespaceDelete a Ruler groupDelete a Ruler namespaceTest a datasource ruleTest a recipient ruleGet the NGAlert organization configurationGet the NGAlert Alertmanager configuration by the organizationCreate or update the NGAlert organization configurationDelete the NGAlert organization configurationAlerting ChannelsGet all notification channelsGet all notification channels (lookup)Get a notification channel by idGet a notification channel by uidCreate an notification channelUpdate a notification channel by idUpdate a notification channel by uidDelete a notification channel by idDelete a notification channel by uidTest a notification channelAlerting ProvisioningGet alert ruleAdd alert ruleUpdate alert ruleUpdate ethe interval fo the alert rule groupDelete alert ruleGet all contact pointsAdd contact pointUpdate contact pointDelete contact pointGet notification policiesAdd notification policiesGet all mute timingsGet mute timingsAdd mute timingUpdate mute timingDelete mute timingGet all message templatesGet message templateCreate or update message templateDelete message templateOrganizationGet current organisationUpdate the current organisation nameAdd a new user and the role to the current organisationGet all users from current organisationGet all users from current organisation (lookup)Update the role of an organisation user by the user idDelete an organisation user by the user idGet an organisation by the idGet an organisation by the nameGet all organisationsCreate an organisationUpdate an organisationDelete an organisationGet organisation usersAdd a new organisation userUpdate an organisation userDelete an organisation userShort URLCreate a short urlUserSearch usersGet user by idGet user by username or emailUpdate the userGet user organizationsGet user teamsSwitch the specific user contextGet the current userUpdate the current userUpdate the current passwordSwitch current user contextGet current user organizationsGet current user teamsStar a dashboardUnstar a dashboardGet auth tokensRevoke auth tokensSnapshotCreate a new snapshotGet all snapshotsGet a specific snapshot by keyDelete snapshot by keyDelete snapshot by delete keyTeamSearch teamGet team by idAdd teamUpdate teamDelete team by idGet team membersAdd team memberDelete team memberGet team preferencesUpdate team preferencesGet external team groupsAdd external team groupDelete external team groupLegacy PlaylistSearch playlistGet playlist by idGet playlist items by idGet playlist dashboards by idCreate playlistUpdate playlist by idDelete playlist by idPlaylistSearch playlistGet playlist by uidGet playlist items by uidGet playlist dashboards by uidCreate playlistUpdate playlist by uidDelete playlist by uidReportingSend reportQuery HistoryAdd query to historyDelete query inside the historyUpdate query inside the historySearch inside the query historyStar a query inside the historyUnstar a query inside the historyOther HTTPGet frontend settingsRenew login sessionGet health statusGet metricsGet Plugin metricsLicensingCheck license availabilityManually force license refreshRemove the license from the databaseAnnotationFind annotationsCreate annotationCreate graphite annotationUpdate annotationDelete annotationFind annotation tagsExternal GroupsGet external groupsAdd external groupRemove external groupAuthenticationGet api tokensCreate a api tokenDelete a api tokenPreferencesGet current user preferencesUpdate current user preferencesGet current org preferencesUpdate current org preferencesAdminGet settingsUpdate settingsGet statsGet preview reportCreate global userUpdate user passwordUpdate user permissionsDelete global userPause all alertsUnpause all alertsGet user auth tokensRevoke user auth tokenLogout userReload dashboard provisioning configurationReload datasource provisioning configurationReload plugins provisioning configurationReload notifications provisioning configurationReload access controls provisioning configurationReload LDAP provisioning configurationRotate data encryption keysService AccountSearch service accountsCreate a service accountGet service account by idUpdate a service accountGet service account token by idCreate service account token by idDelete service account by idMigrate API token to service account by token idRevert the generated service account to API tokenGet service account migration statusHide the API keys tab inside the UIRBACGet statusGet all rolesGet roleCreate roleUpdate roleDelete roleGet user assigned rolesGet user assigned permissionsAdd user role assignmentUpdate user role assignmentRemove user role assignmentGet service account assigned rolesGet service account assigned permissionsAdd service account role assignmentUpdate service account role assignmentRemove service account role assignmentGet team assigned rolesAdd team role assignmentUpdate team role assignmentRemove team role assignmentReset basic roles to their defaultLibraryGet all library elementsGet library element by uidGet library element by nameGet library element connectionsCreate library elementUpdate library elementDelete library elementCorrelationsGet correlationGet all correlations by datasource uidGet all correlationsCreate correlationsUpdate correlationsDelete correlationsInstallationPlease be aware to not install thegrafana-apiandgrafana-api-sdkpackages in parallel and the same environment. This result in name clashes, and it's not possible to use the Grafana API SDK.pip install grafana-api-sdkExampleimportjsonfromgrafana_api.modelimportAPIModelfromgrafana_api.dashboardimportDashboardmodel:APIModel=APIModel(host="test",token="test")dashboard:Dashboard=Dashboard(model)withopen("/tmp/test/test.json")asfile:json_dashboard=json.load(file)dashboard.create_or_update_dashboard(message="Create a new test dashboard",dashboard_json=json_dashboard,dashboard_path="test")TLS/ mTLSIt is possible to pass a custom ssl_context to the underlying library to perform the requests to the HTTP API. For this step and to support custom TLS/ mTLS, there is an option to inject the Python ssl_context. More information can be foundhereand a dummy TLS/ mTLS implementation below.TLSimportsslfromgrafana_api.modelimportAPIModelssl_ctx=ssl.create_default_context(ssl.Purpose.SERVER_AUTH,cafile="/test/path/ca.crt")ssl_ctx.verify_mode=ssl.CERT_REQUIREDmodel:APIModel=APIModel(host="test",token="test",ssl_context=ssl_ctx)mTLSimportsslfromgrafana_api.modelimportAPIModelssl_ctx=ssl.create_default_context(ssl.Purpose.SERVER_AUTH,cafile="/test/path/ca.crt",)ssl_ctx.verify_mode=ssl.CERT_REQUIREDssl_ctx.load_cert_chain(certfile="/test/path/client.crt",keyfile="/test/path/client.key",)model:APIModel=APIModel(host="test",token="test",ssl_context=ssl_ctx)TemplatingIf you want to template your JSON document based on a predefined folder structure you can check out one of my otherprojectand integrate the functionality inside your code.ContributionIf you would like to contribute something, have an improvement request, or want to make a change inside the code, please open a pull request.SupportIf you need support, or you encounter a bug, please don't hesitate to open an issue.DonationsIf you would like to support my work, I ask you to take an unusual action inside the open source community. Donate the money to a non-profit organization like Doctors Without Borders or the Children's Cancer Aid. I will continue to build tools because I like it and it is my passion to develop and share applications.LicenseThis product is available under the Apache 2.0 license.