domain.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package routes
  2. import (
  3. "net/http"
  4. "github.com/710leo/urlooker/modules/web/g"
  5. "github.com/710leo/urlooker/modules/web/http/errors"
  6. "github.com/710leo/urlooker/modules/web/http/param"
  7. "github.com/710leo/urlooker/modules/web/http/render"
  8. "github.com/710leo/urlooker/modules/web/model"
  9. "github.com/710leo/urlooker/modules/web/utils"
  10. )
  11. type Url struct {
  12. Ip string `json:"ip"` //agent所在机器的ip
  13. Status []*model.ItemStatus `json:"status"`
  14. }
  15. func UrlStatus(w http.ResponseWriter, r *http.Request) {
  16. sid := param.MustInt64(r, "id")
  17. sidIpIndex, err := model.RelSidIpRepo.GetBySid(sid)
  18. errors.MaybePanic(err)
  19. urlArr := make([]Url, 0)
  20. idx := 0
  21. var ts int64 = 0
  22. for i, index := range sidIpIndex {
  23. url := Url{
  24. Ip: "agent-" + index.Ip,
  25. }
  26. url.Status, err = model.ItemStatusRepo.GetByIpAndSid(index.Ip, index.Sid)
  27. errors.MaybePanic(err)
  28. if len(url.Status) > 0 && ts < url.Status[len(url.Status)-1].PushTime {
  29. ts = url.Status[len(url.Status)-1].PushTime
  30. idx = i
  31. }
  32. urlArr = append(urlArr, url)
  33. }
  34. //绘图使用,时间轴
  35. var timeData []string
  36. if len(urlArr) > 0 {
  37. for _, item := range urlArr[idx].Status {
  38. t := utils.TimeFormat(item.PushTime)
  39. timeData = append(timeData, t)
  40. }
  41. }
  42. events, err := model.EventRepo.GetByStrategyId(sid, g.Config.ShowDurationMin*60)
  43. errors.MaybePanic(err)
  44. strategy, err := model.GetStrategyById(sid)
  45. errors.MaybePanic(err)
  46. render.Put(r, "AlarmOn", g.Config.Alarm.Enable)
  47. render.Put(r, "TimeData", timeData)
  48. render.Put(r, "Id", sid)
  49. render.Put(r, "Url", strategy.Url)
  50. render.Put(r, "Events", events)
  51. render.Put(r, "Data", urlArr)
  52. render.HTML(r, w, "chart/index")
  53. }