diff --git a/newrelic-security-agent/src/main/java/com/newrelic/agent/security/AgentInfo.java b/newrelic-security-agent/src/main/java/com/newrelic/agent/security/AgentInfo.java index 596ce452f..d69276b45 100644 --- a/newrelic-security-agent/src/main/java/com/newrelic/agent/security/AgentInfo.java +++ b/newrelic-security-agent/src/main/java/com/newrelic/agent/security/AgentInfo.java @@ -5,7 +5,6 @@ import com.newrelic.agent.security.instrumentator.utils.ApplicationInfoUtils; import com.newrelic.agent.security.instrumentator.utils.INRSettingsKey; import com.newrelic.agent.security.intcodeagent.filelogging.FileLoggerThreadPool; -import com.newrelic.api.agent.security.utils.logging.LogLevel; import com.newrelic.agent.security.intcodeagent.models.collectorconfig.CollectorConfig; import com.newrelic.agent.security.intcodeagent.models.javaagent.ApplicationInfoBean; import com.newrelic.agent.security.intcodeagent.models.javaagent.Identifier; @@ -13,6 +12,7 @@ import com.newrelic.agent.security.intcodeagent.properties.BuildInfo; import com.newrelic.agent.security.intcodeagent.websocket.WSUtils; import com.newrelic.api.agent.security.instrumentation.helpers.GrpcClientRequestReplayHelper; +import com.newrelic.api.agent.security.utils.logging.LogLevel; import org.apache.commons.lang3.StringUtils; import java.io.File; @@ -68,7 +68,7 @@ public static AgentInfo getInstance(){ } public void initialiseHC(){ - jaHealthCheck = new JAHealthCheck(applicationUUID); + jaHealthCheck = new JAHealthCheck(); } public ApplicationInfoBean getApplicationInfo() { diff --git a/newrelic-security-agent/src/main/java/com/newrelic/agent/security/intcodeagent/models/javaagent/JAHealthCheck.java b/newrelic-security-agent/src/main/java/com/newrelic/agent/security/intcodeagent/models/javaagent/JAHealthCheck.java index cd926be52..ac19e2e48 100644 --- a/newrelic-security-agent/src/main/java/com/newrelic/agent/security/intcodeagent/models/javaagent/JAHealthCheck.java +++ b/newrelic-security-agent/src/main/java/com/newrelic/agent/security/intcodeagent/models/javaagent/JAHealthCheck.java @@ -31,11 +31,11 @@ public class JAHealthCheck extends AgentBasicInfo { private Boolean scanActive = false; - private AtomicInteger invokedHookCount; + private final AtomicInteger invokedHookCount; private IdentifierEnvs kind; - private EventStats eventStats; + private final EventStats eventStats; private ThreadPoolStats threadPoolStats; @@ -49,8 +49,9 @@ public class JAHealthCheck extends AgentBasicInfo { private SchedulerRuns schedulerRuns = new SchedulerRuns(); + private String iastTestIdentifier; - public JAHealthCheck(String applicationUUID) { + public JAHealthCheck() { super(); this.invokedHookCount = new AtomicInteger(0); this.threadPoolStats = new ThreadPoolStats(); @@ -59,6 +60,7 @@ public JAHealthCheck(String applicationUUID) { this.eventStats = new EventStats(); this.setKind(AgentInfo.getInstance().getApplicationInfo().getIdentifier().getKind()); this.procStartTime = ManagementFactory.getRuntimeMXBean().getStartTime(); + this.iastTestIdentifier = AgentConfig.getInstance().getScanControllers().getIastTestIdentifier(); if(AgentConfig.getInstance().getAgentMode().getScanSchedule().getNextScanTime() != null) { this.csecActivationTime = AgentConfig.getInstance().getAgentMode().getScanSchedule().getNextScanTime().getTime(); } else { @@ -90,6 +92,7 @@ public JAHealthCheck(JAHealthCheck jaHealthCheck) { this.csecActivationTime = jaHealthCheck.getCsecActivationTime(); this.iastDataRequestTime = jaHealthCheck.getIastDataRequestTime(); this.scanActive = jaHealthCheck.getScanActive(); + this.iastTestIdentifier = jaHealthCheck.getIastTestIdentifier(); logger.log(LogLevel.INFO, String.format(HC_CREATED, JsonConverter.toJSON(this)), JAHealthCheck.class.getName()); } @@ -212,6 +215,14 @@ public long getIastDataRequestTime() { return iastDataRequestTime; } + public String getIastTestIdentifier() { + return iastTestIdentifier; + } + + public void setIastTestIdentifier(String iastTestIdentifier) { + this.iastTestIdentifier = iastTestIdentifier; + } + public void reset(){ this.setInvokedHookCount(0); this.stats.clear(); diff --git a/newrelic-security-agent/src/main/java/com/newrelic/agent/security/intcodeagent/websocket/WSClient.java b/newrelic-security-agent/src/main/java/com/newrelic/agent/security/intcodeagent/websocket/WSClient.java index 849ab40ee..c2fcd2a0d 100644 --- a/newrelic-security-agent/src/main/java/com/newrelic/agent/security/intcodeagent/websocket/WSClient.java +++ b/newrelic-security-agent/src/main/java/com/newrelic/agent/security/intcodeagent/websocket/WSClient.java @@ -4,7 +4,6 @@ import com.newrelic.agent.security.AgentInfo; import com.newrelic.agent.security.instrumentator.dispatcher.DispatcherPool; import com.newrelic.agent.security.instrumentator.httpclient.RestRequestThreadPool; -import com.newrelic.agent.security.instrumentator.utils.AgentUtils; import com.newrelic.agent.security.instrumentator.utils.INRSettingsKey; import com.newrelic.agent.security.intcodeagent.controlcommand.ControlCommandProcessor; import com.newrelic.agent.security.intcodeagent.controlcommand.ControlCommandProcessorThreadPool; @@ -71,7 +70,7 @@ public class WSClient extends WebSocketClient { private WebSocketImpl connection = null; - private Map noticeErrorCustomParameters = new HashMap<>(); + private final Map noticeErrorCustomParameters = new HashMap<>(); private SSLContext createSSLContext() throws Exception { @@ -157,7 +156,9 @@ private WSClient() throws URISyntaxException { this.addHeader("NR-CSEC-IGNORED-VUL-CATEGORIES", AgentConfig.getInstance().getAgentMode().getSkipScan().getIastDetectionCategory().getDisabledCategoriesCSV()); this.addHeader("NR-CSEC-PROCESS-START-TIME", String.valueOf(ManagementFactory.getRuntimeMXBean().getStartTime())); this.addHeader("NR-CSEC-IAST-TEST-IDENTIFIER", AgentConfig.getInstance().getScanControllers().getIastTestIdentifier()); - this.addHeader("NR-CSEC-IAST-SCAN-INSTANCE-COUNT", String.valueOf(AgentConfig.getInstance().getScanControllers().getScanInstanceCount())); + if (AgentConfig.getInstance().getScanControllers().getScanInstanceCount() >= 0) { + this.addHeader("NR-CSEC-IAST-SCAN-INSTANCE-COUNT", String.valueOf(AgentConfig.getInstance().getScanControllers().getScanInstanceCount())); + } Proxy proxy = proxyManager(); if(proxy != null) { this.setProxy(proxy); @@ -314,7 +315,7 @@ public void onError(Exception ex) { NewRelic.noticeError(new SecurityNoticeError(CONNECTION_CLOSED_BY + ex.getClass().getSimpleName(), ex), noticeErrorCustomParameters, true); logger.logInit(LogLevel.SEVERE, String.format(IAgentConstants.WS_CONNECTION_UNSUCCESSFUL_INFO, AgentConfig .getInstance().getConfig().getK2ServiceInfo().getValidatorServiceEndpointURL(), - ex.toString(), ex.getCause()), + ex, ex.getCause()), WSClient.class.getName()); logger.log(LogLevel.FINER, String.format(IAgentConstants.WS_CONNECTION_UNSUCCESSFUL, AgentConfig.getInstance().getConfig().getK2ServiceInfo().getValidatorServiceEndpointURL()), ex,