Alerting: Implement /status for the notification system (#33227)
* Alerting: Implement /status for the notification system Implements the necessary plumbing to have a /status endpoint on the notification system. * Add API examples * Update API specs * Update prometheus/common dependency Co-authored-by: Sofia Papagiannaki <sofia@grafana.com>
This commit is contained in:
co-authored by
Sofia Papagiannaki
parent
283572fcbc
commit
f7ed35336d
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/pkg/errors"
|
||||
amv2 "github.com/prometheus/alertmanager/api/v2/models"
|
||||
"github.com/prometheus/alertmanager/config"
|
||||
@@ -40,6 +41,14 @@ import (
|
||||
// 200: Ack
|
||||
// 400: ValidationError
|
||||
|
||||
// swagger:route GET /api/alertmanager/{Recipient}/api/v2/status alertmanager RouteGetAMStatus
|
||||
//
|
||||
// get alertmanager status and configuration
|
||||
//
|
||||
// Responses:
|
||||
// 200: GettableStatus
|
||||
// 400: ValidationError
|
||||
|
||||
// swagger:route GET /api/alertmanager/{Recipient}/api/v2/alerts alertmanager RouteGetAMAlerts
|
||||
//
|
||||
// get alertmanager alerts
|
||||
@@ -114,6 +123,79 @@ type GetSilencesParams struct {
|
||||
Filter []string `json:"filter"`
|
||||
}
|
||||
|
||||
// swagger:model
|
||||
type GettableStatus struct {
|
||||
// cluster
|
||||
// Required: true
|
||||
Cluster *amv2.ClusterStatus `json:"cluster"`
|
||||
|
||||
// config
|
||||
// Required: true
|
||||
Config *PostableApiAlertingConfig `json:"config"`
|
||||
|
||||
// uptime
|
||||
// Required: true
|
||||
// Format: date-time
|
||||
Uptime *strfmt.DateTime `json:"uptime"`
|
||||
|
||||
// version info
|
||||
// Required: true
|
||||
VersionInfo *amv2.VersionInfo `json:"versionInfo"`
|
||||
}
|
||||
|
||||
func (s *GettableStatus) UnmarshalJSON(b []byte) error {
|
||||
amStatus := amv2.AlertmanagerStatus{}
|
||||
if err := json.Unmarshal(b, &amStatus); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c := config.Config{}
|
||||
if err := yaml.Unmarshal([]byte(*amStatus.Config.Original), &c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s.Cluster = amStatus.Cluster
|
||||
s.Config = &PostableApiAlertingConfig{Config: Config{
|
||||
Global: c.Global,
|
||||
Route: c.Route,
|
||||
InhibitRules: c.InhibitRules,
|
||||
Templates: c.Templates,
|
||||
}}
|
||||
s.Uptime = amStatus.Uptime
|
||||
s.VersionInfo = amStatus.VersionInfo
|
||||
|
||||
type overrides struct {
|
||||
Receivers *[]*PostableApiReceiver `yaml:"receivers,omitempty" json:"receivers,omitempty"`
|
||||
}
|
||||
|
||||
if err := yaml.Unmarshal([]byte(*amStatus.Config.Original), &overrides{Receivers: &s.Config.Receivers}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewGettableStatus(cfg *PostableApiAlertingConfig) *GettableStatus {
|
||||
// In Grafana, the only field we support is Config.
|
||||
cs := amv2.ClusterStatusStatusDisabled
|
||||
na := "N/A"
|
||||
return &GettableStatus{
|
||||
Cluster: &amv2.ClusterStatus{
|
||||
Status: &cs,
|
||||
Peers: []*amv2.PeerStatus{},
|
||||
},
|
||||
VersionInfo: &amv2.VersionInfo{
|
||||
Branch: &na,
|
||||
BuildDate: &na,
|
||||
BuildUser: &na,
|
||||
GoVersion: &na,
|
||||
Revision: &na,
|
||||
Version: &na,
|
||||
},
|
||||
Config: cfg,
|
||||
}
|
||||
}
|
||||
|
||||
// swagger:model
|
||||
type PostableSilence = amv2.PostableSilence
|
||||
|
||||
@@ -183,7 +265,7 @@ type BodyAlertingConfig struct {
|
||||
}
|
||||
|
||||
// alertmanager routes
|
||||
// swagger:parameters RoutePostAlertingConfig RouteGetAlertingConfig RouteDeleteAlertingConfig RouteGetAMAlerts RoutePostAMAlerts RouteGetAMAlertGroups RouteGetSilences RouteCreateSilence RouteGetSilence RouteDeleteSilence RoutePostAlertingConfig
|
||||
// swagger:parameters RoutePostAlertingConfig RouteGetAlertingConfig RouteDeleteAlertingConfig RouteGetAMStatus RouteGetAMAlerts RoutePostAMAlerts RouteGetAMAlertGroups RouteGetSilences RouteCreateSilence RouteGetSilence RouteDeleteSilence RoutePostAlertingConfig
|
||||
// ruler routes
|
||||
// swagger:parameters RouteGetRulesConfig RoutePostNameRulesConfig RouteGetNamespaceRulesConfig RouteDeleteNamespaceRulesConfig RouteGetRulegGroupConfig RouteDeleteRuleGroupConfig
|
||||
// prom routes
|
||||
|
||||
Reference in New Issue
Block a user