{"id":13581805,"url":"https://github.com/grafana-tools/sdk","last_synced_at":"2025-05-15T04:06:54.063Z","repository":{"id":14360684,"uuid":"76408302","full_name":"grafana-tools/sdk","owner":"grafana-tools","description":"Library for using Grafana' structures in Go programs and client for Grafana REST API.","archived":false,"fork":false,"pushed_at":"2023-02-25T12:03:00.000Z","size":806,"stargazers_count":327,"open_issues_count":49,"forks_count":192,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-14T05:56:03.184Z","etag":null,"topics":["client","dashboards","generator","golang","grafana","http","json","library","metrics","monitoring","parser","sdk"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/grafana-tools.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-12-13T23:54:11.000Z","updated_at":"2025-03-28T16:28:58.000Z","dependencies_parsed_at":"2023-01-13T17:54:28.801Z","dependency_job_id":"1fdcd169-16bf-4655-830e-dd8b851db8c3","html_url":"https://github.com/grafana-tools/sdk","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grafana-tools%2Fsdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grafana-tools%2Fsdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grafana-tools%2Fsdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grafana-tools%2Fsdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grafana-tools","download_url":"https://codeload.github.com/grafana-tools/sdk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254270646,"owners_count":22042859,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["client","dashboards","generator","golang","grafana","http","json","library","metrics","monitoring","parser","sdk"],"created_at":"2024-08-01T15:02:15.182Z","updated_at":"2025-05-15T04:06:49.050Z","avatar_url":"https://github.com/grafana-tools.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"\u003c!--*- mode:markdown -*--\u003e\n\n# Grafana SDK [![Go Report Card](https://goreportcard.com/badge/github.com/grafana-tools/sdk)](https://goreportcard.com/report/github.com/grafana-tools/sdk)\n\nSDK for Go language offers a library for interacting with\n[Grafana](http://grafana.org) server from Go applications.  It\nrealizes many of\n[HTTP REST API](https://grafana.com/docs/grafana/latest/http_api/) calls for\nadministration, client, organizations. Beside of them it allows\ncreating of Grafana objects (dashboards, panels, datasources) locally\nand manipulating them for constructing dashboards programmatically.\nIt would be helpful for massive operations on a large set of\nGrafana objects.\n\nIt was made foremost for\n[autograf](https://github.com/grafana-tools/autograf) project but\nlater separated from it and moved to this new repository because the\nlibrary is useful per se.\n\n## Library design principles\n\n1. SDK offers client functionality so it covers Grafana REST API with\n   its requests and responses as close as possible.\n1. SDK maps Grafana objects (dashboard, row, panel, datasource) to\n   similar Go structures but not follows exactly all Grafana\n   abstractions.\n1. It doesn't use any logger, instead API functions could return errors\n   where it need.\n1. Prefere no external deps except Go stdlib.\n1. Cover SDK calls with unit tests.\n\n## Examples [![GoDoc](https://godoc.org/github.com/grafana-tools/sdk?status.svg)](https://godoc.org/github.com/grafana-tools/sdk)\n\n```go\n\tboard := sdk.NewBoard(\"Sample dashboard title\")\n\tboard.ID = 1\n\tboard.Time.From = \"now-30m\"\n\tboard.Time.To = \"now\"\n\trow1 := board.AddRow(\"Sample row title\")\n\trow1.Add(sdk.NewGraph(\"Sample graph\"))\n\tgraph := sdk.NewGraph(\"Sample graph 2\")\n\ttarget := sdk.Target{\n\t\tRefID:      \"A\",\n\t\tDatasource: \"Sample Source 1\",\n\t\tExpr:       \"sample request 1\"}\n\tgraph.AddTarget(\u0026target)\n\trow1.Add(graph)\n\tgrafanaURL := \"http://grafana.host\"\n\tc := sdk.NewClient(grafanaURL, \"grafana-api-key\", sdk.DefaultHTTPClient)\n\tresponse, err := c.SetDashboard(context.TODO() ,*board, sdk.SetDashboardParams{\n\t\tOverwrite: false,\n\t})\n\tif err != nil {\n\t\tfmt.Printf(\"error on uploading dashboard %s\", board.Title)\n\t} else {\n\t\tfmt.Printf(\"dashboard URL: %v\", grafanaURL+*response.URL)\n\t}\n```\n\nThe library includes several demo apps for showing API usage:\n\n* [backup-dashboards](cmd/backup-dashboards) — saves all your dashboards as JSON-files.\n* [backup-datasources](cmd/backup-datasources) — saves all your datasources as JSON-files.\n* [import-datasources](cmd/import-datasources) — imports datasources from JSON-files.\n* [import-dashboards](cmd/import-dashboards) — imports dashboards from JSON-files.\n\nYou need Grafana API key with _admin rights_ for using these utilities.\n\n## Installation [![Build Status](https://travis-ci.org/grafana-tools/sdk.svg?branch=master)](https://travis-ci.org/grafana-tools/sdk)\n\nOf course Go development environment should be set up first. Then:\n\n\tgo get github.com/grafana-tools/sdk\n\nDependency packages have included into\ndistro. [govendor](https://github.com/kardianos/govendor) utility used\nfor vendoring.  The single dependency now is:\n\n\tgo get github.com/gosimple/slug\n\nThe \"slugify\" for URLs is a simple task but this package used in\nGrafana server so it used in the SDK for the compatibility reasons.\n\n## Status of REST API realization [![Coverage Status](https://coveralls.io/repos/github/grafana-tools/sdk/badge.svg?branch=master)](https://coveralls.io/github/grafana-tools/sdk?branch=master)\n\nWork on full API implementation still in progress. Currently\nimplemented only create/update/delete operations for dashboards and\ndatasources. State of support for misc API parts noted below.\n\n| API                         | Status                    |\n|-----------------------------|---------------------------|\n| Authorization               | API tokens and Basic Auth |\n| Annotations                 | partially                 |\n| Dashboards                  | partially                 |\n| Datasources                 | +                         |\n| Alert notification channels | +                         |\n| Organization (current)      | partially                 |\n| Organizations               | partially                 |\n| Users                       | partially                 |\n| User (actual)               | partially                 |\n| Snapshots                   | partially                 |\n| Frontend settings           | -                         |\n| Admin                       | partially                 |\n\nThere is no exact roadmap.  The integration tests are being run against the\nfollowing Grafana versions:\n\n* [6.7.1](./travis.yml)\n* [6.6.2](/.travis.yml)\n* [6.5.3](/.travis.yml)\n* [6.4.5](/.travis.yml)\n\nWith the following Go versions:\n\n* 1.14.x\n* 1.13.x\n* 1.12.x\n* 1.11.x\n\nI still have interest to this library development but not always have\ntime for it. So I gladly accept new contributions. Drop an issue or\n[contact me](grafov@gmail.com).\n\n## Licence\n\nDistributed under Apache v2.0. All rights belong to the SDK\nauthors. There is no authors list yet, you can see the full list of\nthe contributors in the git history. Official repository is\nhttps://github.com/grafana-tools/sdk\n\n## Collection of Grafana tools in Golang\n\n* [github.com/nytm/go-grafana-api](https://github.com/nytm/go-grafana-api) — a golang client of Grafana project currently that realizes parts of the REST API, used for the Grafana Terraform provider.\n* [github.com/adejoux/grafanaclient](https://github.com/adejoux/grafanaclient) — API to manage Grafana 2.0 datasources and dashboards. It lacks features from 2.5 and later Grafana versions.\n* [github.com/mgit-at/grafana-backup](https://github.com/mgit-at/grafana-backup) — just saves dashboards localy.\n* [github.com/raintank/memo](https://github.com/raintank/memo) — send slack mentions to Grafana annotations.\n* [github.com/retzkek/grafctl](https://github.com/retzkek/grafctl) — backup/restore/track dashboards with git.\n* [github.com/grafana/grizzly](https://github.com/grafana/grizzly) — manage Grafana dashboards via CLI and libsonnet/jsonnet\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrafana-tools%2Fsdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrafana-tools%2Fsdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrafana-tools%2Fsdk/lists"}