apm_white_list.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package containers
  2. import (
  3. "fmt"
  4. "github.com/coroot/coroot-node-agent/common"
  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. //if true {
  11. // return r.getWhiteListAll()
  12. //}
  13. return r.whiteListRules[codeType.WhiteCodeString()]
  14. }
  15. func (r *Registry) setWhiteList(whiteData WhiteData) {
  16. //var openStack int
  17. //if !r.tracer.DisableStackTracing() {
  18. // openStack = 1
  19. //}
  20. whiteListMap := make(WhiteListMap)
  21. for _, scop := range whiteData.Appscope {
  22. code := scop.Code
  23. for _, setting := range scop.Settings {
  24. //setting.OpenStack = openStack
  25. whiteListMap[code] = append(whiteListMap[code], setting)
  26. }
  27. }
  28. r.whiteListRules = whiteListMap
  29. }
  30. func (r *Registry) pullWhiteList() (bool, error) {
  31. if r.isFusing {
  32. return false, nil
  33. }
  34. if common.IsOpenFilter() {
  35. return false, nil
  36. }
  37. //hostId, _ := utils.GetHostID()
  38. //fmt.Println(hostId)
  39. nodeInfo := r.nodeInfo.GetNodeInfo()
  40. if nodeInfo == nil {
  41. return false, fmt.Errorf("could not find node info")
  42. }
  43. whiteListReq := WhiteListReq{
  44. HostId: nodeInfo.HostID,
  45. AccountId: nodeInfo.AccountID,
  46. }
  47. whiteData, err := r.connServer.WhiteList(whiteListReq)
  48. if err != nil {
  49. log.Errorf("report WhiteList info error is %v.", err)
  50. return false, err
  51. }
  52. //fmt.Println(r.whiteLastUpdatedTime)
  53. //fmt.Println(whiteData.LastUpdatedTime)
  54. // 不用更新
  55. if r.whiteLastUpdatedTime >= 0 && r.whiteLastUpdatedTime == whiteData.LastUpdatedTime {
  56. return false, nil
  57. }
  58. // 更新时间
  59. r.whiteLastUpdatedTime = whiteData.LastUpdatedTime
  60. r.setWhiteList(whiteData)
  61. return true, nil
  62. }