diff --git a/instrumentation-security/dynamodb-1.11.390/src/main/java/com/amazonaws/services/dynamodbv2_1_11_390/AmazonDynamoDBClient_Instrumentation.java b/instrumentation-security/dynamodb-1.11.390/src/main/java/com/amazonaws/services/dynamodbv2_1_11_390/AmazonDynamoDBClient_Instrumentation.java index 5b45d9372..008fcdf7e 100644 --- a/instrumentation-security/dynamodb-1.11.390/src/main/java/com/amazonaws/services/dynamodbv2_1_11_390/AmazonDynamoDBClient_Instrumentation.java +++ b/instrumentation-security/dynamodb-1.11.390/src/main/java/com/amazonaws/services/dynamodbv2_1_11_390/AmazonDynamoDBClient_Instrumentation.java @@ -15,7 +15,11 @@ import com.amazonaws.Response; import com.amazonaws.http.ExecutionContext; import com.amazonaws.http.HttpResponseHandler; +import com.newrelic.api.agent.security.NewRelicSecurity; +import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper; import com.newrelic.api.agent.security.schema.AbstractOperation; +import com.newrelic.api.agent.security.schema.ExternalConnectionType; +import com.newrelic.api.agent.security.utils.logging.LogLevel; import com.newrelic.api.agent.weaver.Weave; import com.newrelic.api.agent.weaver.Weaver; import com.newrelic.agent.security.instrumentation.dynamodb_1_11_390.DynamoDBUtil; @@ -31,6 +35,12 @@ public abstract class AmazonDynamoDBClient_Instrumentation extends AmazonWebServ public AmazonDynamoDBClient_Instrumentation(ClientConfiguration clientConfiguration) { super(clientConfiguration); + try { + NewRelicSecurity.getAgent().recordExternalConnection(endpoint.getHost(), endpoint.getPort(), endpoint.toString(), clientConfiguration.getLocalAddress().getHostAddress(), + ExternalConnectionType.DATABASE_CONNECTION.name(), DynamoDBUtil.DYNAMODB_1_11_390); + } catch (Exception e) { + NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_DETECTING_CONNECTION_STATS, DynamoDBUtil.DYNAMODB_1_11_390, e.getMessage()), this.getClass().getName()); + } } private Response doInvoke(Request request, HttpResponseHandler> responseHandler, diff --git a/instrumentation-security/dynamodb-1.11.453/src/main/java/com/amazonaws/services/dynamodbv2_1_11_453/AmazonDynamoDBClient_Instrumentation.java b/instrumentation-security/dynamodb-1.11.453/src/main/java/com/amazonaws/services/dynamodbv2_1_11_453/AmazonDynamoDBClient_Instrumentation.java index 840b4ea9f..6d1bd4c4b 100644 --- a/instrumentation-security/dynamodb-1.11.453/src/main/java/com/amazonaws/services/dynamodbv2_1_11_453/AmazonDynamoDBClient_Instrumentation.java +++ b/instrumentation-security/dynamodb-1.11.453/src/main/java/com/amazonaws/services/dynamodbv2_1_11_453/AmazonDynamoDBClient_Instrumentation.java @@ -15,7 +15,11 @@ import com.amazonaws.Response; import com.amazonaws.http.ExecutionContext; import com.amazonaws.http.HttpResponseHandler; +import com.newrelic.api.agent.security.NewRelicSecurity; +import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper; import com.newrelic.api.agent.security.schema.AbstractOperation; +import com.newrelic.api.agent.security.schema.ExternalConnectionType; +import com.newrelic.api.agent.security.utils.logging.LogLevel; import com.newrelic.api.agent.weaver.Weave; import com.newrelic.api.agent.weaver.Weaver; import com.newrelic.agent.security.instrumentation.dynamodb_1_11_453.DynamoDBUtil; @@ -31,8 +35,13 @@ public abstract class AmazonDynamoDBClient_Instrumentation extends AmazonWebServ public AmazonDynamoDBClient_Instrumentation(ClientConfiguration clientConfiguration) { super(clientConfiguration); + try { + NewRelicSecurity.getAgent().recordExternalConnection(endpoint.getHost(), endpoint.getPort(), endpoint.toString(), clientConfiguration.getLocalAddress().getHostAddress(), + ExternalConnectionType.DATABASE_CONNECTION.name(), DynamoDBUtil.DYNAMODB_1_11_453); + } catch (Exception e) { + NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_DETECTING_CONNECTION_STATS, DynamoDBUtil.DYNAMODB_1_11_453, e.getMessage()), this.getClass().getName()); + } } - private Response doInvoke(Request request, HttpResponseHandler> responseHandler, ExecutionContext executionContext, URI discoveredEndpoint, URI uriFromEndpointTrait) { AbstractOperation noSQLOperation = null; boolean isLockAcquired = DynamoDBUtil.acquireLockIfPossible(request.hashCode()); diff --git a/instrumentation-security/dynamodb-1.11.459/src/main/java/com/amazonaws/services/dynamodbv2_1_11_459/AmazonDynamoDBClient_Instrumentation.java b/instrumentation-security/dynamodb-1.11.459/src/main/java/com/amazonaws/services/dynamodbv2_1_11_459/AmazonDynamoDBClient_Instrumentation.java index eece5aae0..003ee7aac 100644 --- a/instrumentation-security/dynamodb-1.11.459/src/main/java/com/amazonaws/services/dynamodbv2_1_11_459/AmazonDynamoDBClient_Instrumentation.java +++ b/instrumentation-security/dynamodb-1.11.459/src/main/java/com/amazonaws/services/dynamodbv2_1_11_459/AmazonDynamoDBClient_Instrumentation.java @@ -15,7 +15,11 @@ import com.amazonaws.Response; import com.amazonaws.http.ExecutionContext; import com.amazonaws.http.HttpResponseHandler; +import com.newrelic.api.agent.security.NewRelicSecurity; +import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper; import com.newrelic.api.agent.security.schema.AbstractOperation; +import com.newrelic.api.agent.security.schema.ExternalConnectionType; +import com.newrelic.api.agent.security.utils.logging.LogLevel; import com.newrelic.api.agent.weaver.Weave; import com.newrelic.api.agent.weaver.Weaver; import com.newrelic.agent.security.instrumentation.dynamodb_1_11_459.DynamoDBUtil; @@ -31,6 +35,12 @@ public abstract class AmazonDynamoDBClient_Instrumentation extends AmazonWebServ public AmazonDynamoDBClient_Instrumentation(ClientConfiguration clientConfiguration) { super(clientConfiguration); + try { + NewRelicSecurity.getAgent().recordExternalConnection(endpoint.getHost(), endpoint.getPort(), endpoint.toString(), clientConfiguration.getLocalAddress().getHostAddress(), + ExternalConnectionType.DATABASE_CONNECTION.name(), DynamoDBUtil.DYNAMODB_1_11_459); + } catch (Exception e) { + NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_DETECTING_CONNECTION_STATS, DynamoDBUtil.DYNAMODB_1_11_459, e.getMessage()), this.getClass().getName()); + } } private Response doInvoke(Request request, HttpResponseHandler> responseHandler, ExecutionContext executionContext, URI discoveredEndpoint, URI uriFromEndpointTrait) { diff --git a/instrumentation-security/dynamodb-1.11.80/src/main/java/com/amazonaws/services/dynamodbv2_1_11_80/AmazonDynamoDBClient_Instrumentation.java b/instrumentation-security/dynamodb-1.11.80/src/main/java/com/amazonaws/services/dynamodbv2_1_11_80/AmazonDynamoDBClient_Instrumentation.java index 0464b2b1f..221a7f830 100644 --- a/instrumentation-security/dynamodb-1.11.80/src/main/java/com/amazonaws/services/dynamodbv2_1_11_80/AmazonDynamoDBClient_Instrumentation.java +++ b/instrumentation-security/dynamodb-1.11.80/src/main/java/com/amazonaws/services/dynamodbv2_1_11_80/AmazonDynamoDBClient_Instrumentation.java @@ -15,7 +15,11 @@ import com.amazonaws.Response; import com.amazonaws.http.ExecutionContext; import com.amazonaws.http.HttpResponseHandler; +import com.newrelic.api.agent.security.NewRelicSecurity; +import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper; import com.newrelic.api.agent.security.schema.AbstractOperation; +import com.newrelic.api.agent.security.schema.ExternalConnectionType; +import com.newrelic.api.agent.security.utils.logging.LogLevel; import com.newrelic.api.agent.weaver.Weave; import com.newrelic.api.agent.weaver.Weaver; import com.newrelic.agent.security.instrumentation.dynamodb_1_11_80.DynamoDBUtil; @@ -29,6 +33,11 @@ public abstract class AmazonDynamoDBClient_Instrumentation extends AmazonWebServ public AmazonDynamoDBClient_Instrumentation(ClientConfiguration clientConfiguration) { super(clientConfiguration); + try { + NewRelicSecurity.getAgent().recordExternalConnection(endpoint.getHost(), endpoint.getPort(), null, clientConfiguration.getLocalAddress().getHostAddress(), ExternalConnectionType.DATABASE_CONNECTION.name(), DynamoDBUtil.DYNAMODB_1_11_80); + } catch (Exception e) { + NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_DETECTING_CONNECTION_STATS, DynamoDBUtil.DYNAMODB_1_11_80, e.getMessage()), this.getClass().getName()); + } } // private Response invoke(Request request, HttpResponseHandler> responseHandler, ExecutionContext executionContext) { diff --git a/instrumentation-security/dynamodb-2.1.0/src/main/java/software/amazon/awssdk/services/dynamodb/DefaultDynamoDbAsyncClient_Instrumentation.java b/instrumentation-security/dynamodb-2.1.0/src/main/java/software/amazon/awssdk/services/dynamodb/DefaultDynamoDbAsyncClient_Instrumentation.java new file mode 100644 index 000000000..6aea939d6 --- /dev/null +++ b/instrumentation-security/dynamodb-2.1.0/src/main/java/software/amazon/awssdk/services/dynamodb/DefaultDynamoDbAsyncClient_Instrumentation.java @@ -0,0 +1,29 @@ +package software.amazon.awssdk.services.dynamodb; + +import com.newrelic.agent.security.instrumentation.dynamodb_210.DynamoDBUtil; +import com.newrelic.api.agent.security.NewRelicSecurity; +import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper; +import com.newrelic.api.agent.security.schema.ExternalConnectionType; +import com.newrelic.api.agent.security.utils.logging.LogLevel; +import com.newrelic.api.agent.weaver.MatchType; +import com.newrelic.api.agent.weaver.Weave; +import software.amazon.awssdk.core.client.config.SdkClientConfiguration; +import software.amazon.awssdk.core.client.config.SdkClientOption; + +import java.net.URI; + +@Weave(originalName = "software.amazon.awssdk.services.dynamodb.DefaultDynamoDbAsyncClient", type = MatchType.ExactClass) +final class DefaultDynamoDbAsyncClient_Instrumentation { + + protected DefaultDynamoDbAsyncClient_Instrumentation(SdkClientConfiguration clientConfiguration) { + try { + URI endpoint = clientConfiguration != null ? clientConfiguration.option(SdkClientOption.ENDPOINT) : null; + if (endpoint != null) { + NewRelicSecurity.getAgent().recordExternalConnection(endpoint.getHost(), endpoint.getPort(), null, null, + ExternalConnectionType.DATABASE_CONNECTION.name(), DynamoDBUtil.DYNAMODB_2_1_0); + } + } catch (Exception e) { + NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_DETECTING_CONNECTION_STATS, DynamoDBUtil.DYNAMODB_2_1_0, e.getMessage()), this.getClass().getName()); + } + } +} diff --git a/instrumentation-security/dynamodb-2.1.0/src/main/java/software/amazon/awssdk/services/dynamodb/DefaultDynamoDbClient_Instrumentation.java b/instrumentation-security/dynamodb-2.1.0/src/main/java/software/amazon/awssdk/services/dynamodb/DefaultDynamoDbClient_Instrumentation.java new file mode 100644 index 000000000..abafe8ee6 --- /dev/null +++ b/instrumentation-security/dynamodb-2.1.0/src/main/java/software/amazon/awssdk/services/dynamodb/DefaultDynamoDbClient_Instrumentation.java @@ -0,0 +1,29 @@ +package software.amazon.awssdk.services.dynamodb; + +import com.newrelic.agent.security.instrumentation.dynamodb_210.DynamoDBUtil; +import com.newrelic.api.agent.security.NewRelicSecurity; +import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper; +import com.newrelic.api.agent.security.schema.ExternalConnectionType; +import com.newrelic.api.agent.security.utils.logging.LogLevel; +import com.newrelic.api.agent.weaver.MatchType; +import com.newrelic.api.agent.weaver.Weave; +import software.amazon.awssdk.core.client.config.SdkClientConfiguration; +import software.amazon.awssdk.core.client.config.SdkClientOption; + +import java.net.URI; + +@Weave(originalName = "software.amazon.awssdk.services.dynamodb.DefaultDynamoDbClient", type = MatchType.ExactClass) +final class DefaultDynamoDbClient_Instrumentation { + + protected DefaultDynamoDbClient_Instrumentation(SdkClientConfiguration clientConfiguration) { + try { + URI endpoint = clientConfiguration != null ? clientConfiguration.option(SdkClientOption.ENDPOINT) : null; + if (endpoint != null) { + NewRelicSecurity.getAgent().recordExternalConnection(endpoint.getHost(), endpoint.getPort(), null, null, + ExternalConnectionType.DATABASE_CONNECTION.name(), DynamoDBUtil.DYNAMODB_2_1_0); + } + } catch (Exception e) { + NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_DETECTING_CONNECTION_STATS, DynamoDBUtil.DYNAMODB_2_1_0, e.getMessage()), this.getClass().getName()); + } + } +} diff --git a/instrumentation-security/dynamodb-2.1.2/src/main/java/software/amazon/awssdk/services/dynamodb/DefaultDynamoDbAsyncClient_Instrumentation.java b/instrumentation-security/dynamodb-2.1.2/src/main/java/software/amazon/awssdk/services/dynamodb/DefaultDynamoDbAsyncClient_Instrumentation.java new file mode 100644 index 000000000..82ca92111 --- /dev/null +++ b/instrumentation-security/dynamodb-2.1.2/src/main/java/software/amazon/awssdk/services/dynamodb/DefaultDynamoDbAsyncClient_Instrumentation.java @@ -0,0 +1,29 @@ +package software.amazon.awssdk.services.dynamodb; + +import com.newrelic.agent.security.instrumentation.dynamodb_212.DynamoDBUtil; +import com.newrelic.api.agent.security.NewRelicSecurity; +import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper; +import com.newrelic.api.agent.security.schema.ExternalConnectionType; +import com.newrelic.api.agent.security.utils.logging.LogLevel; +import com.newrelic.api.agent.weaver.MatchType; +import com.newrelic.api.agent.weaver.Weave; +import software.amazon.awssdk.core.client.config.SdkClientConfiguration; +import software.amazon.awssdk.core.client.config.SdkClientOption; + +import java.net.URI; + +@Weave(originalName = "software.amazon.awssdk.services.dynamodb.DefaultDynamoDbAsyncClient", type = MatchType.ExactClass) +final class DefaultDynamoDbAsyncClient_Instrumentation { + + protected DefaultDynamoDbAsyncClient_Instrumentation(SdkClientConfiguration clientConfiguration) { + try { + URI endpoint = clientConfiguration != null ? clientConfiguration.option(SdkClientOption.ENDPOINT) : null; + if (endpoint != null) { + NewRelicSecurity.getAgent().recordExternalConnection(endpoint.getHost(), endpoint.getPort(), null, null, + ExternalConnectionType.DATABASE_CONNECTION.name(), DynamoDBUtil.DYNAMODB_2_1_2); + } + } catch (Exception e) { + NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_DETECTING_CONNECTION_STATS, DynamoDBUtil.DYNAMODB_2_1_2, e.getMessage()), this.getClass().getName()); + } + } +} diff --git a/instrumentation-security/dynamodb-2.1.2/src/main/java/software/amazon/awssdk/services/dynamodb/DefaultDynamoDbClient_Instrumentation.java b/instrumentation-security/dynamodb-2.1.2/src/main/java/software/amazon/awssdk/services/dynamodb/DefaultDynamoDbClient_Instrumentation.java new file mode 100644 index 000000000..e0e8a7252 --- /dev/null +++ b/instrumentation-security/dynamodb-2.1.2/src/main/java/software/amazon/awssdk/services/dynamodb/DefaultDynamoDbClient_Instrumentation.java @@ -0,0 +1,29 @@ +package software.amazon.awssdk.services.dynamodb; + +import com.newrelic.agent.security.instrumentation.dynamodb_212.DynamoDBUtil; +import com.newrelic.api.agent.security.NewRelicSecurity; +import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper; +import com.newrelic.api.agent.security.schema.ExternalConnectionType; +import com.newrelic.api.agent.security.utils.logging.LogLevel; +import com.newrelic.api.agent.weaver.MatchType; +import com.newrelic.api.agent.weaver.Weave; +import software.amazon.awssdk.core.client.config.SdkClientConfiguration; +import software.amazon.awssdk.core.client.config.SdkClientOption; + +import java.net.URI; + +@Weave(originalName = "software.amazon.awssdk.services.dynamodb.DefaultDynamoDbClient", type = MatchType.ExactClass) +final class DefaultDynamoDbClient_Instrumentation { + + protected DefaultDynamoDbClient_Instrumentation(SdkClientConfiguration clientConfiguration) { + try { + URI endpoint = clientConfiguration != null ? clientConfiguration.option(SdkClientOption.ENDPOINT) : null; + if (endpoint != null) { + NewRelicSecurity.getAgent().recordExternalConnection(endpoint.getHost(), endpoint.getPort(), null, null, + ExternalConnectionType.DATABASE_CONNECTION.name(), DynamoDBUtil.DYNAMODB_2_1_2); + } + } catch (Exception e) { + NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_DETECTING_CONNECTION_STATS, DynamoDBUtil.DYNAMODB_2_1_2, e.getMessage()), this.getClass().getName()); + } + } +} diff --git a/instrumentation-security/dynamodb-2.15.34/src/main/java/software/amazon/awssdk/services/dynamodb/DefaultDynamoDbAsyncClient_Instrumentation.java b/instrumentation-security/dynamodb-2.15.34/src/main/java/software/amazon/awssdk/services/dynamodb/DefaultDynamoDbAsyncClient_Instrumentation.java new file mode 100644 index 000000000..59b173dc7 --- /dev/null +++ b/instrumentation-security/dynamodb-2.15.34/src/main/java/software/amazon/awssdk/services/dynamodb/DefaultDynamoDbAsyncClient_Instrumentation.java @@ -0,0 +1,34 @@ +package software.amazon.awssdk.services.dynamodb; + +import com.newrelic.agent.security.instrumentation.dynamodb_215.DynamoDBUtil; +import com.newrelic.api.agent.security.NewRelicSecurity; +import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper; +import com.newrelic.api.agent.security.schema.ExternalConnectionType; +import com.newrelic.api.agent.security.utils.logging.LogLevel; +import com.newrelic.api.agent.weaver.MatchType; +import com.newrelic.api.agent.weaver.Weave; +import com.newrelic.api.agent.weaver.WeaveAllConstructors; +import com.newrelic.api.agent.weaver.Weaver; +import software.amazon.awssdk.core.client.config.SdkClientConfiguration; +import software.amazon.awssdk.core.client.config.SdkClientOption; + +import java.net.URI; + +@Weave(originalName = "software.amazon.awssdk.services.dynamodb.DefaultDynamoDbAsyncClient", type = MatchType.ExactClass) +final class DefaultDynamoDbAsyncClient_Instrumentation { + + private final SdkClientConfiguration clientConfiguration = Weaver.callOriginal(); + + @WeaveAllConstructors + protected DefaultDynamoDbAsyncClient_Instrumentation() { + try { + URI endpoint = clientConfiguration != null ? clientConfiguration.option(SdkClientOption.ENDPOINT) : null; + if (endpoint != null) { + NewRelicSecurity.getAgent().recordExternalConnection(endpoint.getHost(), endpoint.getPort(), null, null, + ExternalConnectionType.DATABASE_CONNECTION.name(), DynamoDBUtil.DYNAMODB_2_15_34); + } + } catch (Exception e) { + NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_DETECTING_CONNECTION_STATS, DynamoDBUtil.DYNAMODB_2_15_34, e.getMessage()), this.getClass().getName()); + } + } +} diff --git a/instrumentation-security/dynamodb-2.15.34/src/main/java/software/amazon/awssdk/services/dynamodb/DefaultDynamoDbClient_Instrumentation.java b/instrumentation-security/dynamodb-2.15.34/src/main/java/software/amazon/awssdk/services/dynamodb/DefaultDynamoDbClient_Instrumentation.java new file mode 100644 index 000000000..f8d89042a --- /dev/null +++ b/instrumentation-security/dynamodb-2.15.34/src/main/java/software/amazon/awssdk/services/dynamodb/DefaultDynamoDbClient_Instrumentation.java @@ -0,0 +1,34 @@ +package software.amazon.awssdk.services.dynamodb; + +import com.newrelic.agent.security.instrumentation.dynamodb_215.DynamoDBUtil; +import com.newrelic.api.agent.security.NewRelicSecurity; +import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper; +import com.newrelic.api.agent.security.schema.ExternalConnectionType; +import com.newrelic.api.agent.security.utils.logging.LogLevel; +import com.newrelic.api.agent.weaver.MatchType; +import com.newrelic.api.agent.weaver.Weave; +import com.newrelic.api.agent.weaver.WeaveAllConstructors; +import com.newrelic.api.agent.weaver.Weaver; +import software.amazon.awssdk.core.client.config.SdkClientConfiguration; +import software.amazon.awssdk.core.client.config.SdkClientOption; + +import java.net.URI; + +@Weave(originalName = "software.amazon.awssdk.services.dynamodb.DefaultDynamoDbClient", type = MatchType.ExactClass) +final class DefaultDynamoDbClient_Instrumentation { + + private final SdkClientConfiguration clientConfiguration = Weaver.callOriginal(); + + @WeaveAllConstructors + protected DefaultDynamoDbClient_Instrumentation() { + try { + URI endpoint = clientConfiguration != null ? clientConfiguration.option(SdkClientOption.ENDPOINT) : null; + if (endpoint != null) { + NewRelicSecurity.getAgent().recordExternalConnection(endpoint.getHost(), endpoint.getPort(), null, null, + ExternalConnectionType.DATABASE_CONNECTION.name(), DynamoDBUtil.DYNAMODB_2_15_34); + } + } catch (Exception e) { + NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_DETECTING_CONNECTION_STATS, DynamoDBUtil.DYNAMODB_2_15_34, e.getMessage()), this.getClass().getName()); + } + } +} diff --git a/instrumentation-security/jedis-1.4.0/src/main/java/redis/clients/jedis/Connection_Instrumentation.java b/instrumentation-security/jedis-1.4.0/src/main/java/redis/clients/jedis/Connection_Instrumentation.java index 83842d5cf..95b460567 100644 --- a/instrumentation-security/jedis-1.4.0/src/main/java/redis/clients/jedis/Connection_Instrumentation.java +++ b/instrumentation-security/jedis-1.4.0/src/main/java/redis/clients/jedis/Connection_Instrumentation.java @@ -4,6 +4,8 @@ import com.newrelic.api.agent.security.NewRelicSecurity; import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper; import com.newrelic.api.agent.security.schema.AbstractOperation; +import com.newrelic.api.agent.security.schema.ExternalConnectionType; +import com.newrelic.api.agent.security.utils.logging.LogLevel; import com.newrelic.api.agent.weaver.MatchType; import com.newrelic.api.agent.weaver.Weave; import com.newrelic.api.agent.weaver.Weaver; @@ -13,6 +15,19 @@ @Weave(type = MatchType.BaseClass, originalName = "redis.clients.jedis.Connection") public abstract class Connection_Instrumentation { + + public abstract int getPort(); + public abstract String getHost(); + + public void connect() { + Weaver.callOriginal(); + try { + NewRelicSecurity.getAgent().recordExternalConnection(getHost(), getPort(), null, null, ExternalConnectionType.DATABASE_CONNECTION.name(), "JEDIS-1.4.0"); + } catch (Exception e) { + NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_DETECTING_CONNECTION_STATS, "JEDIS-1.4.0", e.getMessage()), this.getClass().getName()); + } + } + protected Connection sendCommand(final Protocol.Command cmd, final byte[]... args) { boolean isLockAcquired = JedisHelper.acquireLockIfPossible(cmd.hashCode()); AbstractOperation operation = null; diff --git a/instrumentation-security/jedis-2.7.1_2.7.2/src/main/java/redis/clients/jedis/Connection_Instrumentation.java b/instrumentation-security/jedis-2.7.1_2.7.2/src/main/java/redis/clients/jedis/Connection_Instrumentation.java index 52f2b9f13..7d476b912 100644 --- a/instrumentation-security/jedis-2.7.1_2.7.2/src/main/java/redis/clients/jedis/Connection_Instrumentation.java +++ b/instrumentation-security/jedis-2.7.1_2.7.2/src/main/java/redis/clients/jedis/Connection_Instrumentation.java @@ -4,19 +4,33 @@ import com.newrelic.api.agent.security.NewRelicSecurity; import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper; import com.newrelic.api.agent.security.schema.AbstractOperation; +import com.newrelic.api.agent.security.schema.ExternalConnectionType; +import com.newrelic.api.agent.security.utils.logging.LogLevel; import com.newrelic.api.agent.weaver.MatchType; import com.newrelic.api.agent.weaver.Weave; import com.newrelic.api.agent.weaver.Weaver; -import redis.clients.jedis.Connection; -import redis.clients.jedis.Protocol; +import java.net.Socket; import java.util.ArrayList; import java.util.List; -import static com.newrelic.agent.security.instrumentation.jedis_2_7_1.JedisHelper.NR_SEC_CUSTOM_ATTRIB_NAME; - @Weave(type = MatchType.BaseClass, originalName = "redis.clients.jedis.Connection") public abstract class Connection_Instrumentation { + + public abstract Socket getSocket(); + + public abstract int getPort(); + public abstract String getHost(); + + public void connect() { + Weaver.callOriginal(); + try { + NewRelicSecurity.getAgent().recordExternalConnection(getHost(), getPort(), null, getSocket().getInetAddress().getHostAddress(), ExternalConnectionType.DATABASE_CONNECTION.name(), "JEDIS-2.7.1"); + } catch (Exception e) { + NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_DETECTING_CONNECTION_STATS, "JEDIS-2.7.1", e.getMessage()), this.getClass().getName()); + } + } + protected Connection sendCommand(final ProtocolCommand cmd, final byte[]... args) { boolean isLockAcquired = JedisHelper.acquireLockIfPossible(cmd.hashCode()); AbstractOperation operation = null; diff --git a/instrumentation-security/jedis-3.0.0/build.gradle b/instrumentation-security/jedis-3.0.0/build.gradle index ebc2c0673..82fca2a97 100644 --- a/instrumentation-security/jedis-3.0.0/build.gradle +++ b/instrumentation-security/jedis-3.0.0/build.gradle @@ -12,6 +12,7 @@ dependencies { verifyInstrumentation { passes 'redis.clients:jedis:[3.0.0,4.0.0)' + excludeRegex(".*(rc|beta|RC).*") } site { diff --git a/instrumentation-security/jedis-3.0.0/src/main/java/redis/clients/jedis/Connection_Instrumentation.java b/instrumentation-security/jedis-3.0.0/src/main/java/redis/clients/jedis/Connection_Instrumentation.java index bf5e48f1b..e704a8d28 100644 --- a/instrumentation-security/jedis-3.0.0/src/main/java/redis/clients/jedis/Connection_Instrumentation.java +++ b/instrumentation-security/jedis-3.0.0/src/main/java/redis/clients/jedis/Connection_Instrumentation.java @@ -4,20 +4,35 @@ import com.newrelic.api.agent.security.NewRelicSecurity; import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper; import com.newrelic.api.agent.security.schema.AbstractOperation; +import com.newrelic.api.agent.security.schema.ExternalConnectionType; +import com.newrelic.api.agent.security.utils.logging.LogLevel; import com.newrelic.api.agent.weaver.MatchType; import com.newrelic.api.agent.weaver.Weave; +import com.newrelic.api.agent.weaver.WeaveAllConstructors; import com.newrelic.api.agent.weaver.Weaver; -import redis.clients.jedis.Connection; -import redis.clients.jedis.Protocol; import redis.clients.jedis.commands.ProtocolCommand; +import java.net.Socket; import java.util.ArrayList; import java.util.List; -import static com.newrelic.agent.security.instrumentation.jedis_3_0_0.JedisHelper.NR_SEC_CUSTOM_ATTRIB_NAME; @Weave(type = MatchType.BaseClass, originalName = "redis.clients.jedis.Connection") public abstract class Connection_Instrumentation { + + public abstract Socket getSocket(); + public abstract int getPort(); + public abstract String getHost(); + + @WeaveAllConstructors + public Connection_Instrumentation() { + try { + NewRelicSecurity.getAgent().recordExternalConnection(getHost(), getPort(), null, getSocket().getInetAddress().getHostAddress(), ExternalConnectionType.DATABASE_CONNECTION.name(), "JEDIS-3.0.0"); + } catch (Exception e) { + NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_DETECTING_CONNECTION_STATS, "JEDIS-3.0.0", e.getMessage()), this.getClass().getName()); + } + } + public void sendCommand(final ProtocolCommand cmd, final byte[]... args) { boolean isLockAcquired = JedisHelper.acquireLockIfPossible(cmd.hashCode()); AbstractOperation operation = null; diff --git a/instrumentation-security/jedis-4.0.0/src/main/java/redis/clients/jedis/Connection_Instrumentation.java b/instrumentation-security/jedis-4.0.0/src/main/java/redis/clients/jedis/Connection_Instrumentation.java index 1c9b94479..c2ecc5333 100644 --- a/instrumentation-security/jedis-4.0.0/src/main/java/redis/clients/jedis/Connection_Instrumentation.java +++ b/instrumentation-security/jedis-4.0.0/src/main/java/redis/clients/jedis/Connection_Instrumentation.java @@ -4,18 +4,35 @@ import com.newrelic.api.agent.security.NewRelicSecurity; import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper; import com.newrelic.api.agent.security.schema.AbstractOperation; +import com.newrelic.api.agent.security.schema.ExternalConnectionType; +import com.newrelic.api.agent.security.utils.logging.LogLevel; import com.newrelic.api.agent.weaver.MatchType; import com.newrelic.api.agent.weaver.Weave; import com.newrelic.api.agent.weaver.Weaver; import redis.clients.jedis.args.Rawable; +import redis.clients.jedis.exceptions.JedisConnectionException; import java.util.ArrayList; import java.util.List; -import static com.newrelic.agent.security.instrumentation.jedis_4_0_0.JedisHelper.NR_SEC_CUSTOM_ATTRIB_NAME; @Weave(type = MatchType.BaseClass, originalName = "redis.clients.jedis.Connection") public abstract class Connection_Instrumentation { + + final HostAndPort getHostAndPort() { + return Weaver.callOriginal(); + } + + public void connect() throws JedisConnectionException { + Weaver.callOriginal(); + try { + HostAndPort hostAndPort = getHostAndPort(); + NewRelicSecurity.getAgent().recordExternalConnection(hostAndPort.getHost(), hostAndPort.getPort(), null, null, ExternalConnectionType.DATABASE_CONNECTION.name(), "JEDIS-4.0.0"); + } catch (Exception e) { + NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_DETECTING_CONNECTION_STATS, "JEDIS-4.0.0", e.getMessage()), this.getClass().getName()); + } + } + public void sendCommand(final CommandArguments args) { boolean isLockAcquired = JedisHelper.acquireLockIfPossible(args.hashCode()); AbstractOperation operation = null; diff --git a/instrumentation-security/lettuce-4.3/src/main/java/com/lambdaworks/redis/RedisClient_Instrumentation.java b/instrumentation-security/lettuce-4.3/src/main/java/com/lambdaworks/redis/RedisClient_Instrumentation.java new file mode 100644 index 000000000..80fe0211a --- /dev/null +++ b/instrumentation-security/lettuce-4.3/src/main/java/com/lambdaworks/redis/RedisClient_Instrumentation.java @@ -0,0 +1,32 @@ +package com.lambdaworks.redis; + +import com.lambdaworks.redis.codec.RedisCodec; +import com.lambdaworks.redis.protocol.CommandHandler; +import com.newrelic.agent.security.instrumentation.lettuce_4_3.LettuceUtils; +import com.newrelic.api.agent.security.NewRelicSecurity; +import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper; +import com.newrelic.api.agent.security.schema.ExternalConnectionType; +import com.newrelic.api.agent.security.utils.logging.LogLevel; +import com.newrelic.api.agent.weaver.Weave; +import com.newrelic.api.agent.weaver.Weaver; + +import java.util.concurrent.TimeUnit; + +@SuppressWarnings("deprecation") +@Weave(originalName = "com.lambdaworks.redis.RedisClient") +public abstract class RedisClient_Instrumentation extends AbstractRedisClient { + + private final RedisURI redisURI = Weaver.callOriginal(); + + protected StatefulRedisConnectionImpl newStatefulRedisConnection(CommandHandler commandHandler, RedisCodec codec, long timeout, TimeUnit unit){ + StatefulRedisConnectionImpl redisConnection = Weaver.callOriginal(); + try { + NewRelicSecurity.getAgent().recordExternalConnection(redisURI.getHost(), redisURI.getPort(), null, redisURI.getResolvedAddress().toString(), + ExternalConnectionType.DATABASE_CONNECTION.name(), LettuceUtils.LETTUCE_4_3); + } catch (Exception e){ + NewRelicSecurity.getAgent().log( + LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_DETECTING_CONNECTION_STATS, LettuceUtils.LETTUCE_4_3, e.getMessage()), this.getClass().getName()); + } + return redisConnection; + } +} diff --git a/instrumentation-security/lettuce-5.0/build.gradle b/instrumentation-security/lettuce-5.0/build.gradle index 79018d90d..719756eca 100644 --- a/instrumentation-security/lettuce-5.0/build.gradle +++ b/instrumentation-security/lettuce-5.0/build.gradle @@ -2,7 +2,7 @@ dependencies { implementation(project(":newrelic-security-api")) implementation("com.newrelic.agent.java:newrelic-api:${nrAPIVersion}") implementation("com.newrelic.agent.java:newrelic-weaver-api:${nrAPIVersion}") - implementation group: 'io.lettuce', name: 'lettuce-core', version: '5.0.3.RELEASE' + implementation ("io.lettuce:lettuce-core:5.0.3.RELEASE") testImplementation('org.testcontainers:testcontainers:1.17.1') } diff --git a/instrumentation-security/lettuce-5.0/src/main/java/io/lettuce/core/RedisClient_Instrumentation.java b/instrumentation-security/lettuce-5.0/src/main/java/io/lettuce/core/RedisClient_Instrumentation.java new file mode 100644 index 000000000..a2dfc1fa3 --- /dev/null +++ b/instrumentation-security/lettuce-5.0/src/main/java/io/lettuce/core/RedisClient_Instrumentation.java @@ -0,0 +1,26 @@ +package io.lettuce.core; + +import com.newrelic.agent.security.instrumentation.lettuce_6_0.LettuceUtils; +import com.newrelic.api.agent.security.NewRelicSecurity; +import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper; +import com.newrelic.api.agent.security.schema.ExternalConnectionType; +import com.newrelic.api.agent.security.utils.logging.LogLevel; +import com.newrelic.api.agent.weaver.Weave; +import com.newrelic.api.agent.weaver.Weaver; +import io.lettuce.core.resource.ClientResources; + +@Weave(originalName = "io.lettuce.core.RedisClient") +public abstract class RedisClient_Instrumentation extends AbstractRedisClient { + + private final RedisURI redisURI = Weaver.callOriginal(); + + protected RedisClient_Instrumentation(ClientResources clientResources, RedisURI redisURI) { + super(clientResources); + try { + NewRelicSecurity.getAgent().recordExternalConnection(redisURI.getHost(), redisURI.getPort(), null, null, + ExternalConnectionType.DATABASE_CONNECTION.name(), LettuceUtils.LETTUCE_5_0); + } catch (Exception e){ + NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_DETECTING_CONNECTION_STATS, LettuceUtils.LETTUCE_5_0, e.getMessage()), this.getClass().getName()); + } + } +} diff --git a/instrumentation-security/spymemcached-2.12.0/src/main/java/com/newrelic/agent/security/instrumentation/spy/memcached/MemcachedHelper.java b/instrumentation-security/spymemcached-2.12.0/src/main/java/com/newrelic/agent/security/instrumentation/spy/memcached/MemcachedHelper.java index cef4b3e35..580ba601a 100644 --- a/instrumentation-security/spymemcached-2.12.0/src/main/java/com/newrelic/agent/security/instrumentation/spy/memcached/MemcachedHelper.java +++ b/instrumentation-security/spymemcached-2.12.0/src/main/java/com/newrelic/agent/security/instrumentation/spy/memcached/MemcachedHelper.java @@ -16,7 +16,7 @@ public class MemcachedHelper { public static final String METHOD_ASYNC_STORE = "asyncStore"; public static final String METHOD_ASYNC_CAT = "asyncCat"; public static final String METHOD_ASYNC_CAS = "asyncCAS"; - private static final String SPYMEMCACHED_2_12_0 = "SPYMEMCACHED-2.12.0"; + public static final String SPYMEMCACHED_2_12_0 = "SPYMEMCACHED-2.12.0"; public static AbstractOperation preprocessSecurityHook(String type, String command, String key, Object val, String klass, String method) { try { diff --git a/instrumentation-security/spymemcached-2.12.0/src/main/java/net/spy/memcached/MemcachedClient_Instrumentation.java b/instrumentation-security/spymemcached-2.12.0/src/main/java/net/spy/memcached/MemcachedClient_Instrumentation.java index 66658d078..92e59eba0 100644 --- a/instrumentation-security/spymemcached-2.12.0/src/main/java/net/spy/memcached/MemcachedClient_Instrumentation.java +++ b/instrumentation-security/spymemcached-2.12.0/src/main/java/net/spy/memcached/MemcachedClient_Instrumentation.java @@ -4,19 +4,35 @@ import com.newrelic.api.agent.security.NewRelicSecurity; import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper; import com.newrelic.api.agent.security.schema.AbstractOperation; -import com.newrelic.api.agent.security.schema.exceptions.NewRelicSecurityException; -import com.newrelic.api.agent.security.schema.operation.MemcachedOperation; +import com.newrelic.api.agent.security.schema.ExternalConnectionType; +import com.newrelic.api.agent.security.utils.logging.LogLevel; import com.newrelic.api.agent.weaver.Weave; import com.newrelic.api.agent.weaver.Weaver; import net.spy.memcached.internal.OperationFuture; import net.spy.memcached.ops.ConcatenationType; -import net.spy.memcached.ops.Operation; import net.spy.memcached.ops.StoreType; import net.spy.memcached.transcoders.Transcoder; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.List; + @Weave(originalName = "net.spy.memcached.MemcachedClient") public class MemcachedClient_Instrumentation { + public MemcachedClient_Instrumentation(ConnectionFactory cf, List addrs) throws IOException { + try { + if (addrs != null) { + for (InetSocketAddress address : addrs) { + NewRelicSecurity.getAgent().recordExternalConnection(address.getHostName(), address.getPort(), null, address.getAddress().getHostAddress(), + ExternalConnectionType.DATABASE_CONNECTION.name(), MemcachedHelper.SPYMEMCACHED_2_12_0); + } + } + } catch (Exception e) { + NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_DETECTING_CONNECTION_STATS, MemcachedHelper.SPYMEMCACHED_2_12_0, e.getMessage()), this.getClass().getName()); + } + } + private OperationFuture asyncStore(StoreType storeType, String key, int exp, T value, Transcoder tc) { boolean isLockAcquired = GenericHelper.acquireLockIfPossible(MemcachedHelper.NR_SEC_CUSTOM_ATTRIB_NAME, value.hashCode()); diff --git a/newrelic-security-api/src/main/java/com/newrelic/api/agent/security/instrumentation/helpers/GenericHelper.java b/newrelic-security-api/src/main/java/com/newrelic/api/agent/security/instrumentation/helpers/GenericHelper.java index 8d4cf3f0f..99b5508d7 100644 --- a/newrelic-security-api/src/main/java/com/newrelic/api/agent/security/instrumentation/helpers/GenericHelper.java +++ b/newrelic-security-api/src/main/java/com/newrelic/api/agent/security/instrumentation/helpers/GenericHelper.java @@ -24,6 +24,8 @@ public class GenericHelper { public static final String ERROR_WHILE_DETECTING_USER_CLASS = "Instrumentation library: %s error while detecting user class"; public static final String ERROR_WHILE_GETTING_ROUTE_FOR_INCOMING_REQUEST = "Instrumentation library: %s , error while getting route for incoming request : %s"; + public static final String ERROR_WHILE_DETECTING_CONNECTION_STATS = "Instrumentation library: %s, error while detecting connection stats : %s"; + public static boolean skipExistsEvent() { if (!(NewRelicSecurity.getAgent().getCurrentPolicy().getVulnerabilityScan().getEnabled() && NewRelicSecurity.getAgent().getCurrentPolicy().getVulnerabilityScan().getIastScan().getEnabled())) {