-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from nmervaillie/neo4j-4-compatibility
Neo4j 4 compatibility
- Loading branch information
Showing
13 changed files
with
600 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
version: '2' | ||
services: | ||
# MongoDB: https://hub.docker.com/_/mongo/ | ||
mongodb: | ||
image: mongo:3 | ||
neo4j: | ||
image: 'neo4j:4.2.2' | ||
environment: | ||
- NEO4J_AUTH=neo4j/password | ||
ports: | ||
- 7474:7474 | ||
- 7687:7687 | ||
# Elasticsearch: https://www.elastic.co/guide/en/elasticsearch/reference/6.x/docker.html | ||
elasticsearch: | ||
image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.5.4 | ||
environment: | ||
- http.host=0.0.0.0 | ||
- transport.host=localhost | ||
- network.host=0.0.0.0 | ||
- "ES_JAVA_OPTS=-Xms512m -Xmx512m" | ||
ulimits: | ||
memlock: | ||
soft: -1 | ||
hard: -1 | ||
mem_limit: 1g | ||
# Graylog: https://hub.docker.com/r/graylog/graylog/ | ||
graylog: | ||
image: graylog/graylog:2.5 | ||
environment: | ||
# CHANGE ME (must be at least 16 characters)! | ||
- GRAYLOG_PASSWORD_SECRET=somepasswordpepper | ||
# Password: admin | ||
- GRAYLOG_ROOT_PASSWORD_SHA2=8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918 | ||
- GRAYLOG_WEB_ENDPOINT_URI=http://127.0.0.1:9000/api | ||
links: | ||
- mongodb:mongo | ||
- elasticsearch | ||
- neo4j | ||
depends_on: | ||
- mongodb | ||
- elasticsearch | ||
- neo4j | ||
ports: | ||
# Graylog web interface and REST API | ||
- 9000:9000 | ||
# Syslog TCP | ||
- 514:514 | ||
# Syslog UDP | ||
- 514:514/udp | ||
# GELF TCP | ||
- 12201:12201 | ||
# GELF UDP | ||
- 12201:12201/udp | ||
volumes: | ||
# Mount local plugin file into Docker container | ||
- ./target/plugin-output-neo4j-4.0.0-SNAPSHOT.jar:/usr/share/graylog/plugin/plugin-output-neo4j-4.0.0.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/org/graylog/plugins/outputs/neo4j/Neo4jStatement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.graylog.plugins.outputs.neo4j; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class Neo4jStatement { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(Neo4jStatement.class); | ||
private static final Pattern CYPHER_PARAMETER_REGEX = Pattern.compile("\\$([a-zA-Z0-9_]+)"); | ||
|
||
private final String statement; | ||
private final Collection<String> parameterNames; | ||
|
||
public Neo4jStatement(String statement) { | ||
this.statement = statement; | ||
Matcher m = CYPHER_PARAMETER_REGEX.matcher(statement); | ||
parameterNames = Collections.unmodifiableSet(extractParameterNames(m)); | ||
} | ||
|
||
public String sanitizedQuery() { | ||
return statement.replace("\n", " ") | ||
.replace("\r", " "); | ||
} | ||
|
||
public Collection<String> parameterNames() { | ||
return parameterNames; | ||
} | ||
|
||
private Set<String> extractParameterNames(Matcher m) { | ||
Set<String> params = new HashSet<>(); | ||
while (m.find()) { | ||
params.add(m.group(1)); | ||
LOG.debug("Found field in cypher statement: " + m.group(1)); | ||
} | ||
LOG.info("Identified " + params.size() + " fields in graph create query."); | ||
return params; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/org/graylog/plugins/outputs/neo4j/transport/AbstractNeo4jTransport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.graylog.plugins.outputs.neo4j.transport; | ||
|
||
import static java.util.stream.Collectors.toMap; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.stream.Collectors; | ||
import org.graylog.plugins.outputs.neo4j.Neo4jStatement; | ||
import org.graylog2.plugin.Message; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public abstract class AbstractNeo4jTransport implements INeo4jTransport { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(AbstractNeo4jTransport.class); | ||
|
||
private final Neo4jStatement statement; | ||
|
||
public AbstractNeo4jTransport(Neo4jStatement statement) { | ||
this.statement = statement; | ||
} | ||
|
||
|
||
@Override | ||
public void send(Message message) { | ||
|
||
Collection<String> missingFieldNames = statement.parameterNames().stream() | ||
.filter(it -> !message.hasField(it)) | ||
.collect(Collectors.toSet()); | ||
if (!missingFieldNames.isEmpty()) { | ||
LOG.warn("Unable to execute query because of missing parameters in context : {}", missingFieldNames); | ||
return; | ||
} | ||
|
||
Map<String, Object> convertedFields = message.getFields().entrySet().stream() | ||
.filter(it -> statement.parameterNames().contains(it.getKey())) | ||
.collect(toMap(Entry::getKey, it -> String.valueOf(it.getValue()))); | ||
|
||
postQuery(statement.sanitizedQuery(), convertedFields); | ||
} | ||
|
||
protected abstract void postQuery(String queryString, Map<String, Object> parameters); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.