apm_white_list.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package containers
  2. import (
  3. "github.com/coroot/coroot-node-agent/common"
  4. "github.com/coroot/coroot-node-agent/utils"
  5. . "github.com/coroot/coroot-node-agent/utils/modelse"
  6. log "github.com/sirupsen/logrus"
  7. )
  8. type WhiteListMap map[string][]WhiteSettingInfo
  9. func (r *Registry) getWhiteListByCodeType(codeType CodeType) []WhiteSettingInfo {
  10. return r.whiteListRules[codeType.WhiteCodeString()]
  11. }
  12. func (r *Registry) setWhiteList(whiteData WhiteData) {
  13. whiteListMap := make(WhiteListMap)
  14. for _, scop := range whiteData.Appscope {
  15. code := scop.Code
  16. for _, setting := range scop.Settings {
  17. whiteListMap[code] = append(whiteListMap[code], setting)
  18. }
  19. }
  20. r.whiteListRules = whiteListMap
  21. }
  22. func (r *Registry) getWhiteList() (bool, error) {
  23. if common.IsOpenFilter() {
  24. return false, nil
  25. }
  26. //hostId, _ := utils.GetHostID()
  27. //fmt.Println(hostId)
  28. whiteListReq := WhiteListReq{
  29. HostId: 10154813500555812,
  30. AccountId: utils.GetAccountID(),
  31. }
  32. whiteData, err := r.connServer.WhiteList(whiteListReq)
  33. if err != nil {
  34. log.Errorf("report WhiteList info error is %v.", err)
  35. return false, err
  36. }
  37. //fmt.Println(r.whiteLastUpdatedTime)
  38. //fmt.Println(whiteData.LastUpdatedTime)
  39. // 不用更新
  40. if r.whiteLastUpdatedTime >= 0 && r.whiteLastUpdatedTime == whiteData.LastUpdatedTime {
  41. return false, nil
  42. }
  43. // 更新时间
  44. r.whiteLastUpdatedTime = whiteData.LastUpdatedTime
  45. r.setWhiteList(whiteData)
  46. return true, nil
  47. }