falcon-plus icon indicating copy to clipboard operation
falcon-plus copied to clipboard

API 获取events时step未赋值

Open libailin opened this issue 6 years ago • 1 comments

1、接口文档描述错误: 接口文档地址:http://open-falcon.org/falcon-plus/?#/alarm_events_create 接口文档里描述的是create events,然而这个接口/api/v1/alarm/events是获取列表

2、接口返回的数据未赋值 接口地址:/api/v1/alarm/events 获取的数据

[
    {
        "id": 108,
        "event_caseId": "s_4_179e0112cf7a91201142ab8fe9c7c7d5",
        "step": 0,   #在源代码里面未赋值,一直返回的是0
        "cond": "0 > 0",
        "status": 1,
        "timestamp": "2018-12-07T10:11:30+08:00"
    }
]

修复方案: 文件位置:/modules/api/app/controller/alarm/alarm_events_controller.go

func EventsGet(c *gin.Context) {
	var inputs APIEventsGetInputs
	inputs.Status = -1
	if err := c.Bind(&inputs); err != nil {
		h.JSONR(c, badstatus, err)
		return
	}
	filterCollector := inputs.collectFilters()
	//for get correct table name
	f := alm.Events{}
	evens := []alm.Events{}
	if inputs.Limit == 0 || inputs.Limit >= 50 {
		inputs.Limit = 50
	}
        //修改begin:sql里未查询该字段,增加step字段即可
	perparedSql := fmt.Sprintf("select id, event_caseId, cond, status, timestamp,step from %s %s order by timestamp DESC limit %d,%d", f.TableName(), filterCollector, inputs.Page, inputs.Limit)
       //修改end====================================
	db.Alarm.Raw(perparedSql).Scan(&evens)
	h.JSONR(c, evens)
}

libailin avatar Dec 07 '18 05:12 libailin

@libailin 欢迎提交 pr 👍

laiwei avatar Dec 27 '18 03:12 laiwei