Categorygithub.com/yext/sdk
modulepackage
0.0.0-20250304195708-16907202247f
Repository: https://github.com/yext/sdk.git
Documentation: pkg.go.dev

# README

Grafana SDK Go Report Card

SDK for Go language offers a library for interacting with Grafana server from Go applications. It realizes many of HTTP REST API calls for administration, client, organizations. Beside of them it allows creating of Grafana objects (dashboards, panels, datasources) locally and manipulating them for constructing dashboards programmatically. It would be helpful for massive operations on a large set of dashboards for example.

It was made foremost for autograf project but later separated from it and moved to this new repository because the library is useful per se.

Grafana operates with Javascript objects on client side so on first view Go language looks alien thing here. And Grafana has GUI with detailed options for panel customization so in many cases you don't need additional automatization. But in situations when you operates on hundreds of dashboards programming generation of them become not bad idea. And SDK that allow you import/export, create, modify and validate Grafana structures is very helpful. Golang is good enough choice for operations with JSON though it may be subject of discuss. Positives of this choice is strong typization in Go that help validate objects alongside with high speed of execution and nice concurrency patterns. Negative aspect the same: the strong typization that add more verbosity to JSON parsing in comparing with Javascript or for an example with scripting languages like Python. But with SDK you already have ready for use structures and methods so generation of JSONs become simple. Anyway Grafana server made in Golang that prove concept for applicability of Go for that kind of tasks.

And of course if you write applications in Golang and integrate them with Grafana then client SDK for Go will be uniquely useful.

Library design principles

  1. SDK offers client functionality so it covers Grafana REST API with its requests and responses as close as possible.
  2. SDK maps Grafana objects (dashboard, row, panel, datasource) to similar Go structures but not follows exactly all Grafana abstractions.
  3. It doesn't use logging, instead API functions can return errors where it need.
  4. No external deps except Go stdlib. Another exception is URL slugify, SDK uses external lib "slug" for algorithm compatibility — that is the same package that Grafana server uses.

Examples GoDoc

	board := sdk.NewBoard("Sample dashboard title")
	board.ID = 1
	row1 := board.AddRow("Sample row title")
	row1.Add(sdk.NewGraph("Sample graph"))
	graph := sdk.NewGraph("Sample graph 2")
	target := sdk.Target{
		RefID:      "A",
		Datasource: "Sample Source 1",
		Expr:       "sample request 1"}
	graph.AddTarget(&target)
	row1.Add(graph)
	c := sdk.NewClient("http://grafana.host", "grafana-api-key", sdk.DefaultHTTPClient)	
	if err = c.SetDashboard(board, false); err != nil {
		fmt.Printf("error on uploading dashboard %s", board.Title)
	}

The library includes several demo apps for showing API usage:

You need Grafana API key with admin rights for using these utilities.

Installation Build Status

Of course Go development environment should be set up first. Then:

go get github.com/grafana-tools/sdk

Dependency packages have included into distro. govendor utility used for vendoring. The single dependency now is:

go get github.com/gosimple/slug

The "slugify" for URLs is a simple task but this package used in Grafana server so it used in the SDK for the compatibility reasons.

Grafana server compability

Made mostly for Grafana 3.x, works with Grafana 4.x but need more tests. Full support for Grafana 4.x is on the way.

Status of REST API realization Coverage Status

Work on full API implementation still in progress. Currently implemented only create/update/delete operations for dashboards and datasources. State of support for misc API parts noted below.

APIStatus
Authorizationonly API tokens
Dashboardspartially
Datasources+
Organization (current)partially
Organizations-
Userspartially
User (actual)partially
Snapshots-
Frontend settings-
Admin-

Roadmap

  • [DONE] Realize data structures used in a default Grafana installation for data visualizing (dashboards, datasources, panels, variables, annotations).
  • [PROGRESS] Support all functions of Grafana REST API for manipulating dashboards and datasources.
  • Support functions of Grafana REST API for manipulating users and organizations.

Collection of Grafana tools in Golang

# Packages

No description provided by the author

# Functions

No description provided by the author
NewClient initializes client for interacting with an instance of Grafana server; apiKeyOrBasicAuth accepts either 'username:password' basic authentication credentials, or a Grafana API key.
NewCustom initializes panel with a singlestat panel.
NewDashlist initializes panel with a dashlist panel.
No description provided by the author
NewGraph initializes panel with a graph panel.
No description provided by the author
NewPluginlist initializes panel with a singlestat panel.
NewSinglestat initializes panel with a singlestat panel.
NewTable initializes panel with a table panel.
NewText initializes panel with a text panel.

# Constants

Each panel may be one of these types.
Each panel may be one of these types.
Each panel may be one of these types.
No description provided by the author
Each panel may be one of these types.
Each panel may be one of these types.
Each panel may be one of these types.
Constants for templating.
Constants for templating.
Constants for templating.
Each panel may be one of these types.

# Variables

DefaultHTTPClient initialized Grafana with appropriate conditions.

# Structs

No description provided by the author
for a graph panel.
No description provided by the author
BoardProperties keeps metadata of a dashboard.
No description provided by the author
No description provided by the author
Client uses Grafana REST API for interacting with Grafana server.
No description provided by the author
No description provided by the author
Datasource as described in the doc http://docs.grafana.org/reference/http_api/#get-all-datasources.
Datasource type as described in http://docs.grafana.org/reference/http_api/#available-data-source-types.
FloatString represents special type for json values that could be strings or ints: 100 or "100".
FoundBoard keeps result of search with metadata of a dashboard.
No description provided by the author
IntString represents special type for json values that could be strings or ints: 100 or "100".
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Row represents single row of Grafana dashboard.
No description provided by the author
for a graph panel.
No description provided by the author
StatusMessage reflects status message as it returned by Grafana REST API.
No description provided by the author
for an any panel.
No description provided by the author
No description provided by the author
No description provided by the author
for a graph panel.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author
Height of rows maybe passed as number (ex 200) or as string (ex "200px") or empty string.