gapi

package module
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 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 AlertNotification

type AlertNotification struct {
	Id                    int64       `json:"id,omitempty"`
	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"`
}

type Client

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

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

func (*Client) AddTeam added in v0.3.2

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 added in v0.3.2

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

func (*Client) AlertNotification

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

func (*Client) AlertNotifications added in v0.3.2

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

func (*Client) CreateUser

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

func (*Client) Dashboard deprecated

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

Deprecated: Starting from Grafana v5.0. Please update to use DashboardByUID instead.

func (*Client) DashboardByUID added in v0.3.2

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

func (*Client) DataSource

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

func (*Client) DeleteAlertNotification

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

func (*Client) DeleteDashboard deprecated

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

Deprecated: Starting from Grafana v5.0. Please update to use DeleteDashboardByUID instead.

func (*Client) DeleteDashboardByUID added in v0.3.2

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

func (*Client) DeleteDataSource

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

func (*Client) DeleteFolder

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

func (*Client) DeleteOrg

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

func (*Client) DeleteTeam added in v0.3.2

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

func (*Client) DeleteUser

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

func (*Client) Folder

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

func (*Client) FolderPermissions added in v0.3.2

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

func (*Client) Folders

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

func (*Client) NewAlertNotification

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

func (*Client) NewDashboard

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

func (*Client) NewDataSource

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

func (*Client) NewFolder

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

func (*Client) NewOrg

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

func (*Client) Org

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

func (*Client) OrgByName

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

func (*Client) OrgUsers

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

func (*Client) Orgs

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

func (*Client) RemoveMemberFromTeam added in v0.3.2

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

func (*Client) RemoveOrgUser

func (c *Client) RemoveOrgUser(orgId, userId int64) error

func (*Client) SaveDashboard deprecated

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

Deprecated: use NewDashboard instead

func (*Client) SearchTeam added in v0.3.2

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

func (*Client) Team added in v0.3.2

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

func (*Client) TeamMembers added in v0.3.2

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

func (*Client) TeamPreferences added in v0.3.2

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

func (*Client) UpdateAlertNotification

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

func (*Client) UpdateDataSource

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

func (*Client) UpdateFolder

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

func (*Client) UpdateFolderPermissions added in v0.3.2

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

func (*Client) UpdateOrgUser

func (c *Client) UpdateOrgUser(orgId, userId int64, role string) error

func (*Client) UpdateTeam added in v0.3.2

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

func (*Client) UpdateTeamPreferences added in v0.3.2

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

func (*Client) UserByEmail

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

func (*Client) Users

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

type Dashboard

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

type DashboardMeta

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

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"`
}

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 in favor of secureJsonData.password
	Password string `json:"password,omitempty"`

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

	BasicAuth     bool   `json:"basicAuth"`
	BasicAuthUser string `json:"basicAuthUser,omitempty"`
	// Deprecated in favor of secureJsonData.basicAuthPassword
	BasicAuthPassword string `json:"basicAuthPassword,omitempty"`

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

type Folder

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

type FolderPermission added in v0.3.2

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 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"`
}

JSONData is a representation of the datasource `jsonData` property

type Org

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

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"`
}

type PermissionItem added in v0.3.2

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"`
}

type PermissionItems added in v0.3.2

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

type Preferences added in v0.3.2

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

type SearchTeam added in v0.3.2

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

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"`
}

SecureJSONData is a representation of the datasource `secureJsonData` property

type Team added in v0.3.2

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 added in v0.3.2

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

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"`
}

Jump to

Keyboard shortcuts

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