gapi

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

README

grafana-api-golang-client

Grafana HTTP API Client for Go

Tests

To run the tests:

go test

Documentation

Index

Constants

View Source
const (
	// GrafanaAPIPanelRender Base for the Grafana Render API
	GrafanaAPIPanelRender = "/render/d-solo"

	// GrafanaAPIPanelRenderWidth Default Panel Export Width
	GrafanaAPIPanelRenderWidth = 1000

	// GrafanaAPIPanelRenderHeight Default Panel Export Height
	GrafanaAPIPanelRenderHeight = 500
)

Variables

View Source
var MissingQueryParameterError error

MissingQueryParameterError the error Type for Missing Query Parameters

Functions

func TimeToGrafanaString

func TimeToGrafanaString(t time.Time) string

Types

type AlertNotification

type AlertNotification struct {
	Id        int64       `json:"id,omitempty"`
	Name      string      `json:"name"`
	Type      string      `json:"type"`
	IsDefault bool        `json:"isDefault"`
	Settings  interface{} `json:"settings"`
}

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
}

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) AlertNotification

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

func (*Client) Annotations

func (c *Client) Annotations(params map[string]string) ([]Annotation, error)

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

func (*Client) CreateUser

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

func (*Client) Dashboard deprecated

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

Deprecated: use GetDashboard instead

func (*Client) DataSource

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

func (*Client) DeleteAlertNotification

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

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(uid string) (string, error)

DeleteDashboard deletes a grafana dashoboard

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) DeletePlaylist

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

func (*Client) DeleteUser

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

func (*Client) ExportPanelAsImage

func (c *Client) ExportPanelAsImage(
	dashboardID string,
	orgID int64,
	panelID int64,
	timeRange TimeRange,
	exportSize GrafanaPanelExportSize,
	dashboardVars map[string][]string,
	timeZone string,
	output string) error

ExportPanelAsImage a Grafana Panel to the Local Filesystem Save the Panel as PNG

func (*Client) Folder

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

func (*Client) FolderByUID

func (c *Client) FolderByUID(uid string) (*Folder, error)

func (*Client) Folders

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

func (*Client) GetDashboard

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

GetDashboard get a dashboard by UID

func (*Client) NewAlertNotification

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

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)

func (*Client) NewDataSource

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

func (*Client) NewFolder

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

func (*Client) NewFolderWithUID

func (c *Client) NewFolderWithUID(title, uid string) (Folder, error)

NewFolderWithUID allows to create a new folder by specifying a custom UID. It is duplicated in order to maintain compatibility with existent tools

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)

func (*Client) NewPlaylist

func (c *Client) NewPlaylist(s *Playlist) (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) Playlist

func (c *Client) Playlist(id int64) (*Playlist, 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) SearchDashboard

func (c *Client) SearchDashboard(query string, folderID string) ([]Dashboards, error)

SearchDashboard search a dashboard in Grafana

func (*Client) SearchFolder

func (c *Client) SearchFolder(query string) ([]Folder, error)

SearchFolder search a folder in Grafana

func (*Client) UpdateAlertNotification

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

func (*Client) UpdateAnnotation

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

UpdateAnnotation updates an existing annotation with the Annotation it is passed

func (*Client) UpdateDataSource

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

func (*Client) UpdateFolder

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

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) UpdatePlaylist

func (c *Client) UpdatePlaylist(s *Playlist) 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     DashboardModel `json:"dashboard"`
	Folder    int64          `json:"folderId"`
	Overwrite bool           `json:"overwrite"`
}

func (Dashboard) FrontendURL

func (d Dashboard) FrontendURL(dashboardVars map[string][]string) string

func (Dashboard) GetPanelFromDashboard

func (d Dashboard) GetPanelFromDashboard(panelID int64) (DashboardPanel, error)

GetPanelFromDashboard Returns the Panel from a dashboard by given PanelID

type DashboardAnnotation

type DashboardAnnotation struct {
	BuiltIn    int    `json:"builtIn"`
	Datasource string `json:"datasource"`
	Enable     bool   `json:"enable"`
	Hide       bool   `json:"hide"`
	IconColor  string `json:"iconColor"`
	Name       string `json:"name"`
	Type       string `json:"type"`
}

type DashboardDeleteResponse

type DashboardDeleteResponse struct {
	Title string `json:title`
}

DashboardDeleteResponse grafana response for delete dashboard

type DashboardMeta

type DashboardMeta struct {
	UID         string `json:"uid"`
	Title       string `json:"title"`
	IsStarred   bool   `json:"isStarred"`
	Slug        string `json:"slug"`
	Folder      int64  `json:"folderId"`
	FolderTitle string `json:"folderTitle"`
}

type DashboardModel

type DashboardModel struct {
	Annotations struct {
		List []DashboardAnnotation `json:"list"`
	} `json:"annotations"`
	Editable      bool             `json:"editable"`
	GnetID        interface{}      `json:"gnetId"`
	GraphTooltip  int              `json:"graphTooltip"`
	ID            int              `json:"id"`
	Iteration     int64            `json:"iteration"`
	Links         []Link           `json:"links"`
	Panels        []DashboardPanel `json:"panels"`
	Refresh       bool             `json:"refresh"`
	SchemaVersion int              `json:"schemaVersion"`
	Style         string           `json:"style"`
	Tags          []interface{}    `json:"tags"`
	Templating    struct {
		List []struct {
			AllValue interface{} `json:"allValue"`
			Current  struct {
				Text  string `json:"text"`
				Value string `json:"value"`
			} `json:"current"`
			Hide       int         `json:"hide"`
			IncludeAll bool        `json:"includeAll"`
			Label      interface{} `json:"label"`
			Multi      bool        `json:"multi"`
			Name       string      `json:"name"`
			Options    []struct {
				Selected bool   `json:"selected"`
				Text     string `json:"text"`
				Value    string `json:"value"`
			} `json:"options"`
			Query       string `json:"query"`
			SkipURLSync bool   `json:"skipUrlSync"`
			Type        string `json:"type"`
		} `json:"list"`
	} `json:"templating"`
	Time       TimeRange `json:"time"`
	Timepicker struct {
		RefreshIntervals []string `json:"refresh_intervals"`
	} `json:"timepicker"`
	Timezone string `json:"timezone"`
	Title    string `json:"title"`
	UID      string `json:"uid"`
	Version  int    `json:"version"`
}

type DashboardPanel

type DashboardPanel struct {
	Bars         bool   `json:"bars"`
	DashLength   int    `json:"dashLength"`
	Dashes       bool   `json:"dashes"`
	Description  string `json:"description"`
	Fill         int    `json:"fill"`
	FillGradient int    `json:"fillGradient"`
	GridPos      struct {
		H int `json:"h"`
		W int `json:"w"`
		X int `json:"x"`
		Y int `json:"y"`
	} `json:"gridPos"`
	ID     int64 `json:"id"`
	Legend struct {
		Avg     bool `json:"avg"`
		Current bool `json:"current"`
		Max     bool `json:"max"`
		Min     bool `json:"min"`
		Show    bool `json:"show"`
		Total   bool `json:"total"`
		Values  bool `json:"values"`
	} `json:"legend"`
	Lines         bool   `json:"lines"`
	Linewidth     int    `json:"linewidth"`
	Links         []Link `json:"links"`
	NullPointMode string `json:"nullPointMode"`
	Options       struct {
		DataLinks []interface{} `json:"dataLinks"`
	} `json:"options"`
	Percentage      bool          `json:"percentage"`
	Pointradius     int           `json:"pointradius"`
	Points          bool          `json:"points"`
	Renderer        string        `json:"renderer"`
	SeriesOverrides []interface{} `json:"seriesOverrides"`
	SpaceLength     int           `json:"spaceLength"`
	Stack           bool          `json:"stack"`
	SteppedLine     bool          `json:"steppedLine"`
	Thresholds      []interface{} `json:"thresholds"`
	TimeFrom        interface{}   `json:"timeFrom"`
	TimeRegions     []interface{} `json:"timeRegions"`
	TimeShift       interface{}   `json:"timeShift"`
	Title           string        `json:"title"`
	Tooltip         struct {
		Shared    bool   `json:"shared"`
		Sort      int    `json:"sort"`
		ValueType string `json:"value_type"`
	} `json:"tooltip"`
	Type  string `json:"type"`
	Xaxis struct {
		Buckets interface{}   `json:"buckets"`
		Mode    string        `json:"mode"`
		Name    interface{}   `json:"name"`
		Show    bool          `json:"show"`
		Values  []interface{} `json:"values"`
	} `json:"xaxis"`
	Yaxes []struct {
		Format  string      `json:"format"`
		Label   interface{} `json:"label"`
		LogBase int         `json:"logBase"`
		Max     interface{} `json:"max"`
		Min     interface{} `json:"min"`
		Show    bool        `json:"show"`
	} `json:"yaxes"`
	Yaxis struct {
		Align      bool        `json:"align"`
		AlignLevel interface{} `json:"alignLevel"`
	} `json:"yaxis"`
}

func (DashboardPanel) AsPartOfUrl

func (p DashboardPanel) AsPartOfUrl() string

type DashboardSaveResponse

type DashboardSaveResponse struct {
	Slug    string `json:"slug"`
	ID      int64  `json:"id"`
	UID     string `json:"uid"`
	URL     string `json:"url"`
	Status  string `json:"status"`
	Version int64  `json:"version"`
}

DashboardSaveResponse grafana response for create dashboard

type Dashboards

type Dashboards struct {
	ID          int64  `json:"id"`
	UID         string `json:"uid"`
	Title       string `json:"title"`
	URI         string `json:"uri"`
	URL         string `json:"url"`
	Starred     bool   `json:"isStarred"`
	FolderID    int64  `json:"folderId"`
	FolderUID   string `json:"folderUid"`
	FolderTitle string `json:"folderTitle"`
}

Dashboards represent json returned by search API

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"`
	Password string `json:"password,omitempty"`

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

	BasicAuth         bool   `json:"basicAuth"`
	BasicAuthUser     string `json:"basicAuthUser,omitempty"`
	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 GrafanaPanelExportSize

type GrafanaPanelExportSize struct {
	Width  int
	Height int
}

func (GrafanaPanelExportSize) AsPartOfUrl

func (size GrafanaPanelExportSize) AsPartOfUrl() (string, error)

func (*GrafanaPanelExportSize) New

func (size *GrafanaPanelExportSize) New(width int, height int)

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 {
	// CloudWatch specific
	AssumeRoleArn           string `json:"assumeRoleArn,omitempty"`
	AuthType                string `json:"authType,omitempty"`
	CustomMetricsNamespaces string `json:"customMetricsNamespaces,omitempty"`
	DefaultRegion           string `json:"defaultRegion,omitempty"`

	// Graphite specific
	GraphiteVersion string `json:"graphiteVersion,omitempty"`

	// Elasticsearch specific
	EsVersion                  int64  `json:"esVersion,omitempty"`
	Interval                   string `json:"interval,omitempty"`
	MaxConcurrentShardRequests int64  `json:"maxConcurrentShardRequests,omitempty"`
	TimeField                  string `json:"timeField,omitempty"`

	// OpenTSDB specific
	TSDBResolution int64 `json:"tsdbResolution,omitempty"`
	TSDBVersion    int64 `json:"tsdbVersion,omitempty"`

	// PostgreSQL specific
	SSLMode string `json:"sslmode,omitempty"`

	// Prometheus specific
	QueryTimeout string `json:"queryTimeout,omitempty"`

	// General
	KeepCookies    []string `json:"keepCookies,omitempty"`
	ScrapeInterval string   `json:"timeInterval,omitempty"`
}

JSONData is a representation of the datasource `jsonData` property

type Link struct {
	Title string `json:"title"`
	URL   string `json:"url"`
}

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 Playlist

type Playlist struct {
	Id       int64          `json:"id,omitempty"`
	Name     string         `json:"name"`
	Interval string         `json:"interval"`
	URL      string         `json:"url"`
	Items    []PlaylistItem `json:"items"`
}

type PlaylistItem

type PlaylistItem struct {
	Id    int64  `json:"id,omitempty"`
	Type  string `json:"type"`
	Order int    `json:"order"`
	Title string `json:"title"`
	Value string `json:"value"`
}

type SecureJSONData

type SecureJSONData struct {
	// CloudWatch specific
	AccessKey string `json:"accessKey,omitempty"`
	SecretKey string `json:"secretKey,omitempty"`

	// General
	Password string `json:"password,omitempty"`
}

SecureJSONData is a representation of the datasource `secureJsonData` property

type TimeRange

type TimeRange struct {
	From string `json:"from"`
	To   string `json:"to"`
}

func (TimeRange) AsPartOfUrl

func (t TimeRange) AsPartOfUrl() (string, error)

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