Browse Source

refactor: alert use enabled datasource

tags/v6.0.0-ga12
ning 3 years ago
parent
commit
a2bdeb4f0e
3 changed files with 8 additions and 14 deletions
  1. +1
    -11
      center/router/router_datasource.go
  2. +6
    -2
      models/datasource.go
  3. +1
    -1
      prom/reader.go

+ 1
- 11
center/router/router_datasource.go View File

@@ -15,27 +15,17 @@ type listReq struct {
Name string `json:"name"`
Type string `json:"plugin_type"`
Category string `json:"category"`
Limit int `json:"limit"`
P int `json:"p"`
}

func (rt *Router) datasourceList(c *gin.Context) {
var req listReq
ginx.BindJSON(c, &req)
if req.Limit == 0 {
req.Limit = 10
}
if req.P == 0 {
req.P = 1
}

typ := req.Type
category := req.Category
name := req.Name
limit := req.Limit
p := req.P

list, err := models.GetDatasourcesGetsBy(rt.Ctx, typ, category, name, limit, (p-1)*limit)
list, err := models.GetDatasourcesGetsBy(rt.Ctx, typ, category, name, "")
Render(c, list, err)
}



+ 6
- 2
models/datasource.go View File

@@ -158,7 +158,7 @@ func GetDatasourcesCountBy(ctx *ctx.Context, typ, cate, name string) (int64, err
return Count(session)
}

func GetDatasourcesGetsBy(ctx *ctx.Context, typ, cate, name string, limit, offset int) ([]*Datasource, error) {
func GetDatasourcesGetsBy(ctx *ctx.Context, typ, cate, name, status string) ([]*Datasource, error) {
session := DB(ctx)

if name != "" {
@@ -177,8 +177,12 @@ func GetDatasourcesGetsBy(ctx *ctx.Context, typ, cate, name string, limit, offse
session = session.Where("category = ?", cate)
}

if status != "" {
session = session.Where("status = ?", status)
}

var lst []*Datasource
err := session.Order("id desc").Limit(limit).Offset(offset).Find(&lst).Error
err := session.Order("id desc").Find(&lst).Error
if err == nil {
for i := 0; i < len(lst); i++ {
lst[i].DB2FE()


+ 1
- 1
prom/reader.go View File

@@ -42,7 +42,7 @@ type PromSetting struct {
}

func (pc *PromClientMap) loadFromDatabase() {
datasources, err := models.GetDatasourcesGetsBy(pc.ctx, models.PROMETHEUS, "", "", 1000, 0)
datasources, err := models.GetDatasourcesGetsBy(pc.ctx, models.PROMETHEUS, "", "", "enabled")
if err != nil {
logger.Errorf("failed to get datasources, error: %v", err)
return


Loading…
Cancel
Save