gapi

package module
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

README

grafana-api-golang-client

Build Status

Grafana HTTP API Client for Go

Tests

To run the tests:

go test

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	ID             int64  `json:"id,omitempty"`
	DashboardID    int64  `json:"dashboardId,omitempty"`
	DashboardUID   string `json:"dashboardUid,omitempty"`
	DashboardSlug  string `json:"dashboardSlug,omitempty"`
	PanelID        int64  `json:"panelId,omitempty"`
	Name           string `json:"name,omitempty"`
	State          string `json:"state,omitempty"`
	NewStateDate   string `json:"newStateDate,omitempty"`
	EvalDate       string `json:"evalDate,omitempty"`
	ExecutionError string `json:"executionError,omitempty"`
	URL            string `json:"url,omitempty"`
}

Alert represents a Grafana API Alert

type AlertNotification

type AlertNotification struct {
	Id                    int64       `json:"id,omitempty"`
	Uid                   string      `json:"uid"`
	Name                  string      `json:"name"`
	Type                  string      `json:"type"`
	IsDefault             bool        `json:"isDefault"`
	DisableResolveMessage bool        `json:"disableResolveMessage"`
	SendReminder          bool        `json:"sendReminder"`
	Frequency             string      `json:"frequency"`
	Settings              interface{} `json:"settings"`
}

AlertNotification represents a Grafana alert notification.

type Annotation

type Annotation struct {
	ID          int64    `json:"id,omitempty"`
	AlertID     int64    `json:"alertId,omitempty"`
	DashboardID int64    `json:"dashboardId"`
	PanelID     int64    `json:"panelId"`
	UserID      int64    `json:"userId,omitempty"`
	UserName    string   `json:"userName,omitempty"`
	NewState    string   `json:"newState,omitempty"`
	PrevState   string   `json:"prevState,omitempty"`
	Time        int64    `json:"time"`
	TimeEnd     int64    `json:"timeEnd,omitempty"`
	Text        string   `json:"text"`
	Metric      string   `json:"metric,omitempty"`
	RegionID    int64    `json:"regionId,omitempty"`
	Type        string   `json:"type,omitempty"`
	Tags        []string `json:"tags,omitempty"`
	IsRegion    bool     `json:"isRegion,omitempty"`
}

Annotation represents a Grafana API Annotation

type Client

type Client struct {
	*http.Client
	// contains filtered or unexported fields
}

Client is a Grafana API client.

func New

func New(auth, baseURL string) (*Client, error)

New creates a new grafana client auth can be in user:pass format, or it can be an api key

func (*Client) AddOrgUser

func (c *Client) AddOrgUser(orgID int64, user, role string) error

AddOrgUser adds a user to an org with the specified role.

func (*Client) AddTeam

func (c *Client) AddTeam(name string, email string) (int64, error)

AddTeam makes a new team email arg is an optional value. If you don't want to set email, please set "" (empty string).

func (*Client) AddTeamMember

func (c *Client) AddTeamMember(id int64, userID int64) error

AddTeamMember adds a user to the Grafana team whose ID it's passed.

func (*Client) Alert

func (c *Client) Alert(id int64) (Alert, error)

Alert fetches and returns an individual Grafana alert.

func (*Client) AlertNotification

func (c *Client) AlertNotification(id int64) (*AlertNotification, error)

AlertNotification fetches and returns a Grafana alert notification.

func (*Client) AlertNotifications

func (c *Client) AlertNotifications() ([]AlertNotification, error)

AlertNotifications fetches and returns Grafana alert notifications.

func (*Client) Alerts

func (c *Client) Alerts(params url.Values) ([]Alert, error)

Alerts fetches the annotations queried with the params it's passed.

func (*Client) Annotations

func (c *Client) Annotations(params url.Values) ([]Annotation, error)

Annotations fetches the annotations queried with the params it's passed

func (*Client) CreateUser

func (c *Client) CreateUser(user User) (int64, error)

CreateUser creates a Grafana user.

func (*Client) Dashboard

func (c *Client) Dashboard(slug string) (*Dashboard, error)

Dashboard will be removed. Deprecated: Starting from Grafana v5.0. Use DashboardByUid instead.

func (*Client) DashboardByUID

func (c *Client) DashboardByUID(uid string) (*Dashboard, error)

DashboardByUID will be removed. Deprecated: Interface typo. Use DashboardByUid instead.

func (*Client) DashboardByUid

func (c *Client) DashboardByUid(uid string) (*Dashboard, error)

DashboardByUid fetches and returns the dashboard whose UID is passed.

func (*Client) Dashboards

func (c *Client) Dashboards() ([]DashboardSearchResponse, error)

Dashboards fetches and returns Grafana dashboards.

func (*Client) DataSource

func (c *Client) DataSource(id int64) (*DataSource, error)

DataSource fetches and returns the Grafana data source whose ID it's passed.

func (*Client) DeleteAlertNotification

func (c *Client) DeleteAlertNotification(id int64) error

DeleteAlertNotification deletes a Grafana alert notification.

func (*Client) DeleteAnnotation

func (c *Client) DeleteAnnotation(id int64) (string, error)

DeleteAnnotation deletes the annotation of the ID it is passed

func (*Client) DeleteAnnotationByRegionID

func (c *Client) DeleteAnnotationByRegionID(id int64) (string, error)

DeleteAnnotationByRegionID deletes the annotation corresponding to the region ID it is passed

func (*Client) DeleteDashboard

func (c *Client) DeleteDashboard(slug string) error

DeleteDashboard will be removed. Deprecated: Starting from Grafana v5.0. Use DeleteDashboardByUid instead.

func (*Client) DeleteDashboardByUID

func (c *Client) DeleteDashboardByUID(uid string) error

DeleteDashboardByUID will be removed. Deprecated: Interface typo. Use DeleteDashboardByUid instead.

func (*Client) DeleteDashboardByUid

func (c *Client) DeleteDashboardByUid(uid string) error

DeleteDashboardByUid deletes the dashboard whose UID it's passed.

func (*Client) DeleteDataSource

func (c *Client) DeleteDataSource(id int64) error

DeleteDataSource deletes the Grafana data source whose ID it's passed.

func (*Client) DeleteFolder

func (c *Client) DeleteFolder(id string) error

DeleteFolder deletes the folder whose ID it's passed.

func (*Client) DeleteOrg

func (c *Client) DeleteOrg(id int64) error

DeleteOrg deletes the Grafana org whose ID it's passed.

func (*Client) DeletePlaylist

func (c *Client) DeletePlaylist(id int) error

DeletePlaylist deletes the Grafana playlist whose ID it's passed.

func (*Client) DeleteTeam

func (c *Client) DeleteTeam(id int64) error

DeleteTeam deletes the Grafana team whose ID it's passed.

func (*Client) DeleteUser

func (c *Client) DeleteUser(id int64) error

DeleteUser deletes a Grafana user.

func (*Client) Folder

func (c *Client) Folder(id int64) (*Folder, error)

Folder fetches and returns the Grafana folder whose ID it's passed.

func (*Client) FolderPermissions

func (c *Client) FolderPermissions(fid string) ([]*FolderPermission, error)

FolderPermissions fetches and returns the permissions for the folder whose ID it's passed.

func (*Client) Folders

func (c *Client) Folders() ([]Folder, error)

Folders fetches and returns Grafana folders.

func (*Client) NewAlertNotification

func (c *Client) NewAlertNotification(a *AlertNotification) (int64, error)

NewAlertNotification creates a new Grafana alert notification.

func (*Client) NewAnnotation

func (c *Client) NewAnnotation(a *Annotation) (int64, error)

NewAnnotation creates a new annotation with the Annotation it is passed

func (*Client) NewDashboard

func (c *Client) NewDashboard(dashboard Dashboard) (*DashboardSaveResponse, error)

NewDashboard creates a new Grafana dashboard.

func (*Client) NewDataSource

func (c *Client) NewDataSource(s *DataSource) (int64, error)

NewDataSource creates a new Grafana data source.

func (*Client) NewFolder

func (c *Client) NewFolder(title string) (Folder, error)

NewFolder creates a new Grafana folder.

func (*Client) NewGraphiteAnnotation

func (c *Client) NewGraphiteAnnotation(gfa *GraphiteAnnotation) (int64, error)

NewGraphiteAnnotation creates a new annotation with the GraphiteAnnotation it is passed

func (*Client) NewOrg

func (c *Client) NewOrg(name string) (int64, error)

NewOrg creates a new Grafana org.

func (*Client) NewPlaylist

func (c *Client) NewPlaylist(playlist Playlist) (int, error)

NewPlaylist creates a new Grafana playlist.

func (*Client) Org

func (c *Client) Org(id int64) (Org, error)

Org fetches and returns the org whose ID it's passed.

func (*Client) OrgByName

func (c *Client) OrgByName(name string) (Org, error)

OrgByName fetches and returns the org whose name it's passed.

func (*Client) OrgUsers

func (c *Client) OrgUsers(orgID int64) ([]OrgUser, error)

OrgUsers fetches and returns the users for the org whose ID it's passed.

func (*Client) Orgs

func (c *Client) Orgs() ([]Org, error)

Orgs fetches and returns the Grafana orgs.

func (*Client) PatchAnnotation

func (c *Client) PatchAnnotation(id int64, a *Annotation) (string, error)

PatchAnnotation updates one or more properties of an existing annotation that matches the specified ID.

func (*Client) PauseAlert

func (c *Client) PauseAlert(id int64) (PauseAlertResponse, error)

PauseAlert pauses the Grafana alert whose ID it's passed.

func (*Client) PauseAllAlerts

func (c *Client) PauseAllAlerts() (PauseAllAlertsResponse, error)

PauseAllAlerts pauses all Grafana alerts.

func (*Client) Playlist

func (c *Client) Playlist(id int) (*Playlist, error)

Playlist fetches and returns a Grafana playlist.

func (*Client) RemoveMemberFromTeam

func (c *Client) RemoveMemberFromTeam(id int64, userID int64) error

RemoveMemberFromTeam removes a user from the Grafana team whose ID it's passed.

func (*Client) RemoveOrgUser

func (c *Client) RemoveOrgUser(orgID, userID int64) error

RemoveOrgUser removes a user from an org.

func (*Client) SaveDashboard

func (c *Client) SaveDashboard(model map[string]interface{}, overwrite bool) (*DashboardSaveResponse, error)

SaveDashboard is a deprecated method for saving a Grafana dashboard. Use NewDashboard. Deprecated: Use NewDashboard instead.

func (*Client) SearchTeam

func (c *Client) SearchTeam(query string) (*SearchTeam, error)

SearchTeam searches Grafana teams and returns the results.

func (*Client) Team

func (c *Client) Team(id int64) (*Team, error)

Team fetches and returns the Grafana team whose ID it's passed.

func (*Client) TeamMembers

func (c *Client) TeamMembers(id int64) ([]*TeamMember, error)

TeamMembers fetches and returns the team members for the Grafana team whose ID it's passed.

func (*Client) TeamPreferences

func (c *Client) TeamPreferences(id int64) (*Preferences, error)

TeamPreferences fetches and returns preferences for the Grafana team whose ID it's passed.

func (*Client) UpdateAlertNotification

func (c *Client) UpdateAlertNotification(a *AlertNotification) error

UpdateAlertNotification updates a Grafana alert notification.

func (*Client) UpdateAnnotation

func (c *Client) UpdateAnnotation(id int64, a *Annotation) (string, error)

UpdateAnnotation updates all properties an existing annotation with the Annotation it is passed.

func (*Client) UpdateDataSource

func (c *Client) UpdateDataSource(s *DataSource) error

UpdateDataSource updates a Grafana data source.

func (*Client) UpdateFolder

func (c *Client) UpdateFolder(id string, name string) error

UpdateFolder updates the folder whose ID it's passed.

func (*Client) UpdateFolderPermissions

func (c *Client) UpdateFolderPermissions(fid string, items *PermissionItems) error

UpdateFolderPermissions remove existing permissions if items are not included in the request.

func (*Client) UpdateOrg

func (c *Client) UpdateOrg(id int64, name string) error

UpdateOrg updates a Grafana org.

func (*Client) UpdateOrgUser

func (c *Client) UpdateOrgUser(orgID, userID int64, role string) error

UpdateOrgUser updates and org user.

func (*Client) UpdatePlaylist

func (c *Client) UpdatePlaylist(playlist Playlist) error

UpdatePlaylist updates a Grafana playlist.

func (*Client) UpdateTeam

func (c *Client) UpdateTeam(id int64, name string, email string) error

UpdateTeam updates a Grafana team.

func (*Client) UpdateTeamPreferences

func (c *Client) UpdateTeamPreferences(id int64, theme string, homeDashboardID int64, timezone string) error

UpdateTeamPreferences updates team preferences for the Grafana team whose ID it's passed.

func (*Client) UserByEmail

func (c *Client) UserByEmail(email string) (User, error)

UserByEmail fetches and returns the user whose email matches that passed.

func (*Client) Users

func (c *Client) Users() ([]User, error)

Users fetches and returns Grafana users.

type Dashboard

type Dashboard struct {
	Meta      DashboardMeta          `json:"meta"`
	Model     map[string]interface{} `json:"dashboard"`
	Folder    int64                  `json:"folderId"`
	Overwrite bool                   `json:"overwrite"`
}

Dashboard represents a Grafana dashboard.

type DashboardMeta

type DashboardMeta struct {
	IsStarred bool   `json:"isStarred"`
	Slug      string `json:"slug"`
	Folder    int64  `json:"folderId"`
}

DashboardMeta represents Grafana dashboard meta.

type DashboardSaveResponse

type DashboardSaveResponse struct {
	Slug    string `json:"slug"`
	Id      int64  `json:"id"`
	Uid     string `json:"uid"`
	Status  string `json:"status"`
	Version int64  `json:"version"`
}

DashboardSaveResponse represents the Grafana API response to creating or saving a dashboard.

type DashboardSearchResponse

type DashboardSearchResponse struct {
	Id          uint     `json:"id"`
	Uid         string   `json:"uid"`
	Title       string   `json:"title"`
	Uri         string   `json:"uri"`
	Url         string   `json:"url"`
	Slug        string   `json:"slug"`
	Type        string   `json:"type"`
	Tags        []string `json:"tags"`
	IsStarred   bool     `json:"isStarred"`
	FolderId    uint     `json:"folderId"`
	FolderUid   string   `json:"folderUid"`
	FolderTitle string   `json:"folderTitle"`
	FolderUrl   string   `json:"folderUrl"`
}

DashboardSearchResponse represents the Grafana API dashboard search response.

type DataSource

type DataSource struct {
	Id     int64  `json:"id,omitempty"`
	Name   string `json:"name"`
	Type   string `json:"type"`
	URL    string `json:"url"`
	Access string `json:"access"`

	Database string `json:"database,omitempty"`
	User     string `json:"user,omitempty"`
	// Deprecated: Use secureJsonData.password instead.
	Password string `json:"password,omitempty"`

	OrgId     int64 `json:"orgId,omitempty"`
	IsDefault bool  `json:"isDefault"`

	BasicAuth     bool   `json:"basicAuth"`
	BasicAuthUser string `json:"basicAuthUser,omitempty"`
	// Deprecated: Use secureJsonData.basicAuthPassword instead.
	BasicAuthPassword string `json:"basicAuthPassword,omitempty"`

	JSONData       JSONData       `json:"jsonData,omitempty"`
	SecureJSONData SecureJSONData `json:"secureJsonData,omitempty"`
}

DataSource represents a Grafana data source.

type Folder

type Folder struct {
	Id    int64  `json:"id"`
	Uid   string `json:"uid"`
	Title string `json:"title"`
}

Folder represents a Grafana folder.

type FolderPermission

type FolderPermission struct {
	Id        int64  `json:"id"`
	FolderUid string `json:"uid"`
	UserId    int64  `json:"userId"`
	TeamId    int64  `json:"teamId"`
	Role      string `json:"role"`
	IsFolder  bool   `json:"isFolder"`

	// Permission levels are
	// 1 = View
	// 2 = Edit
	// 4 = Admin
	Permission     int64  `json:"permission"`
	PermissionName string `json:"permissionName"`

	// optional fields
	FolderId    int64 `json:"folderId,omitempty"`
	DashboardId int64 `json:"dashboardId,omitempty"`
}

FolderPermission has information such as a folder, user, team, role and permission.

type GraphiteAnnotation

type GraphiteAnnotation struct {
	What string   `json:"what"`
	When int64    `json:"when"`
	Data string   `json:"data"`
	Tags []string `json:"tags,omitempty"`
}

GraphiteAnnotation represents a Grafana API annotation in Graphite format

type JSONData

type JSONData struct {
	// Used by all datasources
	TlsAuth           bool `json:"tlsAuth,omitempty"`
	TlsAuthWithCACert bool `json:"tlsAuthWithCACert,omitempty"`
	TlsSkipVerify     bool `json:"tlsSkipVerify,omitempty"`

	// Used by Graphite
	GraphiteVersion string `json:"graphiteVersion,omitempty"`

	// Used by Prometheus, Elasticsearch, InfluxDB, MySQL, PostgreSQL and MSSQL
	TimeInterval string `json:"timeInterval,omitempty"`

	// Used by Elasticsearch
	EsVersion       int64  `json:"esVersion,omitempty"`
	TimeField       string `json:"timeField,omitempty"`
	Interval        string `json:"inteval,omitempty"`
	LogMessageField string `json:"logMessageField,omitempty"`
	LogLevelField   string `json:"logLevelField,omitempty"`

	// Used by Cloudwatch
	AuthType                string `json:"authType,omitempty"`
	AssumeRoleArn           string `json:"assumeRoleArn,omitempty"`
	DefaultRegion           string `json:"defaultRegion,omitempty"`
	CustomMetricsNamespaces string `json:"customMetricsNamespaces,omitempty"`

	// Used by OpenTSDB
	TsdbVersion    string `json:"tsdbVersion,omitempty"`
	TsdbResolution string `json:"tsdbResolution,omitempty"`

	// Used by MSSQL
	Encrypt string `json:"encrypt,omitempty"`

	// Used by PostgreSQL
	Sslmode         string `json:"sslmode,omitempty"`
	PostgresVersion int64  `json:"postgresVersion,omitempty"`
	Timescaledb     bool   `json:"timescaledb,omitempty"`

	// Used by MySQL, PostgreSQL and MSSQL
	MaxOpenConns    int64 `json:"maxOpenConns,omitempty"`
	MaxIdleConns    int64 `json:"maxIdleConns,omitempty"`
	ConnMaxLifetime int64 `json:"connMaxLifetime,omitempty"`

	// Used by Prometheus
	HttpMethod   string `json:"httpMethod,omitempty"`
	QueryTimeout string `json:"queryTimeout,omitempty"`

	// Used by Stackdriver
	AuthenticationType string `json:"authenticationType,omitempty"`
	ClientEmail        string `json:"clientEmail,omitempty"`
	DefaultProject     string `json:"defaultProject,omitempty"`
	TokenUri           string `json:"tokenUri,omitempty"`
}

JSONData is a representation of the datasource `jsonData` property

type Org

type Org struct {
	Id   int64  `json:"id"`
	Name string `json:"name"`
}

Org represents a Grafana org.

type OrgUser

type OrgUser struct {
	OrgId  int64  `json:"orgId"`
	UserId int64  `json:"userId"`
	Email  string `json:"email"`
	Login  string `json:"login"`
	Role   string `json:"role"`
}

OrgUser represents a Grafana org user.

type PauseAlertRequest

type PauseAlertRequest struct {
	Paused bool `json:"paused"`
}

PauseAlertRequest represents the request payload for a PauseAlert request.

type PauseAlertResponse

type PauseAlertResponse struct {
	AlertID int64  `json:"alertId,omitempty"`
	State   string `json:"state,omitempty"`
	Message string `json:"message,omitempty"`
}

PauseAlertResponse represents the response body for a PauseAlert request.

type PauseAllAlertsResponse

type PauseAllAlertsResponse struct {
	AlertsAffected int64  `json:"alertsAffected,omitempty"`
	State          string `json:"state,omitempty"`
	Message        string `json:"message,omitempty"`
}

PauseAllAlertsResponse represents the response body for a PauseAllAlerts request.

type PermissionItem

type PermissionItem struct {
	// As you can see the docs, each item has a pair of [Role|TeamId|UserId] and Permission.
	// unnecessary fields are omitted.
	Role       string `json:"role,omitempty"`
	TeamId     int64  `json:"teamId,omitempty"`
	UserId     int64  `json:"userId,omitempty"`
	Permission int64  `json:"permission"`
}

PermissionItem represents a Grafana folder permission item.

type PermissionItems

type PermissionItems struct {
	Items []*PermissionItem `json:"items"`
}

PermissionItems represents Grafana folder permission items.

type Playlist

type Playlist struct {
	Id       int            `json:"id"`
	Name     string         `json:"name"`
	Interval string         `json:"interval"`
	Items    []PlaylistItem `json:"items"`
}

Playlist represents a Grafana playlist.

type PlaylistItem

type PlaylistItem struct {
	Type  string `json:"type"`
	Value string `json:"value"`
	Order int    `json:"order"`
	Title string `json:"title"`
}

PlaylistItem represents a Grafana playlist item.

type Preferences

type Preferences struct {
	Theme           string `json:"theme"`
	HomeDashboardId int64  `json:"homeDashboardId"`
	Timezone        string `json:"timezone"`
}

Preferences represents Grafana preferences.

type SearchTeam

type SearchTeam struct {
	TotalCount int64   `json:"totalCount,omitempty"`
	Teams      []*Team `json:"teams,omitempty"`
	Page       int64   `json:"page,omitempty"`
	PerPage    int64   `json:"perPage,omitempty"`
}

SearchTeam represents a search for a Grafana team.

type SecureJSONData

type SecureJSONData struct {
	// Used by all datasources
	TlsCACert         string `json:"tlsCACert,omitempty"`
	TlsClientCert     string `json:"tlsClientCert,omitempty"`
	TlsClientKey      string `json:"tlsClientKey,omitempty"`
	Password          string `json:"password,omitempty"`
	BasicAuthPassword string `json:"basicAuthPassword,omitempty"`

	// Used by Cloudwatch
	AccessKey string `json:"accessKey,omitempty"`
	SecretKey string `json:"secretKey,omitempty"`

	// Used by Stackdriver
	PrivateKey string `json:"privateKey,omitempty"`
}

SecureJSONData is a representation of the datasource `secureJsonData` property

type Team

type Team struct {
	Id          int64  `json:"id,omitempty"`
	OrgId       int64  `json:"orgId,omitempty"`
	Name        string `json:"name"`
	Email       string `json:"email,omitempty"`
	AvatarUrl   string `json:"avatarUrl,omitempty"`
	MemberCount int64  `json:"memberCount,omitempty"`
	Permission  int64  `json:"permission,omitempty"`
}

Team consists of a get response It's used in Add and Update API

type TeamMember

type TeamMember struct {
	OrgId      int64  `json:"orgId,omitempty"`
	TeamId     int64  `json:"teamId,omitempty"`
	UserId     int64  `json:"userId,omitempty"`
	Email      string `json:"email,omitempty"`
	Login      string `json:"login,omitempty"`
	AvatarUrl  string `json:"avatarUrl,omitempty"`
	Permission int64  `json:"permission,omitempty"`
}

TeamMember represents a Grafana team member.

type User

type User struct {
	Id       int64  `json:"id,omitempty"`
	Email    string `json:"email,omitempty"`
	Name     string `json:"name,omitempty"`
	Login    string `json:"login,omitempty"`
	Password string `json:"password,omitempty"`
	IsAdmin  bool   `json:"isAdmin,omitempty"`
}

User represents a Grafana user.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL