add some api for server cluster bindings
This commit is contained in:
parent
388228a631
commit
c1fec215a9
|
@ -47,6 +47,19 @@ func AlertingEngineGets(where string, args ...interface{}) ([]*AlertingEngines,
|
|||
return objs, err
|
||||
}
|
||||
|
||||
func AlertingEngineGet(where string, args ...interface{}) (*AlertingEngines, error) {
|
||||
lst, err := AlertingEngineGets(where, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(lst) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return lst[0], nil
|
||||
}
|
||||
|
||||
func AlertingEngineGetsInstances(where string, args ...interface{}) ([]string, error) {
|
||||
var arr []string
|
||||
var err error
|
||||
|
|
|
@ -33,6 +33,12 @@ func Init() error {
|
|||
|
||||
func initFromConfig() error {
|
||||
opts := config.C.Reader
|
||||
|
||||
if opts.Url == "" {
|
||||
logger.Warning("reader url is blank")
|
||||
return nil
|
||||
}
|
||||
|
||||
cli, err := api.NewClient(api.Config{
|
||||
Address: opts.Url,
|
||||
RoundTripper: &http.Transport{
|
||||
|
|
|
@ -290,6 +290,9 @@ func configRoute(r *gin.Engine, version string) {
|
|||
pages.POST("/busi-group/:id/tasks", auth(), user(), perm("/job-tasks/add"), bgrw(), taskAdd)
|
||||
pages.GET("/busi-group/:id/task/*url", auth(), user(), perm("/job-tasks"), taskProxy)
|
||||
pages.PUT("/busi-group/:id/task/*url", auth(), user(), perm("/job-tasks/put"), bgrw(), taskProxy)
|
||||
|
||||
pages.GET("/servers", auth(), admin(), serversGet)
|
||||
pages.PUT("/server/:id", auth(), admin(), serverBindCluster)
|
||||
}
|
||||
|
||||
service := r.Group("/v1/n9e")
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package router
|
||||
|
||||
import (
|
||||
"github.com/didi/nightingale/v5/src/models"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/toolkits/pkg/ginx"
|
||||
)
|
||||
|
||||
// 页面上,拉取 server 列表
|
||||
func serversGet(c *gin.Context) {
|
||||
list, err := models.AlertingEngineGets("")
|
||||
ginx.NewRender(c).Data(list, err)
|
||||
}
|
||||
|
||||
type serverBindClusterForm struct {
|
||||
Cluster string `json:"cluster"`
|
||||
}
|
||||
|
||||
// 用户为某个 n9e-server 分配一个集群,也可以清空,设置cluster为空字符串即可
|
||||
// 清空就表示这个server没啥用了,可能是要下线掉,或者仅仅用作转发器
|
||||
func serverBindCluster(c *gin.Context) {
|
||||
id := ginx.UrlParamInt64(c, "id")
|
||||
|
||||
ae, err := models.AlertingEngineGet("id = ?", id)
|
||||
ginx.Dangerous(err)
|
||||
|
||||
if ae == nil {
|
||||
ginx.Dangerous("no such server")
|
||||
}
|
||||
|
||||
var f serverBindClusterForm
|
||||
ginx.BindJSON(c, &f)
|
||||
|
||||
ginx.NewRender(c).Message(ae.UpdateCluster(f.Cluster))
|
||||
}
|
Loading…
Reference in New Issue