Categorygithub.com/grafana-tools/sdk
modulepackage
0.0.0-20220919052116-6562121319fc
Repository: https://github.com/grafana-tools/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 Grafana objects.

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.

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 any logger, instead API functions could return errors where it need.
  4. Prefere no external deps except Go stdlib.
  5. Cover SDK calls with unit tests.

Examples GoDoc

	board := sdk.NewBoard("Sample dashboard title")
	board.ID = 1
	board.Time.From = "now-30m"
	board.Time.To = "now"
	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)
	grafanaURL := "http://grafana.host"
	c := sdk.NewClient(grafanaURL, "grafana-api-key", sdk.DefaultHTTPClient)
	response, err := c.SetDashboard(context.TODO() ,*board, sdk.SetDashboardParams{
		Overwrite: false,
	})
	if err != nil {
		fmt.Printf("error on uploading dashboard %s", board.Title)
	} else {
		fmt.Printf("dashboard URL: %v", grafanaURL+*response.URL)
	}

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.

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
AuthorizationAPI tokens and Basic Auth
Annotationspartially
Dashboardspartially
Datasources+
Alert notification channels+
Organization (current)partially
Organizationspartially
Userspartially
User (actual)partially
Snapshotspartially
Frontend settings-
Adminpartially

There is no exact roadmap. The integration tests are being run against the following Grafana versions:

With the following Go versions:

  • 1.14.x
  • 1.13.x
  • 1.12.x
  • 1.11.x

I still have interest to this library development but not always have time for it. So I gladly accept new contributions. Drop an issue or contact me.

Licence

Distributed under Apache v2.0. All rights belong to the SDK authors. There is no authors list yet, you can see the full list of the contributors in the git history. Official repository is https://github.com/grafana-tools/sdk

Collection of Grafana tools in Golang

# Packages

No description provided by the author

# Functions

Limit sets the max number of folders to return.
No description provided by the author
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 stat 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
No description provided by the author
NewPluginlist initializes panel with a stat panel.
NewSinglestat initializes panel with a singlestat panel.
NewStat initializes panel with a stat panel.
NewTable initializes panel with a table panel.
NewText initializes panel with a text panel.
NewTimeseries initializes panel with a timeseries panel.
QueryParamLimit sets `limit` parameter.
QueryParamStart sets `start` parameter.
SearchDashboardID specifies Search dashboard id's to search for.
SearchFolderID specifies Search folder id's to search for.
SearchLimit specifies maximum number of results from Search query.
SearchPage specifies Search page number to be queried for.
SearchQuery specifies Search search query.
SearchStarred specifies if Search should search for starred dashboards only.
SearchTag specifies Search tag to search for.
SearchType specifies Search type to search for.
WithAlertType filters the type to alerts.
WithAnnotationType filters the type to annotations.
WithDashboard filters the response to the specified dashboard ID.
WithEndTime filters the annotations to before the specified time.
WithLimit sets the max number of alerts to return.
WithPage adds a page number query parameter.
WithPagesize adds a page size query parameter.
WithPanel filters the response to the specified panel ID.
WithQuery adds a query parameter.
WithStartTime filters the annotations to after the specified time.
WithTag adds the tag to the.
WithTeam adds a query parameter.
WithUser filters the annotations to only be made by the specified user ID.

# 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.
Each panel may be one of these types.
DefaultFolderId is the id of the general folder that is pre-created and cannot be removed.
Each panel may be one of these types.
Each panel may be one of these types.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Each panel may be one of these types.
Each panel may be one of these types.
Search entities to be used with SearchType().
Search entities to be used with SearchType().
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.
Each panel may be one of these types.

# Variables

DefaultHTTPClient initialized Grafana with appropriate conditions.
TeamNotFound is an error returned if the given team was not found.

# Structs

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
AlertNotification as described in the doc https://grafana.com/docs/grafana/latest/http_api/alerting_notification_channels/.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
AnnotationResponse is representation of an existing annotation.
for a graph panel.
No description provided by the author
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.
for a table.
for a table.
No description provided by the author
CreateAnnotationRequest is a request to create a new annotation.
CreateSnapshotRequest is representation of a snapshot request.
No description provided by the author
DashboardVersion represents a response from /api/dashboards/id/:dashboardId/versions API.
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.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
FloatString represents special type for json values that could be strings or ints: 100 or "100".
Folder as described in the doc https://grafana.com/docs/grafana/latest/http_api/folder/#get-all-folders.
No description provided by the author
FoundBoard keeps result of search with metadata of a dashboard.
for a stat.
No description provided by the author
HealthResponse represents the health of grafana server.
No description provided by the author
IntString represents special type for json values that could be strings or ints: 100 or "100".
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
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
PatchAnnotationRequest is a request to patch an existing annotation.
No description provided by the author
No description provided by the author
No description provided by the author
RawBoardRequest struct that wraps Board and parameters being sent.
Row represents single row of Grafana dashboard.
No description provided by the author
for a graph panel.
SetDashboardParams contains the extra parameters that affects where and how the dashboard will be stored.
No description provided by the author
for a graph panel.
for a stat.
StackdriverAlignOption defines a single alignment option shown in Grafana during query configuration.
StackdriverAlignOptions defines the list of alignment options shown in Grafana during query configuration.
No description provided by the author
StatusMessage reflects status message as it returned by Grafana REST API.
StringSliceString represents special type for json values that could be strings or slice of strings: "something" or ["something"].
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
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
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
No description provided by the author
for a stat.

# Type aliases

No description provided by the author
GetAnnotationsParams is the type for all options implementing query parameters https://grafana.com/docs/grafana/latest/http_api/annotations/#find-annotations.
GetFolderParams is the type for all options implementing query parameters.
Height of rows maybe passed as number (ex 200) or as string (ex "200px") or empty string.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
SearchTeamParams is the type for all options implementing query parameters perpage optional.