mirror of
https://github.com/prometheus/alertmanager
synced 2025-01-13 17:43:26 +00:00
Implement basic /alerts endpoint
This commit is contained in:
parent
ff7eddc453
commit
8237c0c567
32
api.go
32
api.go
@ -74,15 +74,29 @@ func (e *apiError) Error() string {
|
||||
}
|
||||
|
||||
func (api *API) listAlerts(w http.ResponseWriter, r *http.Request) {
|
||||
// alerts, err := api.alerts.GetAll()
|
||||
// if err != nil {
|
||||
// respondError(w, apiError{
|
||||
// typ: errorBadData,
|
||||
// err: err,
|
||||
// }, nil)
|
||||
// return
|
||||
// }
|
||||
// respond(w, alerts)
|
||||
alerts := api.alerts.GetPending()
|
||||
defer alerts.Close()
|
||||
|
||||
var (
|
||||
err error
|
||||
res []*types.Alert
|
||||
)
|
||||
// TODO(fabxc): enforce a sensible timeout.
|
||||
for a := range alerts.Next() {
|
||||
if err = alerts.Err(); err != nil {
|
||||
break
|
||||
}
|
||||
res = append(res, a)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
respondError(w, apiError{
|
||||
typ: errorBadData,
|
||||
err: err,
|
||||
}, nil)
|
||||
return
|
||||
}
|
||||
respond(w, types.Alerts(res...))
|
||||
}
|
||||
|
||||
func (api *API) addAlerts(w http.ResponseWriter, r *http.Request) {
|
||||
|
Loading…
Reference in New Issue
Block a user