Documentation ¶
Index ¶
- Constants
- Variables
- func WaitHealthy(logger zerolog.Logger, c Client, maxRetry int)
- type Client
- func (c Client) CreateDatasource(ctx context.Context, orgId OrgId, name string, srcType string, isDefault bool) (Datasource, error)
- func (c Client) CreateFolder(ctx context.Context, orgId OrgId, title string) (Folder, error)
- func (c Client) CreateOrg(ctx context.Context, name string) (OrgId, error)
- func (c Client) CreateUpdateDashboard(ctx context.Context, orgId OrgId, folderUid Uid, dashboardJson map[string]any, ...) (Uid, error)
- func (c Client) DeleteDashboardByUid(ctx context.Context, orgId OrgId, dashboardID Uid) error
- func (c Client) DeleteDatasourceByName(ctx context.Context, orgId OrgId, name string) error
- func (c Client) DeleteFolder(ctx context.Context, orgId OrgId, folderId Uid) error
- func (c Client) GetDashboardByUid(ctx context.Context, orgId OrgId, dashboardID Uid) (Dashboard, error)
- func (c Client) GetDatasourceByName(ctx context.Context, orgId OrgId, name string) (Datasource, error)
- func (c Client) GetFolderPermissions(ctx context.Context, orgId OrgId, folderId Uid) ([]FolderPermission, error)
- func (c Client) HealthCheck(ctx context.Context) error
- func (c Client) ListDatasources(ctx context.Context, orgId OrgId) ([]Datasource, error)
- func (c Client) ListFolders(ctx context.Context, orgId OrgId, limit int, page int) ([]Folder, error)
- func (c Client) SearchDashboards(ctx context.Context, orgId OrgId, limit, page int, query string) ([]SearchDashboardResult, error)
- func (c Client) SetFolderPermissions(ctx context.Context, orgId OrgId, folderId Uid, ...) error
- func (c Client) UpdateDatasource(ctx context.Context, orgId OrgId, datasource Datasource) error
- type Dashboard
- type DashboardMetadata
- type Datasource
- type Folder
- type FolderPermission
- type FolderPermissionLevel
- type OrgId
- type Role
- type SearchDashboardResult
- type Uid
- type User
- type UserId
Constants ¶
const (
GrafanaOrgIdHeader = "X-Grafana-Org-Id"
)
const MaxUIDLength = 40
Variables ¶
var ( ErrGrafanaDashboardAlreadyExists = errors.New("grafana dashboard already exists") ErrGrafanaDashboardNotFound = errors.New("grafana dashboard not found") )
var ( ErrGrafanaDatasourceAlreadyExists = errors.New("grafana datasource already exists") ErrGrafanaDatasourceNotFound = errors.New("grafana datasource not found") )
var ( ErrGrafanaFolderAlreadyExists = errors.New("folder with same title already exists") ErrGrafanaFolderNotFound = errors.New("folder not found") )
var ( ErrUIDTooLong = fmt.Errorf("UID is longer than %d symbols", MaxUIDLength) ErrUIDFormatInvalid = errors.New("invalid format of UID. Only letters, numbers, '-' and '_' are allowed") ErrUIDEmpty = fmt.Errorf("UID is empty") )
var (
ErrGrafanaOrgAlreadyExists = errors.New("grafana org already exists")
)
var (
ErrGrafanaUserNotFound = errors.New("grafana user not found")
)
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client define an API client for grafana.
func ProvideClient ¶
Provide is a wire provider for Client.
func (Client) CreateDatasource ¶
func (c Client) CreateDatasource(ctx context.Context, orgId OrgId, name string, srcType string, isDefault bool) (Datasource, error)
CreateDatasource creates a datasource in the given organization.
func (Client) CreateFolder ¶
CreateFolder creates a folder within current organization.
func (Client) CreateOrg ¶
CreateOrg creates an organization with the given name. If it fails an error is returned. ErrGrafanaOrgAlreadyExists is returned if name is already used by an organization.
func (Client) CreateUpdateDashboard ¶
func (c Client) CreateUpdateDashboard(ctx context.Context, orgId OrgId, folderUid Uid, dashboardJson map[string]any, overwrite bool) (Uid, error)
CreateUpdateDashboard creates/updates a dashboard in the given organization and folder. dashboardJson map[string]any argument must contain a "uid" and "version" fields for updates. Version field must contains version BEFORE update, that is, the current version. If overwrite is sets to true, "version" field is optional.
func (Client) DeleteDashboardByUid ¶ added in v0.10.0
DeleteDashboardByUid deletes a dashboard with the given ID within the given organization.
func (Client) DeleteDatasourceByName ¶
DeleteDatasourceByName deletes datasource with the given name inside the given organization.
func (Client) DeleteFolder ¶
DeleteFolder deletes folder with the given Uid.
func (Client) GetDashboardByUid ¶ added in v0.10.0
func (c Client) GetDashboardByUid(ctx context.Context, orgId OrgId, dashboardID Uid) (Dashboard, error)
GetDashboardByUid returns dashboard with the given id within the given organization.
func (Client) GetDatasourceByName ¶
func (c Client) GetDatasourceByName(ctx context.Context, orgId OrgId, name string) (Datasource, error)
GetDatasourceByName retrieves datasource with the given name.
func (Client) GetFolderPermissions ¶
func (c Client) GetFolderPermissions(ctx context.Context, orgId OrgId, folderId Uid) ([]FolderPermission, error)
GetFolderPermissions gets permissions associated to folder with the given Uid.
func (Client) HealthCheck ¶
HealthCheck performs an health check request against a grafana instance.
func (Client) ListDatasources ¶
ListDatasources returns a list of datasource present in the given organization.
func (Client) ListFolders ¶
func (c Client) ListFolders(ctx context.Context, orgId OrgId, limit int, page int) ([]Folder, error)
ListFolders lists up to the given limit, children folders of parent folder with the given folder UUID.
func (Client) SearchDashboards ¶
func (c Client) SearchDashboards(ctx context.Context, orgId OrgId, limit, page int, query string) ([]SearchDashboardResult, error)
SearchDashboards searches dashboard within the given organization.
func (Client) SetFolderPermissions ¶
func (c Client) SetFolderPermissions(ctx context.Context, orgId OrgId, folderId Uid, permissions ...FolderPermission) error
SetFolderPermissions sets permissions associated to folder with the given Uid. This operation will remove existing permissions if they're not included in the request.
func (Client) UpdateDatasource ¶
UpdateDatasource updates datasource in the given organization.
type Dashboard ¶
type Dashboard struct { Dashboard map[string]any `json:"dashboard"` Metadata DashboardMetadata `json:"meta"` }
type DashboardMetadata ¶
type DashboardMetadata struct { AnnotationsPermissions struct { // contains filtered or unexported fields } CanAdmin bool CanDelete bool CanEdit bool CanSave bool CanStar bool Created time.Time CreatedBy string Expires time.Time FolderId int64 FolderTitle string FolderUid Uid `json:"folderUid,omitempty"` FolderUrl string HasAcl bool IsFolder bool IsSnapshot bool IsStarred bool Provisioned bool ProvisionedExternalId string PublicDashboardEnabled bool PublicDashboardUid string Slug string Type string Updated time.Time UpdatedBy string Url string Version int }
type Datasource ¶
type Datasource struct { Access string `json:"access,omitempty"` BasicAuth bool `json:"basicAuth,omitempty"` Database string `json:"database,omitempty"` Id int64 `json:"id,omitempty"` IsDefault bool `json:"isDefault,omitempty"` JSONData map[string]any `json:"jsonData,omitempty"` SecureJSONData map[string]any `json:"secureJsonData"` Name string `json:"name,omitempty"` OrgId OrgId `json:"orgId,omitempty"` ReadOnly bool `json:"readOnly,omitempty"` Type string `json:"type,omitempty"` TypeLogoUrl string `json:"typeLogoUrl,omitempty"` TypeName string `json:"typeName,omitempty"` Uid Uid `json:"uid,omitempty"` URL string `json:"url,omitempty"` User string `json:"user,omitempty"` Version uint `json:"version,omitempty"` }
Datasource define data sources for grafana dashboards.
type FolderPermission ¶
type FolderPermission struct { Permission FolderPermissionLevel `json:"permission"` Role Role `json:"role,omitempty"` TeamId int64 `json:"teamId,omitempty"` UserId UserId `json:"userId,omitempty"` }
type FolderPermissionLevel ¶
type FolderPermissionLevel int8
FolderPermissionLevel enumerate possible folder permission level.
const ( FolderPermissionLevelView FolderPermissionLevel = 1 << iota FolderPermissionLevelEdit FolderPermissionLevelAdmin )
func (FolderPermissionLevel) String ¶
func (fpl FolderPermissionLevel) String() string
String implements fmt.Stringer.
type Role ¶
type Role int8
Role enumerate possible user roles in an organization. If role is unknown, it will default to None.
func (Role) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Role) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type SearchDashboardResult ¶
type Uid ¶ added in v0.16.0
type Uid struct {
// contains filtered or unexported fields
}
Uid represents grafana uid type used to identify multiples ressources.
func (Uid) MarshalJSON ¶ added in v0.16.0
MarshalJSON implements json.Marshaler.
func (*Uid) UnmarshalJSON ¶ added in v0.16.0
UnmarshalJSON implements json.Unmarshaler.
type User ¶
type User struct { Id UserId `json:"id"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` IsDisabled bool `json:"isDisabled"` IsGrafanaAdmin bool `json:"isGrafanaAdmin"` IsGrafanaAdminExternallySynced bool `json:"isGrafanaAdminExternallySynced"` Name string `json:"name"` Email string `json:"email"` OrgId OrgId `json:"orgId"` }
User define a grafana user.