|
|
@@ -3,7 +3,9 @@ package containers
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
+ "time"
|
|
|
"github.com/coroot/coroot-node-agent/common"
|
|
|
+ "github.com/coroot/coroot-node-agent/config"
|
|
|
"github.com/coroot/coroot-node-agent/utils"
|
|
|
. "github.com/coroot/coroot-node-agent/utils/modelse"
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
@@ -32,6 +34,15 @@ func (r *Registry) pullWhiteListV2() (bool, error) {
|
|
|
if common.IsOpenFilter() {
|
|
|
return false, nil
|
|
|
}
|
|
|
+
|
|
|
+ // 若配置文件中存在 agent.rules,则直接使用,不走接口
|
|
|
+ if agentRules := config.Get().AgentRules(); len(agentRules) > 0 {
|
|
|
+ whiteData := buildWhiteDataFromAgentRules(agentRules)
|
|
|
+ r.setWhiteListV2(whiteData)
|
|
|
+ saveRule(whiteData)
|
|
|
+ return true, nil
|
|
|
+ }
|
|
|
+
|
|
|
nodeInfo := r.nodeInfo.GetNodeInfo()
|
|
|
if nodeInfo == nil {
|
|
|
return false, fmt.Errorf("could not find node info")
|
|
|
@@ -64,6 +75,17 @@ func (r *Registry) pullWhiteListV2() (bool, error) {
|
|
|
return true, nil
|
|
|
}
|
|
|
|
|
|
+func buildWhiteDataFromAgentRules(rules []config.AgentRule) WhiteDataV2 {
|
|
|
+ var settings []WhiteSettingInfo
|
|
|
+ for _, rule := range rules {
|
|
|
+ settings = append(settings, WhiteSettingInfo{
|
|
|
+ AppName: rule.AppName,
|
|
|
+ ProcessKey: rule.Filters,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return WhiteDataV2{SettingList: settings, LastUpdatedTime: int(time.Now().Unix())}
|
|
|
+}
|
|
|
+
|
|
|
func saveRule(runtimeApps WhiteDataV2) {
|
|
|
appStr, _ := json.Marshal(runtimeApps)
|
|
|
dumpPath := path.Join(utils.GetDefaultRuntimePath(), "memdump")
|