Documentation
¶
Index ¶
- func FormatAlertsTable(alerts []Annotation) string
- type Alert
- type AlertGroupsResponse
- type AlertManagerClient
- type AlertRulerClient
- type Annotation
- type AnnotationsQueryParams
- type Client
- func (c *Client) DeleteAnnotation(annotationID int64) (*resty.Response, error)
- func (c *Client) GetAlertRulesForDashboardID(dashboardID string) ([]ProvisionedAlertRule, error)
- func (c *Client) GetAlertsRules() ([]ProvisionedAlertRule, *resty.Response, error)
- func (c *Client) GetAnnotations(params AnnotationsQueryParams) ([]Annotation, *resty.Response, error)
- func (c *Client) GetDashboard(uid string) (GetDashboardResponse, *resty.Response, error)
- func (c *Client) GetDatasources() (map[string]string, *resty.Response, error)
- func (c *Client) PostAnnotation(annotation PostAnnotation) (PostAnnotationResponse, *resty.Response, error)
- func (c *Client) PostDashboard(dashboard PostDashboardRequest) (GrafanaResponse, *resty.Response, error)
- type CustomTime
- type GetDashboardResponse
- type GrafanaResponse
- type PostAnnotation
- type PostAnnotationResponse
- type PostDashboardRequest
- type ProvisionedAlertRule
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatAlertsTable ¶
func FormatAlertsTable(alerts []Annotation) string
FormatAlertsTable formats a slice of alerts into a tabular string representation. It provides a clear overview of alert states, including timestamps and IDs, making it useful for logging or displaying alert information in a structured format.
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)
GetAlertGroups retrieves the alert groups from the AlertManager API. It returns a slice of AlertGroupsResponse, the HTTP response, and any error encountered. This function is useful for monitoring and managing alert configurations.
func (*AlertManagerClient) GetAlterManagerAlerts ¶
func (g *AlertManagerClient) GetAlterManagerAlerts() ([]interface{}, *resty.Response, error)
GetAlterManagerAlerts retrieves alerts from the AlertManager API. It returns a slice of alerts, the HTTP response, and any error encountered.
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
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 Client ¶
type Client struct {
AlertManager *AlertManagerClient
AlertRuler *AlertRulerClient
// contains filtered or unexported fields
}
func NewGrafanaClient ¶
NewGrafanaClient initializes a new Grafana client with the specified URL and API key. It sets up the necessary headers and configurations for making API requests to Grafana, providing access to AlertManager and AlertRuler functionalities.
func (*Client) DeleteAnnotation ¶
DeleteAnnotation removes an annotation identified by its ID from the server. It returns the response from the server and any error encountered during the request.
func (*Client) GetAlertRulesForDashboardID ¶
func (c *Client) GetAlertRulesForDashboardID(dashboardID string) ([]ProvisionedAlertRule, error)
GetAlertRulesForDashboardID retrieves all provisioned alert rules associated with a specific dashboard ID. It returns a slice of ProvisionedAlertRule and any error encountered during the process.
func (*Client) GetAlertsRules ¶
func (c *Client) GetAlertsRules() ([]ProvisionedAlertRule, *resty.Response, error)
GetAlertsRules retrieves all provisioned alert rules from the API. It returns a slice of ProvisionedAlertRule, the HTTP response, and any error encountered.
func (*Client) GetAnnotations ¶
func (c *Client) GetAnnotations(params AnnotationsQueryParams) ([]Annotation, *resty.Response, error)
GetAnnotations retrieves a list of annotations based on specified query parameters. It allows filtering by alert ID, dashboard ID, type, and time range, ensuring both From and To are set. This function is useful for fetching relevant annotations in a Grafana context.
func (*Client) GetDashboard ¶
func (c *Client) GetDashboard(uid string) (GetDashboardResponse, *resty.Response, error)
GetDashboard retrieves the dashboard associated with the given unique identifier (uid). It returns the dashboard data, the HTTP response, and any error encountered during the request.
func (*Client) GetDatasources ¶
GetDatasources retrieves a map of datasource names to their unique identifiers from the API. It also identifies the default datasource, if available, and includes it in the returned map. This function is useful for applications needing to interact with various datasources dynamically.
func (*Client) PostAnnotation ¶
func (c *Client) PostAnnotation(annotation PostAnnotation) (PostAnnotationResponse, *resty.Response, error)
PostAnnotation sends a new annotation to a specified dashboard, allowing users to add notes or comments. It returns the response containing the annotation details, the HTTP response, and any error encountered.
func (*Client) PostDashboard ¶
func (c *Client) PostDashboard(dashboard PostDashboardRequest) (GrafanaResponse, *resty.Response, error)
PostDashboard sends a request to create or update a Grafana dashboard. It returns the response containing the dashboard details, the HTTP response, and any error encountered during the request. This function is useful for programmatically managing Grafana dashboards.
type CustomTime ¶
func (*CustomTime) UnmarshalJSON ¶
func (ct *CustomTime) UnmarshalJSON(b []byte) error
UnmarshalJSON parses the JSON-encoded data and sets the CustomTime's value. It expects the data to represent a timestamp in milliseconds since the epoch. This function is useful for decoding JSON data into a CustomTime type.
type GetDashboardResponse ¶
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 PostAnnotationResponse ¶
type PostDashboardRequest ¶
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
String returns a formatted string representation of the ProvisionedAlertRule, including its ID, UID, title, labels, annotations, and other relevant details. This function is useful for logging and debugging purposes, providing a clear overview of the alert rule's properties.