123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- package http
- import (
- "encoding/json"
- "go-common/app/admin/main/videoup/model/monitor"
- "go-common/library/ecode"
- "go-common/library/log"
- bm "go-common/library/net/http/blademaster"
- )
- // monitorRuleResult 获取监控规则的监控结果
- func monitorRuleResult(c *bm.Context) {
- var (
- err error
- res []*monitor.RuleResultData
- p = &monitor.RuleResultParams{}
- )
- if err = c.Bind(p); err != nil {
- return
- }
- if p == nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if p.Type == 0 || p.Business == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if res, err = vdaSvc.MonitorResult(c, p); err != nil {
- log.Error("vdaSvc.MonitorResult(%v) error(%v)", p, err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- c.JSON(res, nil)
- }
- // monitorRuleUpdate 更新/添加监控规则
- func monitorRuleUpdate(c *bm.Context) {
- var (
- err error
- p = new(struct {
- Rule string `form:"rule" validate:"required"`
- })
- rule = &monitor.Rule{}
- )
- if err = c.Bind(p); err != nil {
- log.Error("c.Bind(%v) error(%v)", p, err)
- return
- }
- if p == nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if err = json.Unmarshal([]byte(p.Rule), rule); err != nil {
- log.Error("json.Unmarshal(%s) error(%v)", p.Rule, err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if rule.Type == 0 || rule.Business == 0 || rule.RuleConf == nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- UID, _ := getUIDName(c)
- rule.UID = UID
- if err = vdaSvc.MonitorRuleUpdate(c, rule); err != nil {
- log.Error("vdaSvc.MonitorRuleUpdate(%v) error(%v)", rule, err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- c.JSON(nil, nil)
- }
- func monitorRuleResultOids(c *bm.Context) {
- var (
- err error
- p = new(struct {
- Type int8 `form:"type" validate:"required"`
- Business int8 `form:"business" validate:"required"`
- ID int64 `form:"id" validate:"required"`
- })
- total int
- oidMap map[int64]int
- )
- if err = c.Bind(p); err != nil {
- log.Error("c.Bind(%v) error(%v)", p, err)
- return
- }
- if p.Type == 0 || p.Business == 0 || p.ID == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if total, oidMap, _, err = vdaSvc.MoniStayOids(c, p.Type, p.Business, p.ID); err != nil {
- log.Error("vdaSvc.MoniStatsOids(%v) error(%v)", p, err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- r := new(struct {
- Total int `json:"total"`
- Oids map[int64]int `json:"oids"`
- })
- r.Total = total
- r.Oids = oidMap
- c.JSON(r, nil)
- }
- func monitorNotify(c *bm.Context) {
- var (
- err error
- res []*monitor.RuleResultData
- )
- if res, err = vdaSvc.MonitorNotifyResult(c); err != nil {
- log.Error("vdaSvc.MonitorNotifyResult() error(%v)", err)
- c.JSON(nil, ecode.RequestErr)
- return
- }
- c.JSON(res, nil)
- }
|