grafana

package module
v1.50.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: MIT Imports: 9 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatAlertsTable

func FormatAlertsTable(alerts []Annotation) string

Types

type Alert

type Alert struct {
	Annotations struct {
		DashboardUID string `json:"__dashboardUid__"`
		OrgID        string `json:"__orgId__"`
		PanelID      string `json:"__panelId__"`
		Description  string `json:"description"`
		RunbookURL   string `json:"runbook_url"`
		Summary      string `json:"summary"`
	} `json:"annotations"`
	EndsAt      time.Time `json:"endsAt"`
	Fingerprint string    `json:"fingerprint"`
	Receivers   []struct {
		Active       interface{} `json:"active"`
		Integrations interface{} `json:"integrations"`
		Name         string      `json:"name"`
	} `json:"receivers"`
	StartsAt time.Time `json:"startsAt"`
	Status   struct {
		InhibitedBy []interface{} `json:"inhibitedBy"`
		SilencedBy  []interface{} `json:"silencedBy"`
		State       string        `json:"state"`
	} `json:"status"`
	UpdatedAt    time.Time         `json:"updatedAt"`
	GeneratorURL string            `json:"generatorURL"`
	Labels       map[string]string `json:"labels"`
}

type AlertGroupsResponse

type AlertGroupsResponse struct {
	Alerts []Alert `json:"alerts"`
	Labels struct {
		Alertname     string `json:"alertname"`
		GrafanaFolder string `json:"grafana_folder"`
	} `json:"labels"`
	Receiver struct {
		Active       interface{} `json:"active"`
		Integrations interface{} `json:"integrations"`
		Name         string      `json:"name"`
	} `json:"receiver"`
}

AlertGroupsResponse is response body for "api/alertmanager/grafana/api/v2/alerts/groups"

type AlertManagerClient

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

func (*AlertManagerClient) GetAlertGroups

func (g *AlertManagerClient) GetAlertGroups() ([]AlertGroupsResponse, *resty.Response, error)

func (*AlertManagerClient) GetAlterManagerAlerts

func (g *AlertManagerClient) GetAlterManagerAlerts() ([]interface{}, *resty.Response, error)

type AlertRulerClient

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

func (*AlertRulerClient) GetAlertsForDashboard

func (g *AlertRulerClient) GetAlertsForDashboard(dashboardUID string) (map[string][]interface{}, *resty.Response, error)

ruler API is deprecated https://github.com/grafana/grafana/issues/74434

func (*AlertRulerClient) PostAlert

func (g *AlertRulerClient) PostAlert(dashboardUID string) (map[string][]interface{}, *resty.Response, error)

type Annotation

type Annotation struct {
	ID           int64         `json:"id"`
	AlertID      int64         `json:"alertId"`
	DashboardID  int64         `json:"dashboardId"`
	DashboardUID string        `json:"dashboardUID"`
	PanelID      int64         `json:"panelId"`
	PrevState    string        `json:"prevState"`
	NewState     string        `json:"newState"`
	Text         string        `json:"text"`
	Time         CustomTime    `json:"time"`
	TimeEnd      CustomTime    `json:"timeEnd"`
	Created      CustomTime    `json:"created"`
	Updated      CustomTime    `json:"updated"`
	Tags         []interface{} `json:"tags"`
	Data         interface{}   `json:"data"`
}

type AnnotationsQueryParams

type AnnotationsQueryParams struct {
	Limit        *int
	AlertID      *int
	DashboardID  *int
	DashboardUID *string // when dashboardUID presents, dashboardId would be ignored by /annotations API
	Type         *string
	From         *time.Time
	To           *time.Time
}

type Client

type Client struct {
	AlertManager *AlertManagerClient
	AlertRuler   *AlertRulerClient
	// contains filtered or unexported fields
}

func NewGrafanaClient

func NewGrafanaClient(url, apiKey string) *Client

func (*Client) DeleteAnnotation

func (c *Client) DeleteAnnotation(annotationID int64) (*resty.Response, error)

func (*Client) GetAlertRulesForDashboardID

func (c *Client) GetAlertRulesForDashboardID(dashboardID string) ([]ProvisionedAlertRule, error)

func (*Client) GetAlertsRules

func (c *Client) GetAlertsRules() ([]ProvisionedAlertRule, *resty.Response, error)

func (*Client) GetAnnotations

func (c *Client) GetAnnotations(params AnnotationsQueryParams) ([]Annotation, *resty.Response, error)

func (*Client) GetDashboard

func (c *Client) GetDashboard(uid string) (GetDashboardResponse, *resty.Response, error)

func (*Client) GetDatasources

func (c *Client) GetDatasources() (map[string]string, *resty.Response, error)

func (*Client) PostAnnotation

func (c *Client) PostAnnotation(annotation PostAnnotation) (PostAnnotationResponse, *resty.Response, error)

func (*Client) PostDashboard

func (c *Client) PostDashboard(dashboard PostDashboardRequest) (GrafanaResponse, *resty.Response, error)

type CustomTime

type CustomTime struct {
	time.Time
}

func (*CustomTime) UnmarshalJSON

func (ct *CustomTime) UnmarshalJSON(b []byte) error

type GetDashboardResponse

type GetDashboardResponse struct {
	Meta      map[string]interface{} `json:"meta"`
	Dashboard *dashboard.Dashboard   `json:"dashboard"`
}

type GrafanaResponse

type GrafanaResponse struct {
	ID      *uint   `json:"id"`
	OrgID   *uint   `json:"orgId"`
	Message *string `json:"message"`
	Slug    *string `json:"slug"`
	Version *int    `json:"version"`
	Status  *string `json:"status"`
	UID     *string `json:"uid"`
	URL     *string `json:"url"`
}

nolint:revive

type PostAnnotation

type PostAnnotation struct {
	DashboardID  *int
	PanelID      *int
	DashboardUID string
	Time         *time.Time
	TimeEnd      *time.Time
	Tags         []string
	Text         string
}

type PostAnnotationResponse

type PostAnnotationResponse struct {
	Message string `json:"message"`
	ID      int64  `json:"id"`
}

type PostDashboardRequest

type PostDashboardRequest struct {
	Dashboard interface{} `json:"dashboard"`
	FolderID  int         `json:"folderId"`
	Overwrite bool        `json:"overwrite"`
}

type ProvisionedAlertRule

type ProvisionedAlertRule struct {
	ID           int64             `json:"id"`
	UID          string            `json:"uid"`
	FolderUID    string            `json:"folderUID"`
	Title        string            `json:"title"`
	Data         []interface{}     `json:"data"`
	ExecErrState string            `json:"execErrState"`
	Labels       map[string]string `json:"labels"`
	RuleGroup    string            `json:"ruleGroup"`
	UpdatedAt    time.Time         `json:"updated"`
	Annotations  map[string]string `json:"annotations"`
}

func (ProvisionedAlertRule) String

func (p ProvisionedAlertRule) String() string

Jump to

Keyboard shortcuts

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