gapi

package module
v0.0.0-...-d4d7cce Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: Apache-2.0 Imports: 19 Imported by: 1

README

ARCHIVED

This repo was an attempt at using the swagger spec prior to an official client has been released. Please use the official client that can be found here.


Go workflow

Grafana HTTP API Client for Go

This library provides a low-level client to access Grafana HTTP API.

Generating New GoModels

GRAFANA_TARGET_VERSION=v9.3.6 make generate

This project is heavily inspired by the work from @papagian which can be found on here

Initially, API version will match the grafana version.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetClient

func GetClient(serverURL string) (*client.GrafanaHTTPAPI, error)

func ToPtr

func ToPtr[T any](t T) *T

Types

type APIKeyAuthenticator

type APIKeyAuthenticator struct {
	APIKey string
}

func (APIKeyAuthenticator) AuthenticateRequest

func (a APIKeyAuthenticator) AuthenticateRequest(req runtime.ClientRequest, reg strfmt.Registry) error

type BasicAuthenticator

type BasicAuthenticator struct {
	Username string
	Password string
}

func (BasicAuthenticator) AuthenticateRequest

func (a BasicAuthenticator) AuthenticateRequest(req runtime.ClientRequest, reg strfmt.Registry) error

type CloudAPIKey

type CloudAPIKey struct {
	ID         int
	Name       string
	Role       string
	Token      string
	Expiration string
}

type CloudClient

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

CloudClient is a Grafana API client.

func New

func New(baseURL string, cfg Config) (*CloudClient, error)

New creates a new Grafana client.

func (*CloudClient) CreateCloudAPIKey

func (c *CloudClient) CreateCloudAPIKey(org string, input *CreateCloudAPIKeyInput) (*CloudAPIKey, error)

func (*CloudClient) DeleteCloudAPIKey

func (c *CloudClient) DeleteCloudAPIKey(org string, keyName string) error

func (*CloudClient) DeleteStack

func (c *CloudClient) DeleteStack(stackSlug string) error

DeleteStack deletes the Grafana stack whose slug it passed in.

func (*CloudClient) GetCloudPluginInstallation

func (c *CloudClient) GetCloudPluginInstallation(stackSlug string, pluginSlug string) (*CloudPluginInstallation, error)

GetCloudPluginInstallation returns the cloud plugin installation details for the specified plugin.

func (*CloudClient) GetCloudRegionBySlug

func (c *CloudClient) GetCloudRegionBySlug(slug string) (CloudRegion, error)

GetCloudRegionBySlug fetches and returns the cloud region which matches the given slug. You can also provide a numeric region ID.

func (*CloudClient) GetCloudRegions

func (c *CloudClient) GetCloudRegions() (CloudRegionsResponse, error)

GetCloudRegions fetches and returns all Grafana Cloud regions.

func (*CloudClient) InstallCloudPlugin

func (c *CloudClient) InstallCloudPlugin(stackSlug string, pluginSlug string, pluginVersion string) (*CloudPluginInstallation, error)

InstallCloudPlugin installs the specified plugin to the given stack.

func (*CloudClient) IsCloudPluginInstalled

func (c *CloudClient) IsCloudPluginInstalled(stackSlug string, pluginSlug string) (bool, error)

IsCloudPluginInstalled returns a boolean if the specified plugin is installed on the stack.

func (*CloudClient) ListCloudAPIKeys

func (c *CloudClient) ListCloudAPIKeys(org string) (*ListCloudAPIKeysOutput, error)

func (*CloudClient) NewStack

func (c *CloudClient) NewStack(stack *CreateStackInput) (int64, error)

NewStack creates a new Grafana Stack

func (*CloudClient) PluginByID

func (c *CloudClient) PluginByID(pluginID int64) (*Plugin, error)

PluginByID returns the plugin with the given id. An error will be returned given an unknown ID.

func (*CloudClient) PluginBySlug

func (c *CloudClient) PluginBySlug(slug string) (*Plugin, error)

PluginBySlug returns the plugin with the given slug. An error will be returned given an unknown slug.

func (*CloudClient) StackByID

func (c *CloudClient) StackByID(id int64) (Stack, error)

StackByID fetches and returns the stack whose name it's passed. This returns deleted instances as well with `status=deleted`.

func (*CloudClient) StackBySlug

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

StackByName fetches and returns the stack whose slug it's passed.

func (*CloudClient) Stacks

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

Stacks fetches and returns the Grafana stacks.

func (*CloudClient) UninstallCloudPlugin

func (c *CloudClient) UninstallCloudPlugin(stackSlug string, pluginSlug string) error

UninstallCloudPlugin uninstalls the specified plugin to the given stack.

func (*CloudClient) UpdateStack

func (c *CloudClient) UpdateStack(id int64, stack *UpdateStackInput) error

UpdateOrg updates a Grafana stack. Only name, slug and description can be updated. No other parameters of the stack are updateable

type CloudPluginInstallation

type CloudPluginInstallation struct {
	ID           int    `json:"id"`
	InstanceID   int    `json:"instanceId"`
	InstanceURL  string `json:"instanceUrl"`
	InstanceSlug string `json:"instanceSlug"`
	PluginID     int    `json:"pluginId"`
	PluginSlug   string `json:"pluginSlug"`
	PluginName   string `json:"pluginName"`
	Version      string `json:"version"`
}

type CloudRegion

type CloudRegion struct {
	ID          int    `json:"id"`
	Status      string `json:"status"`
	Slug        string `json:"slug"`
	Name        string `json:"name"`
	Description string `json:"description"`
	CreatedAt   string `json:"createdAt"`
	UpdatedAt   string `json:"updatedAt"`
	Visibility  string `json:"visibility"`

	// Service URLs for the region
	StackStateServiceURL      string `json:"stackStateServiceUrl"`
	SyntheticMonitoringAPIURL string `json:"syntheticMonitoringApiUrl"`
	IntegrationsAPIURL        string `json:"integrationsApiUrl"`
	HostedExportersAPIURL     string `json:"hostedExportersApiUrl"`
	MachineLearningAPIURL     string `json:"machineLearningApiUrl"`
	IncidentsAPIURL           string `json:"incidentsApiUrl"`

	// Hosted Grafana
	HGClusterID   int    `json:"hgClusterId"`
	HGClusterSlug string `json:"hgClusterSlug"`
	HGClusterName string `json:"hgClusterName"`
	HGClusterURL  string `json:"hgClusterUrl"`

	// Hosted Metrics: Prometheus
	HMPromClusterID   int    `json:"hmPromClusterId"`
	HMPromClusterSlug string `json:"hmPromClusterSlug"`
	HMPromClusterName string `json:"hmPromClusterName"`
	HMPromClusterURL  string `json:"hmPromClusterUrl"`

	// Hosted Metrics: Graphite
	HMGraphiteClusterID   int    `json:"hmGraphiteClusterId"`
	HMGraphiteClusterSlug string `json:"hmGraphiteClusterSlug"`
	HMGraphiteClusterName string `json:"hmGraphiteClusterName"`
	HMGraphiteClusterURL  string `json:"hmGraphiteClusterUrl"`

	// Hosted Logs
	HLClusterID   int    `json:"hlClusterId"`
	HLClusterSlug string `json:"hlClusterSlug"`
	HLClusterName string `json:"hlClusterName"`
	HLClusterURL  string `json:"hlClusterUrl"`

	// Alertmanager
	AMClusterID   int    `json:"amClusterId"`
	AMClusterSlug string `json:"amClusterSlug"`
	AMClusterName string `json:"amClusterName"`
	AMClusterURL  string `json:"amClusterUrl"`

	// Hosted Traces
	HTClusterID   int    `json:"htClusterId"`
	HTClusterSlug string `json:"htClusterSlug"`
	HTClusterName string `json:"htClusterName"`
	HTClusterURL  string `json:"htClusterUrl"`
}

CloudRegion represents a Grafana Cloud region. https://grafana.com/docs/grafana-cloud/reference/cloud-api/#list-regions

type CloudRegionsResponse

type CloudRegionsResponse struct {
	Items []CloudRegion `json:"items"`
}

CloudRegionsResponse represents the response from the Grafana Cloud regions API.

type Config

type Config struct {
	// APIKey is an optional API key.
	APIKey string
	// BasicAuth is optional basic auth credentials.
	BasicAuth *url.Userinfo
	// HTTPHeaders are optional HTTP headers.
	HTTPHeaders map[string]string
	// Client provides an optional HTTP client, otherwise a default will be used.
	Client *http.Client
	// OrgID provides an optional organization ID, ignored when using APIKey, BasicAuth defaults to last used org
	OrgID int64
	// NumRetries contains the number of attempted retries
	NumRetries int
}

Config contains client configuration.

type CreateCloudAPIKeyInput

type CreateCloudAPIKeyInput struct {
	Name string `json:"name"`
	Role string `json:"role"`
}

type CreateStackInput

type CreateStackInput struct {
	Name        string `json:"name"`
	Slug        string `json:"slug"`
	URL         string `json:"url"`
	Region      string `json:"region"`
	Description string `json:"description"`
}

type ListCloudAPIKeysOutput

type ListCloudAPIKeysOutput struct {
	Items []*CloudAPIKey
}

type Plugin

type Plugin struct {
	ID          int    `json:"id"`
	Name        string `json:"name"`
	Slug        string `json:"slug"`
	Version     string `json:"version"`
	Description string `json:"description"`
}

type Stack

type Stack struct {
	ID                       int64     `json:"id"`
	OrgID                    int64     `json:"orgId"`
	OrgSlug                  string    `json:"orgSlug"`
	OrgName                  string    `json:"orgName"`
	Name                     string    `json:"name"`
	URL                      string    `json:"url"`
	Slug                     string    `json:"slug"`
	Version                  string    `json:"version"`
	Description              string    `json:"description"`
	Status                   string    `json:"status"`
	Gateway                  string    `json:"gateway"`
	CreatedAt                time.Time `json:"createdAt"`
	CreatedBy                string    `json:"createdBy"`
	UpdatedAt                time.Time `json:"updatedAt"`
	UpdatedBy                string    `json:"updatedBy"`
	Trial                    int       `json:"trial"`
	TrialExpiresAt           time.Time `json:"trialExpiresAt"`
	ClusterID                int       `json:"clusterId"`
	ClusterSlug              string    `json:"clusterSlug"`
	ClusterName              string    `json:"clusterName"`
	Plan                     string    `json:"plan"`
	PlanName                 string    `json:"planName"`
	BillingStartDate         time.Time `json:"billingStartDate"`
	BillingEndDate           time.Time `json:"billingEndDate"`
	BillingActiveUsers       int       `json:"billingActiveUsers"`
	CurrentActiveUsers       int       `json:"currentActiveUsers"`
	CurrentActiveAdminUsers  int       `json:"currentActiveAdminUsers"`
	CurrentActiveEditorUsers int       `json:"currentActiveEditorUsers"`
	CurrentActiveViewerUsers int       `json:"currentActiveViewerUsers"`
	DailyUserCnt             int       `json:"dailyUserCnt"`
	DailyAdminCnt            int       `json:"dailyAdminCnt"`
	DailyEditorCnt           int       `json:"dailyEditorCnt"`
	DailyViewerCnt           int       `json:"dailyViewerCnt"`
	BillableUserCnt          int       `json:"billableUserCnt"`
	DashboardCnt             int       `json:"dashboardCnt"`
	DatasourceCnts           struct {
	} `json:"datasourceCnts"`
	UserQuota                         int     `json:"userQuota"`
	DashboardQuota                    int     `json:"dashboardQuota"`
	AlertQuota                        int     `json:"alertQuota"`
	Ssl                               bool    `json:"ssl"`
	CustomAuth                        bool    `json:"customAuth"`
	CustomDomain                      bool    `json:"customDomain"`
	Support                           bool    `json:"support"`
	RunningVersion                    string  `json:"runningVersion"`
	MachineLearning                   int     `json:"machineLearning"`
	HmInstancePromID                  int     `json:"hmInstancePromId"`
	HmInstancePromURL                 string  `json:"hmInstancePromUrl"`
	HmInstancePromName                string  `json:"hmInstancePromName"`
	HmInstancePromStatus              string  `json:"hmInstancePromStatus"`
	HmInstancePromCurrentUsage        float64 `json:"hmInstancePromCurrentUsage"`
	HmInstancePromCurrentActiveSeries int     `json:"hmInstancePromCurrentActiveSeries"`
	HmInstanceGraphiteID              int     `json:"hmInstanceGraphiteId"`
	HmInstanceGraphiteURL             string  `json:"hmInstanceGraphiteUrl"`
	HmInstanceGraphiteName            string  `json:"hmInstanceGraphiteName"`
	HmInstanceGraphiteType            string  `json:"hmInstanceGraphiteType"`
	HmInstanceGraphiteStatus          string  `json:"hmInstanceGraphiteStatus"`
	HmInstanceGraphiteCurrentUsage    float64 `json:"hmInstanceGraphiteCurrentUsage"`
	HlInstanceID                      int     `json:"hlInstanceId"`
	HlInstanceURL                     string  `json:"hlInstanceUrl"`
	HlInstanceName                    string  `json:"hlInstanceName"`
	HlInstanceStatus                  string  `json:"hlInstanceStatus"`
	HlInstanceCurrentUsage            float64 `json:"hlInstanceCurrentUsage"`
	AmInstanceID                      int     `json:"amInstanceId"`
	AmInstanceName                    string  `json:"amInstanceName"`
	AmInstanceURL                     string  `json:"amInstanceUrl"`
	AmInstanceStatus                  string  `json:"amInstanceStatus"`
	AmInstanceGeneratorURL            string  `json:"amInstanceGeneratorUrl"`
	HtInstanceID                      int     `json:"htInstanceId"`
	HtInstanceURL                     string  `json:"htInstanceUrl"`
	HtInstanceName                    string  `json:"htInstanceName"`
	HtInstanceStatus                  string  `json:"htInstanceStatus"`
	RegionID                          int     `json:"regionId"`
	RegionSlug                        string  `json:"regionSlug"`
	Links                             []struct {
		Rel  string `json:"rel"`
		Href string `json:"href"`
	} `json:"links"`
}

https://grafana.com/docs/grafana-cloud/reference/cloud-api/#stacks

type StackItems

type StackItems struct {
	Items []*Stack `json:"items"`
}

StackItems represents Grafana stack items.

type UpdateStackInput

type UpdateStackInput struct {
	Name        string `json:"name"`
	Slug        string `json:"slug"`
	Description string `json:"description"`
}

Jump to

Keyboard shortcuts

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