apm_white_list.go 1.5 KB

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