apm_white_list.go 1.4 KB

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