monitor.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package http
  2. import (
  3. "encoding/json"
  4. "go-common/app/admin/main/videoup/model/monitor"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. // monitorRuleResult 获取监控规则的监控结果
  10. func monitorRuleResult(c *bm.Context) {
  11. var (
  12. err error
  13. res []*monitor.RuleResultData
  14. p = &monitor.RuleResultParams{}
  15. )
  16. if err = c.Bind(p); err != nil {
  17. return
  18. }
  19. if p == nil {
  20. c.JSON(nil, ecode.RequestErr)
  21. return
  22. }
  23. if p.Type == 0 || p.Business == 0 {
  24. c.JSON(nil, ecode.RequestErr)
  25. return
  26. }
  27. if res, err = vdaSvc.MonitorResult(c, p); err != nil {
  28. log.Error("vdaSvc.MonitorResult(%v) error(%v)", p, err)
  29. c.JSON(nil, ecode.RequestErr)
  30. return
  31. }
  32. c.JSON(res, nil)
  33. }
  34. // monitorRuleUpdate 更新/添加监控规则
  35. func monitorRuleUpdate(c *bm.Context) {
  36. var (
  37. err error
  38. p = new(struct {
  39. Rule string `form:"rule" validate:"required"`
  40. })
  41. rule = &monitor.Rule{}
  42. )
  43. if err = c.Bind(p); err != nil {
  44. log.Error("c.Bind(%v) error(%v)", p, err)
  45. return
  46. }
  47. if p == nil {
  48. c.JSON(nil, ecode.RequestErr)
  49. return
  50. }
  51. if err = json.Unmarshal([]byte(p.Rule), rule); err != nil {
  52. log.Error("json.Unmarshal(%s) error(%v)", p.Rule, err)
  53. c.JSON(nil, ecode.RequestErr)
  54. return
  55. }
  56. if rule.Type == 0 || rule.Business == 0 || rule.RuleConf == nil {
  57. c.JSON(nil, ecode.RequestErr)
  58. return
  59. }
  60. UID, _ := getUIDName(c)
  61. rule.UID = UID
  62. if err = vdaSvc.MonitorRuleUpdate(c, rule); err != nil {
  63. log.Error("vdaSvc.MonitorRuleUpdate(%v) error(%v)", rule, err)
  64. c.JSON(nil, ecode.RequestErr)
  65. return
  66. }
  67. c.JSON(nil, nil)
  68. }
  69. func monitorRuleResultOids(c *bm.Context) {
  70. var (
  71. err error
  72. p = new(struct {
  73. Type int8 `form:"type" validate:"required"`
  74. Business int8 `form:"business" validate:"required"`
  75. ID int64 `form:"id" validate:"required"`
  76. })
  77. total int
  78. oidMap map[int64]int
  79. )
  80. if err = c.Bind(p); err != nil {
  81. log.Error("c.Bind(%v) error(%v)", p, err)
  82. return
  83. }
  84. if p.Type == 0 || p.Business == 0 || p.ID == 0 {
  85. c.JSON(nil, ecode.RequestErr)
  86. return
  87. }
  88. if total, oidMap, _, err = vdaSvc.MoniStayOids(c, p.Type, p.Business, p.ID); err != nil {
  89. log.Error("vdaSvc.MoniStatsOids(%v) error(%v)", p, err)
  90. c.JSON(nil, ecode.RequestErr)
  91. return
  92. }
  93. r := new(struct {
  94. Total int `json:"total"`
  95. Oids map[int64]int `json:"oids"`
  96. })
  97. r.Total = total
  98. r.Oids = oidMap
  99. c.JSON(r, nil)
  100. }
  101. func monitorNotify(c *bm.Context) {
  102. var (
  103. err error
  104. res []*monitor.RuleResultData
  105. )
  106. if res, err = vdaSvc.MonitorNotifyResult(c); err != nil {
  107. log.Error("vdaSvc.MonitorNotifyResult() error(%v)", err)
  108. c.JSON(nil, ecode.RequestErr)
  109. return
  110. }
  111. c.JSON(res, nil)
  112. }