apm_white_list.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 common.IsOpenFilter() {
  32. return false, nil
  33. }
  34. //hostId, _ := utils.GetHostID()
  35. //fmt.Println(hostId)
  36. nodeInfo := r.nodeInfo.GetNodeInfo()
  37. if nodeInfo == nil {
  38. return false, fmt.Errorf("could not find node info")
  39. }
  40. whiteListReq := WhiteListReq{
  41. HostId: nodeInfo.HostID,
  42. AccountId: nodeInfo.AccountID,
  43. }
  44. whiteData, err := r.connServer.WhiteList(whiteListReq)
  45. if err != nil {
  46. log.Errorf("report WhiteList info error is %v.", err)
  47. return false, err
  48. }
  49. //fmt.Println(r.whiteLastUpdatedTime)
  50. //fmt.Println(whiteData.LastUpdatedTime)
  51. // 不用更新
  52. if r.whiteLastUpdatedTime >= 0 && r.whiteLastUpdatedTime == whiteData.LastUpdatedTime {
  53. return false, nil
  54. }
  55. // 更新时间
  56. r.whiteLastUpdatedTime = whiteData.LastUpdatedTime
  57. r.setWhiteList(whiteData)
  58. return true, nil
  59. }