Documentation ¶
Index ¶
- Constants
- Variables
- func AutoFixRole(role string) string
- func IsUserRoleValid(role string) bool
- type AdminCreateUserForm
- type AlertNotification
- type Client
- func (c *Client) ActualUser() (*User, error)
- func (c *Client) AlertNotification(id int64) (*AlertNotification, error)
- func (c *Client) AlertNotifications() ([]*AlertNotification, error)
- func (c *Client) CreateUser(u User) error
- func (c *Client) CreateUserForm(settings AdminCreateUserForm) error
- func (c *Client) Dashboard(slug string) (*Dashboard, error)
- func (c *Client) DashboardMetas() ([]*DashboardMeta, error)
- func (c *Client) Dashboards() ([]*Dashboard, error)
- func (c *Client) DataSource(id int64) (*DataSource, error)
- func (c *Client) DataSources() ([]*DataSource, error)
- func (c *Client) DataSourcesByOrgID(id int64) ([]*DataSource, error)
- func (c *Client) DeleteAlertNotification(id int64) error
- func (c *Client) DeleteDashboard(uri string) error
- func (c *Client) DeleteDataSource(id int64) error
- func (c *Client) DeleteOrg(id int64) error
- func (c *Client) DeleteUser(id int64) error
- func (c *Client) Do(req *http.Request) (*http.Response, error)
- func (c *Client) FrontEndSettings() (map[string]interface{}, error)
- func (c *Client) GetCurrentOrgPrefs() (*OrgPrefs, error)
- func (c *Client) NewAlertNotification(a *AlertNotification) (int64, error)
- func (c *Client) NewDataSource(s *DataSource) (int64, error)
- func (c *Client) NewOrg(name string) (Org, error)
- func (c *Client) NewUser(u User) error
- func (c *Client) Org(id int64) (Org, error)
- func (c *Client) OrgByName(name string) (Org, error)
- func (c *Client) Orgs() ([]Org, error)
- func (c *Client) SaveDashboard(model map[string]interface{}, overwrite bool) (*DashboardSaveResponse, error)
- func (c *Client) SaveUser(u *User) error
- func (c *Client) SearchDashboards(query string, tag string, starred bool) ([]*DashboardMeta, error)
- func (c *Client) SetUserAdmin(id int64, admin bool) error
- func (c *Client) Stats() (map[string]int64, error)
- func (c *Client) SwitchCurrentUserOrg(orgID int64) error
- func (c *Client) SwitchUserOrg(userID, orgID int64) error
- func (c *Client) UpdateAlertNotification(a *AlertNotification) error
- func (c *Client) UpdateCurrentOrgPrefs(prefs *OrgPrefs) error
- func (c *Client) UpdateDataSource(s *DataSource) error
- func (c *Client) UpdateOrgUserRole(orgID, userID int64, role string) error
- func (c *Client) User(id int64) (*User, error)
- func (c *Client) UserByEmail(email string) (*User, error)
- func (c *Client) UserByLogin(login string) (*User, error)
- func (c *Client) Users() ([]*User, error)
- type Dashboard
- type DashboardMeta
- type DashboardSaveResponse
- type DataSource
- type JSONData
- type Org
- func (o Org) AddUser(c *Client, username, role string) error
- func (o Org) DataSources(c OrgDataSourceGetter) ([]*DataSource, error)
- func (o Org) RemoveUser(c *Client, userID int64) error
- func (o Org) SetHomeDashboard(c *Client, dashID int64) error
- func (o Org) String() string
- func (o Org) Users(c *Client) ([]*OrgUser, error)
- type OrgDataSourceGetter
- type OrgPrefs
- type OrgUser
- type OrgUsers
- type Response
- type SecureJSONData
- type Tags
- type User
- func (u User) AddToAllOrgs(c *Client, role string) error
- func (u User) MakeGlobalAdmin(c *Client) error
- func (u User) MakeGlobalEditor(c *Client) error
- func (u User) MakeGlobalViewer(c *Client) error
- func (u User) RemoveFromAllOrgs(c *Client) error
- func (u User) SwitchOrg(c *Client, orgID int64) error
- type Users
Constants ¶
const ( // OrgUserRoleViewer is the readonly role OrgUserRoleViewer = "Viewer" // OrgUserRoleAdmin is the admin role OrgUserRoleAdmin = "Admin" // OrgUserRoleEditor is the editing role OrgUserRoleEditor = "Editor" )
Variables ¶
var ( // ErrNotFound 404 ErrNotFound = errors.New(http.StatusText(404)) // ErrConflict 409 ErrConflict = errors.New(http.StatusText(409)) // ErrNotImplemented 501 ErrNotImplemented = errors.New(http.StatusText(501)) // ErrNotAuthorized 401 ErrNotAuthorized = errors.New(http.StatusText(401)) // ErrInternalServerError 500 ErrInternalServerError = errors.New(http.StatusText(500)) )
var ErrInvalidUserRole = fmt.Errorf("invalid user role")
ErrInvalidUserRole will be returned when a org user role is unknown
var UserRoleIsValid = IsUserRoleValid
UserRoleIsValid is deprecated in preference to IsUserRoleValid
Functions ¶
func AutoFixRole ¶
AutoFixRole will attempt to automatically fix common issues when setting user roles using strings. It will titleize and correct the miss-spelling of viewer
func IsUserRoleValid ¶
IsUserRoleValid will return true if the given role is valid
Types ¶
type AdminCreateUserForm ¶ added in v1.0.0
type AdminCreateUserForm struct { Email string `json:"email"` Login string `json:"login"` Name string `json:"name"` Password string `json:"password" binding:"Required"` }
AdminCreateUserForm is used to create a new user
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"` }
AlertNotification represents a Grafana alert notification
type Client ¶
Client represents a Grafana API client
func New ¶
New creates a new grafana client auth can be in user:pass format, or it can be an api key
func (*Client) ActualUser ¶ added in v1.1.0
ActualUser will return the actual user that is logged into the API
func (*Client) AlertNotification ¶
func (c *Client) AlertNotification(id int64) (*AlertNotification, error)
AlertNotification gets the alert with the given ID from Grafana
func (*Client) AlertNotifications ¶
func (c *Client) AlertNotifications() ([]*AlertNotification, error)
AlertNotifications returns all notifications for the actual/current org
func (*Client) CreateUser ¶
CreateUser creates a new user by wrapping the CreateUserForm method to avoiding requiring a dependency on Grafana code in your code
func (*Client) CreateUserForm ¶
func (c *Client) CreateUserForm(settings AdminCreateUserForm) error
CreateUserForm will create a user from the given form
func (*Client) DashboardMetas ¶
func (c *Client) DashboardMetas() ([]*DashboardMeta, error)
DashboardMetas returns the dashboard metadata for the current organisation context. These can then be used to get specific dashboards
func (*Client) Dashboards ¶
Dashboards returns the dashboards for the current org
func (*Client) DataSource ¶
func (c *Client) DataSource(id int64) (*DataSource, error)
DataSource will return the datasource with the given ID
func (*Client) DataSources ¶
func (c *Client) DataSources() ([]*DataSource, error)
DataSources will return all the datasources from Grafana
func (*Client) DataSourcesByOrgID ¶
func (c *Client) DataSourcesByOrgID(id int64) ([]*DataSource, error)
DataSourcesByOrgID will return the datasources for the given org ID
func (*Client) DeleteAlertNotification ¶
DeleteAlertNotification will delete the alert notification from Grafana matching the given ID
func (*Client) DeleteDashboard ¶
DeleteDashboard will delete the dashboard with the given slug from Grafana
func (*Client) DeleteDataSource ¶
DeleteDataSource will delete the datasource with the given ID from Grafana
func (*Client) DeleteUser ¶
DeleteUser deletes the user with the given ID from Grafana
func (*Client) Do ¶
Do overrides the Do method to hook in a response logger before returning the response
func (*Client) FrontEndSettings ¶
FrontEndSettings will get the front end settings from the API
func (*Client) GetCurrentOrgPrefs ¶ added in v1.1.0
GetCurrentOrgPrefs will get the preferences for the organisation in the current context, as selected by the SwitchContext method
func (*Client) NewAlertNotification ¶
func (c *Client) NewAlertNotification(a *AlertNotification) (int64, error)
NewAlertNotification creates the given alert notification object in Grafana
func (*Client) NewDataSource ¶
func (c *Client) NewDataSource(s *DataSource) (int64, error)
NewDataSource will create the given data source in Grafana
func (*Client) SaveDashboard ¶
func (c *Client) SaveDashboard(model map[string]interface{}, overwrite bool) (*DashboardSaveResponse, error)
SaveDashboard saves the given dashboard model to the API
func (*Client) SearchDashboards ¶ added in v1.1.0
SearchDashboards allows to search via query, tag or starred dashboards
func (*Client) SetUserAdmin ¶
SetUserAdmin will set the given user ID as an admin
func (*Client) SwitchCurrentUserOrg ¶
SwitchCurrentUserOrg will switch the current organisation of the signed in user
func (*Client) SwitchUserOrg ¶
SwitchUserOrg will switch the current organisation of the given user ID (via basic auth) to the given organisation ID
func (*Client) UpdateAlertNotification ¶
func (c *Client) UpdateAlertNotification(a *AlertNotification) error
UpdateAlertNotification wll update the alert notification in Grafana that matches the ID from the given alert notification object
func (*Client) UpdateCurrentOrgPrefs ¶ added in v1.1.0
UpdateCurrentOrgPrefs will update the preferences of the organisation in the current context, as selected by the SwitchContext method
func (*Client) UpdateDataSource ¶
func (c *Client) UpdateDataSource(s *DataSource) error
UpdateDataSource will update the data source in Grafana from the given datasource object that matches the given datasource objects ID
func (*Client) UpdateOrgUserRole ¶
UpdateOrgUserRole will update the role for the given user on the given org
func (*Client) UserByEmail ¶
UserByEmail will find a user by their email address
func (*Client) UserByLogin ¶
UserByLogin will find a user by their login
type Dashboard ¶
type Dashboard struct { Meta DashboardMeta `json:"meta"` Model map[string]interface{} `json:"dashboard"` }
Dashboard represents a Grafana dashboard
func (*Dashboard) RemoveTags ¶
RemoveTags will remove the given tags to the dashboard
type DashboardMeta ¶
type DashboardMeta struct { IsStarred bool `json:"isStarred"` ID int64 `json:"id"` Slug string `json:"slug"` Title string `json:"title"` URI string `json:"uri"` Type string `json:"type"` Tags []string `json:"tags"` }
DashboardMeta holds dashboard metadata
func (*DashboardMeta) SetSlug ¶ added in v1.1.0
func (meta *DashboardMeta) SetSlug()
type DashboardSaveResponse ¶
type DashboardSaveResponse struct { ID int64 `json:"id"` UID int64 `json:"uid"` URL string `json:"url"` Status string `json:"status"` Version int64 `json:"version"` Slug string `json:"slug"` }
DashboardSaveResponse represents the response from the API when a dashboard is saved
type DataSource ¶
type DataSource struct { ID int64 `json:"id,omitempty"` Name string `json:"name"` Type string `json:"type"` TypeLogoURL string `json:"typeLogoUrl"` 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"` BasicAuth bool `json:"basicAuth"` BasicAuthUser string `json:"basicAuthUser,omitempty"` BasicAuthPassword string `json:"basicAuthPassword,omitempty"` JSONData JSONData `json:"jsonData,omitempty"` SecureJSONData SecureJSONData `json:"secureJsonData,omitempty"` }
DataSource represents a Grafana data source
type JSONData ¶
type JSONData struct { AssumeRoleArn string `json:"assumeRoleArn,omitempty"` AuthType string `json:"authType,omitempty"` DefaultRegion string `json:"defaultRegion,omitempty"` }
JSONData is a representation of the datasource `jsonData` property
type Org ¶
Org represents an Organisation object in Grafana
func (Org) DataSources ¶
func (o Org) DataSources(c OrgDataSourceGetter) ([]*DataSource, error)
DataSources use the given client to return the datasources for the organisation
func (Org) RemoveUser ¶
RemoveUser removes the user from the organisation
func (Org) SetHomeDashboard ¶ added in v1.1.0
SetHomeDashboard will set the home dashboard of the organisation
type OrgDataSourceGetter ¶
type OrgDataSourceGetter interface {
DataSourcesByOrgID(int64) ([]*DataSource, error)
}
OrgDataSourceGetter allows getting datasources using an org ID
type OrgPrefs ¶ added in v1.1.0
type OrgPrefs struct { Theme string `json:"theme"` HomeDashboardID int64 `json:"homeDashboardId"` Timezone string `json:"timezone"` }
OrgPrefs represents the organisation preferences
type OrgUser ¶
type OrgUser struct { User ID int64 `json:"userId"` Role string `json:"role"` OrgID int64 `json:"orgId"` }
OrgUser is a user of the org
type OrgUsers ¶
type OrgUsers []*OrgUser
OrgUsers is a collection of Org user models
func (OrgUsers) FindByLogin ¶
FindByLogin returns the org user with the given email from a collection of org users, and a false if it was not found
type Response ¶
Response is an API response
func NewResponse ¶
NewResponse returns a new grafana API response
type SecureJSONData ¶
type SecureJSONData struct { AccessKey string `json:"accessKey,omitempty"` SecretKey string `json:"secretKey,omitempty"` }
SecureJSONData is a representation of the datasource `secureJsonData` property
type Tags ¶
Tags represents a set of tags
type User ¶
type User struct { ID int64 `json:"id"` Email string `json:"email"` Name string `json:"name"` Login string `json:"login"` OrgID int64 `json:"orgId"` IsAdmin bool `json:"isGrafanaAdmin"` // TODO: handle isAdmin returned from /api/users Password string `json:"password,omitempty"` }
User represents a Grafana user
func (User) AddToAllOrgs ¶
AddToAllOrgs will add the user to all orgs with the given role
func (User) MakeGlobalAdmin ¶
MakeGlobalAdmin assigns the user to all orgs with an Admin role
func (User) MakeGlobalEditor ¶
MakeGlobalEditor assigns the user to all orgs with a Editor role
func (User) MakeGlobalViewer ¶
MakeGlobalViewer assigns the user to all orgs with a Viewer role
func (User) RemoveFromAllOrgs ¶
RemoveFromAllOrgs will remove the user from all the orgs that they have a current role in
type Users ¶
type Users []*User
Users is a collection of user models
func (Users) FindByEmail ¶
FindByEmail returns the user with the given email from a collection of users, and a false if it was not found
func (Users) FindByLogin ¶
FindByLogin returns the user with the given email from a collection of users, and a false if it was not found
func (Users) FindIndexByEmail ¶
FindIndexByEmail is like FindByEmail but it returns the index