api

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2023 License: BSD-3-Clause-LBNL Imports: 48 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CloudType  = "cloud_type"
	BucketName = "bucket_name"
	Prefix     = "prefix"
)
View Source
const StorageContext = ContextStorage("storage")

Variables

View Source
var (
	DefaultFolderName = "General"
	DefaultFolderId   = int64(0)
)

Functions

func CreateDestinationPath

func CreateDestinationPath(v string)

CreateDestinationPath Handle osMkdir Errors

func DefaultUserPassword added in v0.4.0

func DefaultUserPassword(username string) string

func GetSlug

func GetSlug(title string) string

func NewDashboardFilter

func NewDashboardFilter(entries ...string) filters.Filter

func NewDataSourceFilter added in v0.4.0

func NewDataSourceFilter(name string) filters.Filter

func NewFolderFilter added in v0.4.0

func NewFolderFilter() filters.Filter

Types

type AlertNotificationsApi added in v0.4.0

type AlertNotificationsApi interface {
	ListAlertNotifications() []*models.AlertNotification
	ImportAlertNotifications() []string
	ExportAlertNotifications() []string
	DeleteAllAlertNotifications() []string
}

AlertNotificationsApi Contract definition Deprecated: Marked as Deprecated as of Grafana 9.0, Moving to ContactPoints is recommended

type ApiService

type ApiService interface {
	OrganizationsApi
	DashboardsApi
	DataSourcesApi
	AlertNotificationsApi
	UsersApi
	FoldersApi
	LibraryElementsApi

	//MetaData
	GetServerInfo() map[string]interface{}
}

func NewApiService

func NewApiService(override ...string) ApiService

type AuthenticationApi added in v0.4.0

type AuthenticationApi interface {
	Login()
	AdminLogin()
}

AuthenticationApi Contract definition

type CloudStorage

type CloudStorage struct {
	BucketRef   *blob.Bucket
	BucketName  string
	Prefix      string
	StorageName string
}

func (*CloudStorage) FindAllFiles

func (s *CloudStorage) FindAllFiles(folder string, fullPath bool) ([]string, error)

func (*CloudStorage) Name

func (s *CloudStorage) Name() string

func (*CloudStorage) ReadFile

func (s *CloudStorage) ReadFile(filename string) ([]byte, error)

ReadFile read file from Cloud Provider and return byte array

func (*CloudStorage) WriteFile

func (s *CloudStorage) WriteFile(filename string, data []byte, mode fs.FileMode) error

WriteFile persists data to Cloud Provider Storage returning error if operation failed

type ContextStorage

type ContextStorage string

type DashNGoImpl

type DashNGoImpl struct {
	// contains filtered or unexported fields
}

func NewDashNGoImpl

func NewDashNGoImpl() *DashNGoImpl

func (*DashNGoImpl) ClearAPIKeys added in v0.4.1

func (s *DashNGoImpl) ClearAPIKeys() error

func (*DashNGoImpl) CreateAdminAPIKey added in v0.4.1

func (s *DashNGoImpl) CreateAdminAPIKey(name string) *models.NewAPIKeyResult

func (*DashNGoImpl) DeleteAPIKey added in v0.4.1

func (s *DashNGoImpl) DeleteAPIKey(id int64) error

func (*DashNGoImpl) DeleteAllAlertNotifications

func (s *DashNGoImpl) DeleteAllAlertNotifications() []string

Removes all current alert notification channels

func (*DashNGoImpl) DeleteAllDashboards

func (s *DashNGoImpl) DeleteAllDashboards(filter filters.Filter) []string

DeleteAllDashboards clears all current dashboards being monitored. Any folder not white listed will not be affected

func (*DashNGoImpl) DeleteAllDataSources

func (s *DashNGoImpl) DeleteAllDataSources(filter filters.Filter) []string

Removes all current datasources

func (*DashNGoImpl) DeleteAllFolder

func (s *DashNGoImpl) DeleteAllFolder(filter filters.Filter) []string

func (*DashNGoImpl) DeleteAllLibraryElements added in v0.4.0

func (s *DashNGoImpl) DeleteAllLibraryElements(filter filters.Filter) []string

func (*DashNGoImpl) DeleteAllUsers

func (s *DashNGoImpl) DeleteAllUsers() []string

DeleteAllUsers

func (*DashNGoImpl) ExportAlertNotifications

func (s *DashNGoImpl) ExportAlertNotifications() []string

ExportAlertNotifications: exports all alert notification channels to grafana. NOTE: credentials will be missing and need to be set manually after export TODO implement configuring sensitive fields for different kinds of alert notification channels

func (*DashNGoImpl) ExportDashboards

func (s *DashNGoImpl) ExportDashboards(filterReq filters.Filter)

ExportDashboards finds all the dashboards in the configured location and exports them to grafana. if the folder doesn't exist, it'll be created.

func (*DashNGoImpl) ExportDataSources

func (s *DashNGoImpl) ExportDataSources(filter filters.Filter) []string

ExportDataSources: exports all datasources to grafana using the credentials configured in config file.

func (*DashNGoImpl) ExportFolder

func (s *DashNGoImpl) ExportFolder(filter filters.Filter) []string

func (*DashNGoImpl) ExportLibraryElements added in v0.4.0

func (s *DashNGoImpl) ExportLibraryElements(filter filters.Filter) []string

func (*DashNGoImpl) ExportUsers

func (s *DashNGoImpl) ExportUsers() []models.UserProfileDTO

func (*DashNGoImpl) GetServerInfo

func (s *DashNGoImpl) GetServerInfo() map[string]interface{}

GetServerInfo returns basic Grafana Server info

func (*DashNGoImpl) ImportAlertNotifications

func (s *DashNGoImpl) ImportAlertNotifications() []string

ImportAlertNotifications: will read in all the configured alert notification channels.

func (*DashNGoImpl) ImportDashboards

func (s *DashNGoImpl) ImportDashboards(filter filters.Filter) []string

ImportDashboards saves all dashboards matching query to configured location

func (*DashNGoImpl) ImportDataSources

func (s *DashNGoImpl) ImportDataSources(filter filters.Filter) []string

ImportDataSources: will read in all the configured datasources. NOTE: credentials cannot be retrieved and need to be set via configuration

func (*DashNGoImpl) ImportFolder

func (s *DashNGoImpl) ImportFolder(filter filters.Filter) []string

func (*DashNGoImpl) ImportLibraryElements added in v0.4.0

func (s *DashNGoImpl) ImportLibraryElements(filter filters.Filter) []string

func (*DashNGoImpl) ImportUsers

func (s *DashNGoImpl) ImportUsers() []string

func (*DashNGoImpl) ListAlertNotifications

func (s *DashNGoImpl) ListAlertNotifications() []*models.AlertNotification

func (*DashNGoImpl) ListDashboards

func (s *DashNGoImpl) ListDashboards(filterReq filters.Filter) []*models.Hit

ListDashboards List all dashboards optionally filtered by folder name. If folderFilters is blank, defaults to the configured Monitored folders

func (*DashNGoImpl) ListDataSources

func (s *DashNGoImpl) ListDataSources(filter filters.Filter) []models.DataSourceListItemDTO

func (*DashNGoImpl) ListFolder

func (s *DashNGoImpl) ListFolder(filter filters.Filter) []*models.Hit

func (*DashNGoImpl) ListLibraryElements added in v0.4.0

func (s *DashNGoImpl) ListLibraryElements(filter filters.Filter) []*models.LibraryElementDTO

func (*DashNGoImpl) ListLibraryElementsConnections added in v0.4.1

func (s *DashNGoImpl) ListLibraryElementsConnections(filter filters.Filter, connectionID string) []*models.DashboardFullWithMeta

func (*DashNGoImpl) ListOrganizations

func (s *DashNGoImpl) ListOrganizations() []*models.OrgDTO

ListOrganizations: List all dashboards

func (*DashNGoImpl) ListUsers

func (s *DashNGoImpl) ListUsers() []*models.UserSearchHitDTO

ListUsers list all grafana users

func (*DashNGoImpl) Login

func (s *DashNGoImpl) Login()

Login Logs into grafana returning a legacyClient instance using Token or Basic Auth

func (*DashNGoImpl) PromoteUser

func (s *DashNGoImpl) PromoteUser(userLogin string) (string, error)

PromoteUser promote the user to have Admin Access

func (*DashNGoImpl) SetStorage

func (s *DashNGoImpl) SetStorage(v Storage)

Testing Only

type DashboardsApi added in v0.4.0

type DashboardsApi interface {
	ListDashboards(filter filters.Filter) []*models.Hit
	ImportDashboards(filter filters.Filter) []string
	ExportDashboards(filter filters.Filter)
	DeleteAllDashboards(filter filters.Filter) []string
	// contains filtered or unexported methods
}

DashboardsApi Contract definition

type DataSourcesApi added in v0.4.0

type DataSourcesApi interface {
	ListDataSources(filter filters.Filter) []models.DataSourceListItemDTO
	ImportDataSources(filter filters.Filter) []string
	ExportDataSources(filter filters.Filter) []string
	DeleteAllDataSources(filter filters.Filter) []string
}

DataSourcesApi Contract definition

type FoldersApi added in v0.4.0

type FoldersApi interface {
	ListFolder(filter filters.Filter) []*models.Hit
	ImportFolder(filter filters.Filter) []string
	ExportFolder(filter filters.Filter) []string
	DeleteAllFolder(filter filters.Filter) []string
}

FoldersApi Contract definition

type LibraryElementsApi added in v0.4.0

type LibraryElementsApi interface {
	ListLibraryElements(filter filters.Filter) []*models.LibraryElementDTO
	ListLibraryElementsConnections(filter filters.Filter, connectionID string) []*models.DashboardFullWithMeta
	ImportLibraryElements(filter filters.Filter) []string
	ExportLibraryElements(filter filters.Filter) []string
	DeleteAllLibraryElements(filter filters.Filter) []string
}

type LocalStorage

type LocalStorage struct {
}

LocalStorage default storage engine

func (*LocalStorage) FindAllFiles

func (s *LocalStorage) FindAllFiles(folder string, fullPath bool) ([]string, error)

func (LocalStorage) Name

func (LocalStorage) Name() string

func (*LocalStorage) ReadFile

func (s *LocalStorage) ReadFile(filename string) ([]byte, error)

ReadFile returns a byte array of file content

func (*LocalStorage) WriteFile

func (s *LocalStorage) WriteFile(filename string, data []byte, mode fs.FileMode) error

WriteFile writes file to disk and returns an error if operation failed

type OrganizationsApi added in v0.4.0

type OrganizationsApi interface {
	ListOrganizations() []*models.OrgDTO
}

OrganizationsApi Contract definition

type Storage

type Storage interface {
	WriteFile(filename string, data []byte, mode fs.FileMode) error // WriteFile returns error or writes byte array to destination
	ReadFile(filename string) ([]byte, error)                       // ReadFile returns byte array or error with data from file
	FindAllFiles(folder string, fullPath bool) ([]string, error)    // FindAllFiles recursively list all files for a given path
	Name() string                                                   // Name of storage engine
}

TODO: pull all the cloud based interaction into a Plugin System

func NewCloudStorage

func NewCloudStorage(c context.Context) (Storage, error)

func NewLocalStorage

func NewLocalStorage(ctx context.Context) Storage

type UsersApi added in v0.4.0

type UsersApi interface {
	//User
	ListUsers() []*models.UserSearchHitDTO
	ImportUsers() []string
	ExportUsers() []models.UserProfileDTO
	PromoteUser(userLogin string) (string, error)
	DeleteAllUsers() []string
	//TODO: clean up and expose API Keys management via CLI
	CreateAdminAPIKey(name string) *models.NewAPIKeyResult
	DeleteAPIKey(id int64) error
	ClearAPIKeys() error
}

UsersApi Contract definition

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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