Skip to content

Commit a551c69

Browse files
author
‘niuerzhuang’
committed
feature: allow data report
1 parent 1ce229f commit a551c69

File tree

2 files changed

+17
-36
lines changed

2 files changed

+17
-36
lines changed

dongtai-agent/src/main/java/io/dongtai/iast/agent/monitor/impl/AgentStateMonitor.java

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,33 +50,26 @@ public void check() {
5050
return;
5151
}
5252

53-
Map<String, String> stringStringMap = checkExpectState();
53+
Map<String, Object> stringStringMap = checkExpectState();
5454
// 默认值
5555
String expectState = "other";
56-
String allowReport = "1";
56+
boolean allowReport = true;
5757

5858
if (stringStringMap != null) {
59-
expectState = stringStringMap.get("exceptRunningStatus");
60-
allowReport = stringStringMap.get("isAllowDateReport");
61-
if ("null".equals(allowReport)){
62-
allowReport = "1";
59+
expectState = stringStringMap.get("exceptRunningStatus").toString();
60+
if (null != stringStringMap.get("isAllowDateReport")) {
61+
allowReport = (boolean) stringStringMap.get("isAllowDateReport");
6362
}
6463
}
6564

66-
if (!agentState.isAllowReport(allowReport)) {
67-
if (null == agentState.getAllowReport()) {
68-
DongTaiLog.info("engine is not allowed to report data");
69-
agentState.setAllowReport(allowReport);
70-
}
71-
if (!allowReport.equals(agentState.getAllowReport())) {
72-
DongTaiLog.info("engine is not allowed to report data");
73-
agentState.setAllowReport(allowReport);
74-
engineManager.stop();
75-
}
76-
} else if (agentState.isAllowReport(allowReport) && !allowReport.equals(agentState.getAllowReport())) {
65+
if (allowReport && !agentState.isAllowReport()) {
7766
DongTaiLog.info("engine is allowed to report data");
7867
agentState.setAllowReport(allowReport);
7968
engineManager.start();
69+
} else if (!allowReport && agentState.isAllowReport()) {
70+
DongTaiLog.info("engine is not allowed to report data");
71+
agentState.setAllowReport(allowReport);
72+
engineManager.stop();
8073
}
8174

8275
if (!agentState.isFallback() && !agentState.isException() && agentState.isAllowReport() && agentState.isAllowReport()) {
@@ -97,15 +90,15 @@ public void check() {
9790
}
9891
}
9992

100-
private Map<String, String> checkExpectState() {
93+
private Map<String, Object> checkExpectState() {
10194
try {
10295
Map<String, String> parameters = new HashMap<String, String>();
10396
parameters.put("agentId", String.valueOf(AgentRegisterReport.getAgentId()));
10497
String respRaw = HttpClientUtils.sendGet(ApiPath.EXCEPT_ACTION, parameters).toString();
10598
if (!respRaw.isEmpty()) {
10699
JSONObject resp = JSON.parseObject(respRaw);
107100
JSONObject data = (JSONObject) resp.get("data");
108-
Map<String, String> objectObjectHashMap = new HashMap<>(2);
101+
Map<String, Object> objectObjectHashMap = new HashMap<>(2);
109102
String s = data.toJSONString();
110103
objectObjectHashMap = JSON.parseObject(s, Map.class);
111104
return objectObjectHashMap;

dongtai-common/src/main/java/io/dongtai/iast/common/state/AgentState.java

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public class AgentState {
55
private State pendingState;
66
private StateCause cause;
77
private boolean fallback;
8-
private Integer allowReport;
8+
private boolean allowReport = true;
99
private static AgentState INSTANCE;
1010

1111
public static AgentState getInstance() {
@@ -97,23 +97,11 @@ public boolean isFallback() {
9797
return this.fallback;
9898
}
9999

100-
public Boolean isAllowReport(String allowReport) {
101-
if (null == allowReport) {
102-
return true;
103-
} else {
104-
return Integer.valueOf(allowReport).equals(1);
105-
}
106-
}
107-
108-
public Boolean isAllowReport() {
109-
return 1 == this.allowReport;
110-
}
111-
112-
public void setAllowReport(String allowReport) {
113-
this.allowReport = Integer.valueOf(allowReport);
100+
public boolean isAllowReport() {
101+
return this.allowReport;
114102
}
115103

116-
public String getAllowReport() {
117-
return String.valueOf(allowReport);
104+
public void setAllowReport(boolean allowReport) {
105+
this.allowReport = allowReport;
118106
}
119107
}

0 commit comments

Comments
 (0)