client

package module
v0.0.0-...-6bc99fc Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2025 License: MIT Imports: 13 Imported by: 1

README

Grafana-client

A Go module wrapping Grafana Cloud API (grafana-com-public-clients/go/gcom) and Grafana HTTP API (grafana-openapi-client-go) official client implementations.

Documentation

Overview

Package client provides a Go client for interacting with Grafana Cloud and Grafana HTTP APIs. It supports operations for managing service accounts, tokens, organizations, and dashboards.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CloudClient

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

CloudClient implements GrafanaCloudClient interface and handles communication with the Grafana Cloud API.

func (*CloudClient) CreateServiceAccount

func (c *CloudClient) CreateServiceAccount(instanceId int, saName string, roleName string) (*ServiceAccount, error)

func (*CloudClient) CreateToken

func (c *CloudClient) CreateToken(stackId int, serviceAccountID int, tokenName string) (*Token, error)

func (*CloudClient) DeleteServiceAccount

func (c *CloudClient) DeleteServiceAccount(instanceId int, saId int) error

func (*CloudClient) GetStack

func (c *CloudClient) GetStack(slug string) (*Stack, error)

GetStack returns a stack definition for the corresponding GrafanaCloud stack identified by its slug. Returns an error if the stack cannot be found or if the API request fails.

func (*CloudClient) ListStacks

func (c *CloudClient) ListStacks() (Stacks, error)

ListStacks retrieves all available stacks from GrafanaCloud. Returns a collection of Stack objects or an error if the API request fails.

func (*CloudClient) NewStackClient

func (cc *CloudClient) NewStackClient(stack *Stack) (GrafanaStackClient, error)

func (*CloudClient) NewStackClientWithHttpClient

func (cc *CloudClient) NewStackClientWithHttpClient(stack *Stack, httpClient *http.Client) (GrafanaStackClient, error)

type Dashboard

type Dashboard struct {
	UID       string `json:"uid"`
	Title     string `json:"title"`
	FolderUID string
	Dashboard JSON
	Meta      *models.DashboardMeta
}

Dashboard represents a Grafana dashboard with its metadata and content

type DashboardClient

type DashboardClient interface {
	// UploadDashboard creates or updates a dashboard in Grafana.
	UploadDashboard(dashboard *Dashboard) error

	// GetDashboard retrieves a dashboard by its UID.
	GetDashboard(uid string) (*Dashboard, error)

	// DeleteDashboard removes a dashboard identified by its UID.
	DeleteDashboard(uid string) error

	// EnsureFolder creates a folder if it doesn't exist or returns existing folder.
	EnsureFolder(folder string) (*Folder, error)

	// GetDataSource retrieves a datasource by its name.
	GetDataSource(name string) (*Datasource, error)
}

DashboardClient defines operations for uploading and updating dashboards in a Grafana instance.

type Datasource

type Datasource = models.DataSource

type Folder

type Folder struct {
	UID   string `json:"uid"`
	Title string `json:"title"`
}

Folder represents a Grafana folder with its UID and title

type GrafanaCloudClient

type GrafanaCloudClient interface {
	ServiceAccountClient
	TokenClient
	OrganisationClient
	NewStackClient(stack *Stack) (GrafanaStackClient, error)
	NewStackClientWithHttpClient(stack *Stack, httpClient *http.Client) (GrafanaStackClient, error)
}

GrafanaCloudClient is the main interface for interacting with Grafana Cloud API. It provides access to service accounts, tokens, and organization management. It also allows creating new stack clients for specific Grafana instances.

func NewCloudClient

func NewCloudClient() (GrafanaCloudClient, error)

NewCloudClient creates a new GrafanaCloudClient using the default HTTP client. It requires GRAFANA_CLOUD_TOKEN environment variable to be set.

func NewCloudClientWithHttpClient

func NewCloudClientWithHttpClient(httpClient *http.Client) (GrafanaCloudClient, error)

NewCloudClientWithHttpClient creates a new GrafanaCloudClient using the provided HTTP client. It requires GRAFANA_CLOUD_TOKEN environment variable to be set.

type GrafanaStackClient

type GrafanaStackClient interface {
	DashboardClient
	Cleanup() error
}

GrafanaStackClient represents a client for a specific Grafana stack instance. It provides operations for managing dashboards and cleanup operations.

type JSON

type JSON interface{}

type OrganisationClient

type OrganisationClient interface {
	GetStack(slug string) (*Stack, error)
	ListStacks() (Stacks, error)
}

OrganisationClient defines operations for managing Grafana Cloud organizations and retrieving stack information.

type ServiceAccount

type ServiceAccount struct {
	Id             int    `json:"id,omitempty"`
	IsDisabled     bool   `json:"isDisabled,omitempty"`
	Name           string `json:"name,omitempty"`
	OrgId          int    `json:"orgId,omitempty"`
	Role           string `json:"role,omitempty"`
	NumberOfTokens int    `json:"tokens,omitempty"`
}

ServiceAccount represents a Grafana service account with its associated properties such as ID, name, role, and status.

type ServiceAccountClient

type ServiceAccountClient interface {
	// CreateServiceAccount creates a new service account in the specified Grafana instance
	// with the given name and role.
	CreateServiceAccount(instanceId int, saName string, roleName string) (*ServiceAccount, error)

	// DeleteServiceAccount removes a service account from the specified Grafana instance.
	DeleteServiceAccount(instanceId int, saId int) error
}

ServiceAccountClient defines all operations related to creating, retrieving, and deleting service accounts in Grafana Cloud.

type Stack

type Stack struct {
	LogsInstanceID    int    `json:"hlInstanceId"`
	MetricsInstanceID int    `json:"hmInstancePromId"`
	PromURL           string `json:"hmInstancePromUrl"`
	LogsURL           string `json:"hlInstanceUrl"`
	StackID           int    `json:"id"`
	Slug              string `json:"slug" yaml:"slug"`
	StackURL          string `json:"url" yaml:"url"`
}

Stack contains all the relevant details of a GrafanaCloud stack including instance IDs, URLs, and identification information.

type StackClient

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

StackClient implements GrafanaStackClient interface and handles operations for a specific Grafana stack instance.

func (*StackClient) Cleanup

func (c *StackClient) Cleanup() error

func (*StackClient) DeleteDashboard

func (sc *StackClient) DeleteDashboard(uid string) error

func (*StackClient) EnsureFolder

func (sc *StackClient) EnsureFolder(folderName string) (*Folder, error)

func (*StackClient) GetDashboard

func (sc *StackClient) GetDashboard(uid string) (*Dashboard, error)

func (*StackClient) GetDataSource

func (sc *StackClient) GetDataSource(name string) (*Datasource, error)

func (*StackClient) GetFolder

func (sc *StackClient) GetFolder(folderName string) (*Folder, error)

func (*StackClient) UploadDashboard

func (sc *StackClient) UploadDashboard(dashboard *Dashboard) error

type Stacks

type Stacks []Stack

Stacks represents a collection of Stack objects

type Token

type Token struct {
	Id   int64  `json:"id,omitempty"`
	Key  string `json:"key,omitempty"`
	Name string `json:"name,omitempty"`
}

Token represents a Grafana service account token with its associated ID, key, and name.

type TokenClient

type TokenClient interface {
	// CreateToken creates a new token for a service account in the specified stack.
	CreateToken(stackId int, serviceAccountID int, tokenName string) (*Token, error)
}

TokenClient defines operations for managing service account tokens in Grafana Cloud.

Jump to

Keyboard shortcuts

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