Unified Alerting: Validate PostableSilence API. (#46892)

Invalid PostableSilences could be passed to the Alerting API - if they
are passed all the way down into the alertmanager data layer, they can
cause a panic. This change adds validation to avoid a panic in the
alertmanager.
This commit is contained in:
Joe Blubaugh
2022-04-27 15:55:47 +08:00
committed by GitHub
parent 7798b08b1e
commit 103087a1a5
2 changed files with 67 additions and 0 deletions
@@ -9,6 +9,7 @@ import (
"strings"
"time"
"github.com/go-openapi/strfmt"
"github.com/grafana/grafana/pkg/api/response"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
@@ -50,6 +51,12 @@ func (srv AlertmanagerSrv) RouteGetAMStatus(c *models.ReqContext) response.Respo
}
func (srv AlertmanagerSrv) RouteCreateSilence(c *models.ReqContext, postableSilence apimodels.PostableSilence) response.Response {
err := postableSilence.Validate(strfmt.Default)
if err != nil {
srv.log.Error("silence failed validation", "err", err)
return ErrResp(http.StatusBadRequest, err, "silence failed validation")
}
am, errResp := srv.AlertmanagerFor(c.OrgId)
if errResp != nil {
return errResp