Add alerts endpoint to API client (#552)
Add alerts endpoint to API client. The alerts endpoint returns a list of all active alerts. Signed-off-by: Roald Nefs <info@roaldnefs.com>
This commit is contained in:
parent
fa4aa9000d
commit
7490f0a745
|
@ -35,6 +35,7 @@ const (
|
||||||
|
|
||||||
apiPrefix = "/api/v1"
|
apiPrefix = "/api/v1"
|
||||||
|
|
||||||
|
epAlerts = apiPrefix + "/alerts"
|
||||||
epAlertManagers = apiPrefix + "/alertmanagers"
|
epAlertManagers = apiPrefix + "/alertmanagers"
|
||||||
epQuery = apiPrefix + "/query"
|
epQuery = apiPrefix + "/query"
|
||||||
epQueryRange = apiPrefix + "/query_range"
|
epQueryRange = apiPrefix + "/query_range"
|
||||||
|
@ -115,6 +116,8 @@ type Range struct {
|
||||||
|
|
||||||
// API provides bindings for Prometheus's v1 API.
|
// API provides bindings for Prometheus's v1 API.
|
||||||
type API interface {
|
type API interface {
|
||||||
|
// Alerts returns a list of all active alerts.
|
||||||
|
Alerts(ctx context.Context) (AlertsResult, error)
|
||||||
// AlertManagers returns an overview of the current state of the Prometheus alert manager discovery.
|
// AlertManagers returns an overview of the current state of the Prometheus alert manager discovery.
|
||||||
AlertManagers(ctx context.Context) (AlertManagersResult, error)
|
AlertManagers(ctx context.Context) (AlertManagersResult, error)
|
||||||
// CleanTombstones removes the deleted data from disk and cleans up the existing tombstones.
|
// CleanTombstones removes the deleted data from disk and cleans up the existing tombstones.
|
||||||
|
@ -142,6 +145,11 @@ type API interface {
|
||||||
Targets(ctx context.Context) (TargetsResult, error)
|
Targets(ctx context.Context) (TargetsResult, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AlertsResult contains the result from querying the alerts endpoint.
|
||||||
|
type AlertsResult struct {
|
||||||
|
Alerts []Alert `json:"alerts"`
|
||||||
|
}
|
||||||
|
|
||||||
// AlertManagersResult contains the result from querying the alertmanagers endpoint.
|
// AlertManagersResult contains the result from querying the alertmanagers endpoint.
|
||||||
type AlertManagersResult struct {
|
type AlertManagersResult struct {
|
||||||
Active []AlertManager `json:"activeAlertManagers"`
|
Active []AlertManager `json:"activeAlertManagers"`
|
||||||
|
@ -402,6 +410,24 @@ type httpAPI struct {
|
||||||
client api.Client
|
client api.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *httpAPI) Alerts(ctx context.Context) (AlertsResult, error) {
|
||||||
|
u := h.client.URL(epAlerts, nil)
|
||||||
|
|
||||||
|
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
|
||||||
|
if err != nil {
|
||||||
|
return AlertsResult{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, body, err := h.client.Do(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
return AlertsResult{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var res AlertsResult
|
||||||
|
err = json.Unmarshal(body, &res)
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
func (h *httpAPI) AlertManagers(ctx context.Context) (AlertManagersResult, error) {
|
func (h *httpAPI) AlertManagers(ctx context.Context) (AlertManagersResult, error) {
|
||||||
u := h.client.URL(epAlertManagers, nil)
|
u := h.client.URL(epAlertManagers, nil)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue