apm_white_list.go 1.4 KB

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