Rainbond/monitor/api/controller/rules.go

30 lines
645 B
Go
Raw Normal View History

2018-07-31 14:26:47 +08:00
package controller
import (
"net/http"
"io/ioutil"
httputil "github.com/goodrain/rainbond/util/http"
"github.com/Sirupsen/logrus"
"gopkg.in/yaml.v2"
"github.com/goodrain/rainbond/monitor/prometheus"
)
func AddRules(w http.ResponseWriter, r *http.Request) {
in, err := ioutil.ReadAll(r.Body)
if err != nil {
httputil.ReturnError(r, w, 400, err.Error())
return
}
var RulesConfig prometheus.AlertingNameConfig
if err := yaml.Unmarshal(in, &RulesConfig); err != nil {
logrus.Error("Unmarshal prometheus alerting rules config string to object error.", err.Error())
httputil.ReturnError(r, w, 400, err.Error())
return
}
}