You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metron.apache.org by le...@apache.org on 2017/01/26 16:21:55 UTC
[2/3] incubator-metron git commit: METRON-283 Migrate Geo Enrichment
outside of MySQL (justinleet) closes apache/incubator-metron#421
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-deployment/roles/mysql_server/tasks/main.yml
----------------------------------------------------------------------
diff --git a/metron-deployment/roles/mysql_server/tasks/main.yml b/metron-deployment/roles/mysql_server/tasks/main.yml
deleted file mode 100644
index 159e5a6..0000000
--- a/metron-deployment/roles/mysql_server/tasks/main.yml
+++ /dev/null
@@ -1,20 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
----
-- include: mysql.yml
-- include: mysql-password.yml
-- include: geoip.yml
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-deployment/roles/mysql_server/tasks/mysql-password.yml
----------------------------------------------------------------------
diff --git a/metron-deployment/roles/mysql_server/tasks/mysql-password.yml b/metron-deployment/roles/mysql_server/tasks/mysql-password.yml
deleted file mode 100644
index a4f0d0b..0000000
--- a/metron-deployment/roles/mysql_server/tasks/mysql-password.yml
+++ /dev/null
@@ -1,33 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
----
-- name: Retrieve temporary root password
- shell: "grep 'temporary password' /var/log/mysqld.log | sed 's/.*root@localhost: //'"
- args:
- creates: ~/.my.cnf
- register: temp_root_password
-
-- name: Update mysql root password
- command: "mysqladmin --user=root --password='{{ temp_root_password.stdout }}' password '{{ mysql_root_password }}'"
- ignore_errors: yes
- args:
- creates: ~/.my.cnf
-
-- name: Create .my.cnf
- template:
- src: "../roles/mysql_server/templates/.my.cnf"
- dest: ~/.my.cnf
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-deployment/roles/mysql_server/tasks/mysql.yml
----------------------------------------------------------------------
diff --git a/metron-deployment/roles/mysql_server/tasks/mysql.yml b/metron-deployment/roles/mysql_server/tasks/mysql.yml
deleted file mode 100644
index e48ad5c..0000000
--- a/metron-deployment/roles/mysql_server/tasks/mysql.yml
+++ /dev/null
@@ -1,60 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
----
-- name: Create temporary directories
- file:
- path: "/tmp/geoip"
- state: directory
- mode: 0755
-
-- name: Install Mysql Community Release Repo Def
- get_url:
- dest: /tmp/{{ mysql_rpm_version }}.rpm
- url: "{{ mysql_yum_repo_url }}"
-
-- name: Install Mysql Community Release Repo
- yum:
- pkg: /tmp/{{ mysql_rpm_version }}.rpm
- state: installed
- register: result
- until: result.rc == 0
- retries: 5
- delay: 10
-
-- name: Install MySQL
- yum:
- name: "{{ item }}"
- state: latest
- with_items:
- - "mysql-community-server"
- - "MySQL-python"
- register: result
- until: result.rc == 0
- retries: 5
- delay: 10
-
-#
-# mysql must be running for the 'mysql_client' role to function properly. that
-# role grants access to mysql clients connecting from external hosts (think
-# storm topologies doing geoip enrichment).
-#
-# ideally the logic in 'mysql_client' would be moved to 'mysql_server' so that
-# mysql could be started, access granted, and then shutdown after this is
-# complete.
-#
-- name: Start MySQL
- service: name=mysqld state=started
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-deployment/roles/mysql_server/templates/.my.cnf
----------------------------------------------------------------------
diff --git a/metron-deployment/roles/mysql_server/templates/.my.cnf b/metron-deployment/roles/mysql_server/templates/.my.cnf
deleted file mode 100644
index d5c0825..0000000
--- a/metron-deployment/roles/mysql_server/templates/.my.cnf
+++ /dev/null
@@ -1,20 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-[client]
-user=root
-password={{ mysql_root_password }}
-host=localhost
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-deployment/roles/snort/files/snort.conf
----------------------------------------------------------------------
diff --git a/metron-deployment/roles/snort/files/snort.conf b/metron-deployment/roles/snort/files/snort.conf
index 141b23b..a6edb09 100644
--- a/metron-deployment/roles/snort/files/snort.conf
+++ b/metron-deployment/roles/snort/files/snort.conf
@@ -632,7 +632,6 @@ include $RULE_PATH/community.rules
# include $RULE_PATH/server-iis.rules
# include $RULE_PATH/server-mail.rules
# include $RULE_PATH/server-mssql.rules
-# include $RULE_PATH/server-mysql.rules
# include $RULE_PATH/server-oracle.rules
# include $RULE_PATH/server-other.rules
# include $RULE_PATH/server-samba.rules
@@ -701,7 +700,6 @@ include $RULE_PATH/community.rules
# include $SO_RULE_PATH/server-apache.rules
# include $SO_RULE_PATH/server-iis.rules
# include $SO_RULE_PATH/server-mail.rules
-# include $SO_RULE_PATH/server-mysql.rules
# include $SO_RULE_PATH/server-oracle.rules
# include $SO_RULE_PATH/server-other.rules
# include $SO_RULE_PATH/server-webapp.rules
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-docker/.gitignore
----------------------------------------------------------------------
diff --git a/metron-docker/.gitignore b/metron-docker/.gitignore
index 01cfaca..6444af5 100644
--- a/metron-docker/.gitignore
+++ b/metron-docker/.gitignore
@@ -2,7 +2,6 @@
/compose/kafkazk/common
/compose/kafkazk/parser
/compose/kafkazk/enrichment
-/compose/mysql/enrichment
/compose/hbase/data-management
/compose/storm/elasticsearch
/compose/storm/enrichment
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-docker/README.md
----------------------------------------------------------------------
diff --git a/metron-docker/README.md b/metron-docker/README.md
index 6026124..25f8f82 100644
--- a/metron-docker/README.md
+++ b/metron-docker/README.md
@@ -11,7 +11,6 @@ Metron Docker includes these images that have been customized for Metron:
- Kafka (with Zookeeper)
- HBase
- Storm (with all topologies deployed)
- - MySQL
- Elasticsearch
- Kibana
@@ -65,7 +64,6 @@ metron_storm_1 Up 5 minutes
metron_hbase_1 Up 5 minutes
metron_kibana_1 Up 5 minutes
metron_kafkazk_1 Up 5 minutes
-metron_mysql_1 Up 5 minutes
metron_elasticsearch_1 Up 5 minutes
```
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-docker/compose/docker-compose.yml
----------------------------------------------------------------------
diff --git a/metron-docker/compose/docker-compose.yml b/metron-docker/compose/docker-compose.yml
index d60a5dd..8ec5573 100644
--- a/metron-docker/compose/docker-compose.yml
+++ b/metron-docker/compose/docker-compose.yml
@@ -16,15 +16,6 @@
#
version: '2'
services:
- mysql:
- build:
- context: ./mysql
- args:
- METRON_VERSION: $METRON_VERSION
- ports:
- - "3306:3306"
- environment:
- MYSQL_ROOT_PASSWORD: root
kafkazk:
build:
context: ./kafkazk
@@ -61,7 +52,6 @@ services:
volumes_from:
- hbase
depends_on:
- - mysql
- kafkazk
- hbase
- elasticsearch
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-docker/compose/mysql/Dockerfile
----------------------------------------------------------------------
diff --git a/metron-docker/compose/mysql/Dockerfile b/metron-docker/compose/mysql/Dockerfile
deleted file mode 100644
index 4634998..0000000
--- a/metron-docker/compose/mysql/Dockerfile
+++ /dev/null
@@ -1,37 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-FROM mysql:5.7
-
-ARG METRON_VERSION
-
-ENV METRON_VERSION $METRON_VERSION
-ENV METRON_HOME /usr/metron/$METRON_VERSION/
-
-ADD http://geolite.maxmind.com/download/geoip/database/GeoLiteCity_CSV/GeoLiteCity-latest.tar.xz /tmp/geoip/GeoLiteCity-latest.tar.xz
-ADD ./bin /usr/local/bin
-RUN chmod 755 /usr/local/bin/wait-for-it.sh
-ADD ./enrichment /enrichment
-
-RUN apt-get update
-RUN apt-get install xz-utils
-RUN tar xf /tmp/geoip/GeoLiteCity-latest.tar.xz -C /tmp/geoip/
-RUN cp /tmp/geoip/GeoLiteCity_*/* /var/lib/mysql-files
-RUN mkdir -p $METRON_HOME
-RUN tar -xzf /enrichment/metron-enrichment-$METRON_VERSION-archive.tar.gz -C /usr/metron/$METRON_VERSION/
-
-WORKDIR /usr/local
-CMD ./bin/start.sh
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-docker/compose/mysql/bin/init-mysql.sh
----------------------------------------------------------------------
diff --git a/metron-docker/compose/mysql/bin/init-mysql.sh b/metron-docker/compose/mysql/bin/init-mysql.sh
deleted file mode 100755
index 40f085c..0000000
--- a/metron-docker/compose/mysql/bin/init-mysql.sh
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/bin/bash
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-mysql -uroot -proot -e "CREATE DATABASE IF NOT EXISTS metronrest"
-mysql -uroot -proot < /usr/metron/$METRON_VERSION/ddl/geoip_ddl.sql
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-docker/compose/mysql/bin/start.sh
----------------------------------------------------------------------
diff --git a/metron-docker/compose/mysql/bin/start.sh b/metron-docker/compose/mysql/bin/start.sh
deleted file mode 100755
index e007ed0..0000000
--- a/metron-docker/compose/mysql/bin/start.sh
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/bin/bash
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-./bin/docker-entrypoint.sh mysqld &
-./bin/wait-for-it.sh localhost:3306
-./bin/init-mysql.sh
-tail -f /dev/null
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-docker/compose/storm/Dockerfile
----------------------------------------------------------------------
diff --git a/metron-docker/compose/storm/Dockerfile b/metron-docker/compose/storm/Dockerfile
index 75191db..4d80479 100644
--- a/metron-docker/compose/storm/Dockerfile
+++ b/metron-docker/compose/storm/Dockerfile
@@ -20,6 +20,7 @@ ARG METRON_VERSION
ENV METRON_VERSION $METRON_VERSION
ENV METRON_HOME /usr/metron/$METRON_VERSION/
+ENV GEO_DIR /apps/metron/geo/default/
ADD ./bin $METRON_HOME/bin
ADD ./parser /parser
@@ -27,13 +28,12 @@ ADD ./enrichment /enrichment
ADD ./indexing /indexing
ADD ./elasticsearch /elasticsearch
RUN mkdir -p $METRON_HOME
+RUN mkdir -p $GEO_DIR
RUN tar -xzf /parser/metron-parsers-$METRON_VERSION-archive.tar.gz -C /usr/metron/$METRON_VERSION/
RUN tar -xzf /enrichment/metron-enrichment-$METRON_VERSION-archive.tar.gz -C /usr/metron/$METRON_VERSION/
RUN sed -i -e "s/kafka.zk=.*:/kafka.zk=kafkazk:/g" /usr/metron/$METRON_VERSION/config/enrichment.properties
RUN sed -i -e "s/kafka.broker=.*/kafka.broker=kafkazk:9092/g" /usr/metron/$METRON_VERSION/config/enrichment.properties
-RUN sed -i -e "s/mysql.ip=.*/mysql.ip=mysql/g" /usr/metron/$METRON_VERSION/config/enrichment.properties
-RUN sed -i -e "s/mysql.password=.*/mysql.password=root/g" /usr/metron/$METRON_VERSION/config/enrichment.properties
RUN sed -i -e "s/threat.intel.tracker.table=.*/threat.intel.tracker.table=access_tracker/g" /usr/metron/$METRON_VERSION/config/enrichment.properties
RUN sed -i -e "s/threat.intel.tracker.cf=.*/threat.intel.tracker.cf=cf/g" /usr/metron/$METRON_VERSION/config/enrichment.properties
RUN sed -i -e "s/threat.intel.ip.table=.*/threat.intel.ip.table=ip/g" /usr/metron/$METRON_VERSION/config/enrichment.properties
@@ -55,3 +55,4 @@ EXPOSE 8080 8000
EXPOSE 8081 8081
WORKDIR $METRON_HOME
+RUN cd $GEO_DIR && wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-docker/install-metron.sh
----------------------------------------------------------------------
diff --git a/metron-docker/install-metron.sh b/metron-docker/install-metron.sh
index 7aa7e7a..adc95a0 100755
--- a/metron-docker/install-metron.sh
+++ b/metron-docker/install-metron.sh
@@ -21,14 +21,11 @@ METRON_PLATFORM_ROOT=$METRON_DOCKER_ROOT/../metron-platform
if [ $# -gt 0 ] && [ $1 == "-b" ]
then cd $METRON_PLATFORM_ROOT && mvn clean package -DskipTests
fi
-mkdir -p $METRON_DOCKER_ROOT/mysql/enrichment/
mkdir -p $METRON_DOCKER_ROOT/hbase/data-management
mkdir -p $METRON_DOCKER_ROOT/storm/parser/
mkdir -p $METRON_DOCKER_ROOT/storm/enrichment/
mkdir -p $METRON_DOCKER_ROOT/storm/indexing/
mkdir -p $METRON_DOCKER_ROOT/storm/elasticsearch/
-echo Installing MySQL dependencies
-cp $METRON_PLATFORM_ROOT/metron-enrichment/target/metron-enrichment-$METRON_VERSION-archive.tar.gz $METRON_DOCKER_ROOT/mysql/enrichment/
echo Installing HBase dependencies
cp $METRON_PLATFORM_ROOT/metron-data-management/target/metron-data-management-$METRON_VERSION-archive.tar.gz $METRON_DOCKER_ROOT/hbase/data-management
echo Installing Storm dependencies
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-docker/pom.xml
----------------------------------------------------------------------
diff --git a/metron-docker/pom.xml b/metron-docker/pom.xml
index 4c30035..5709ba1 100644
--- a/metron-docker/pom.xml
+++ b/metron-docker/pom.xml
@@ -107,24 +107,6 @@
</configuration>
</execution>
<execution>
- <id>copy-enrichment-to-mysql</id>
- <phase>prepare-package</phase>
- <goals>
- <goal>copy-resources</goal>
- </goals>
- <configuration>
- <outputDirectory>${project.basedir}/compose/mysql/enrichment</outputDirectory>
- <resources>
- <resource>
- <directory>../metron-platform/metron-enrichment/target/</directory>
- <includes>
- <include>*.tar.gz</include>
- </includes>
- </resource>
- </resources>
- </configuration>
- </execution>
- <execution>
<id>copy-parsers-to-storm</id>
<phase>prepare-package</phase>
<goals>
@@ -251,24 +233,6 @@
</resources>
</configuration>
</execution>
- <execution>
- <id>copy-wait-for-it-to-mysql</id>
- <phase>prepare-package</phase>
- <goals>
- <goal>copy-resources</goal>
- </goals>
- <configuration>
- <outputDirectory>${project.basedir}/compose/mysql/bin</outputDirectory>
- <resources>
- <resource>
- <directory>./scripts</directory>
- <includes>
- <include>wait-for-it.sh</include>
- </includes>
- </resource>
- </resources>
- </configuration>
- </execution>
</executions>
</plugin>
</plugins>
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-common/README.md
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/README.md b/metron-platform/metron-common/README.md
index 21e82fb..56932f3 100644
--- a/metron-platform/metron-common/README.md
+++ b/metron-platform/metron-common/README.md
@@ -96,6 +96,7 @@ The `!=` operator is the negation of the above.
| [ `ENRICHMENT_GET`](#enrichment_get) |
| [ `FILL_LEFT`](#fill_left) |
| [ `FILL_RIGHT`](#fill_right) |
+| [ `GEO_GET`](#geo_get) |
| [ `GET`](#get) |
| [ `GET_FIRST`](#get_first) |
| [ `GET_LAST`](#get_last) |
@@ -249,6 +250,13 @@ The `!=` operator is the negation of the above.
* column_family - The Column Family to use
* Returns: A Map associated with the indicator and enrichment type. Empty otherwise.
+### `GEO_GET`
+ * Description: Look up an IPV4 address and returns geographic information about it
+ * Input:
+ * ip - The IPV4 address to lookup
+ * fields - Optional list of GeoIP fields to grab. Options are locID, country, city postalCode, dmaCode, latitude, longitude, location_point
+ * Returns: If a Single field is requested a string of the field, If multiple fields a map of string of the fields, and null otherwise
+
### `GET`
* Description: Returns the i'th element of the list
* Input:
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-common/src/main/java/org/apache/metron/common/bolt/ConfiguredParserBolt.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/bolt/ConfiguredParserBolt.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/bolt/ConfiguredParserBolt.java
index cd379e7..15d573f 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/bolt/ConfiguredParserBolt.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/bolt/ConfiguredParserBolt.java
@@ -28,7 +28,7 @@ import java.io.IOException;
public abstract class ConfiguredParserBolt extends ConfiguredBolt<ParserConfigurations> {
- private static final Logger LOG = Logger.getLogger(ConfiguredEnrichmentBolt.class);
+ private static final Logger LOG = Logger.getLogger(ConfiguredParserBolt.class);
protected final ParserConfigurations configurations = new ParserConfigurations();
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-common/src/main/java/org/apache/metron/common/configuration/Configurations.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/configuration/Configurations.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/configuration/Configurations.java
index 8c39fab..f97e88b 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/configuration/Configurations.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/configuration/Configurations.java
@@ -27,6 +27,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -40,7 +41,7 @@ public class Configurations implements Serializable {
@SuppressWarnings("unchecked")
public Map<String, Object> getGlobalConfig() {
- return (Map<String, Object>) configurations.get(ConfigurationType.GLOBAL.getName());
+ return (Map<String, Object>) configurations.getOrDefault(ConfigurationType.GLOBAL.getName(), new HashMap());
}
public List<FieldValidator> getFieldValidations() {
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/Context.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/Context.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/Context.java
index 6195ec2..51a3f8f 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/Context.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/Context.java
@@ -34,7 +34,8 @@ public class Context implements Serializable {
, GLOBAL_CONFIG
, ZOOKEEPER_CLIENT
, SERVICE_DISCOVERER
- , STELLAR_CONFIG;
+ , STELLAR_CONFIG
+ , GEO_IP
}
public static class Builder {
@@ -98,8 +99,8 @@ public class Context implements Serializable {
if(c == null && errorIfNotThere) {
throw new IllegalStateException("Unable to find capability " + capability + "; it may not be available in your context.");
}
- else if(c == null && !errorIfNotThere) {
- return Optional.ofNullable(null);
+ else if(c == null) {
+ return Optional.empty();
}
return Optional.ofNullable(c.get());
}
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-data-management/README.md
----------------------------------------------------------------------
diff --git a/metron-platform/metron-data-management/README.md b/metron-platform/metron-data-management/README.md
index a123cc3..a0c0164 100644
--- a/metron-platform/metron-data-management/README.md
+++ b/metron-platform/metron-data-management/README.md
@@ -250,3 +250,18 @@ The parameters for the utility are as follows:
| -l | --log4j | No | The log4j properties file to load |
| -n | --enrichment_config | No | The JSON document describing the enrichments to configure. Unlike other loaders, this is run first if specified. |
+### GeoLite2 Loader
+
+The shell script `$METRON_HOME/bin/geo_enrichment_load.sh` will retrieve MaxMind GeoLite2 data and load data into HDFS, and update the configuration.
+
+THIS SCRIPT WILL NOT UPDATE AMBARI'S GLOBAL.JSON, JUST THE ZK CONFIGS. CHANGES WILL GO INTO EFFECT, BUT WILL NOT PERSIST PAST AN AMBARI RESTART UNTIL UPDATED THERE.
+
+The parameters for the utility are as follows:
+
+| Short Code | Long Code | Is Required? | Description |
+|------------|---------------------|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| -h | | No | Generate the help screen/set of options |
+| -g | --geo_url | No | GeoIP URL - defaults to http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz
+| -r | --remote_dir | No | HDFS directory to land formatted GeoIP file - defaults to /apps/metron/geo/<epoch millis>/
+| -t | --tmp_dir | No | Directory for landing the temporary GeoIP data - defaults to /tmp
+| -z | --zk_quorum | Yes | Zookeeper Quorum URL (zk1:port,zk2:port,...)
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-data-management/pom.xml
----------------------------------------------------------------------
diff --git a/metron-platform/metron-data-management/pom.xml b/metron-platform/metron-data-management/pom.xml
index 3b85e61..be7fe33 100644
--- a/metron-platform/metron-data-management/pom.xml
+++ b/metron-platform/metron-data-management/pom.xml
@@ -395,7 +395,7 @@
<shadedPattern>org.apache.metron.httpcore.dataload</shadedPattern>
</relocation>
</relocations>
- <transformers>
+ <transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
<resources>
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-data-management/src/main/java/org/apache/metron/dataloads/nonbulk/geo/GeoEnrichmentLoader.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-data-management/src/main/java/org/apache/metron/dataloads/nonbulk/geo/GeoEnrichmentLoader.java b/metron-platform/metron-data-management/src/main/java/org/apache/metron/dataloads/nonbulk/geo/GeoEnrichmentLoader.java
new file mode 100644
index 0000000..322edec
--- /dev/null
+++ b/metron-platform/metron-data-management/src/main/java/org/apache/metron/dataloads/nonbulk/geo/GeoEnrichmentLoader.java
@@ -0,0 +1,233 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.metron.dataloads.nonbulk.geo;
+
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.google.common.base.Function;
+import com.google.common.base.Joiner;
+import org.apache.commons.cli.*;
+import org.apache.commons.io.FileUtils;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.util.GenericOptionsParser;
+import org.apache.metron.common.configuration.ConfigurationsUtils;
+import org.apache.metron.common.utils.JSONUtils;
+import org.apache.metron.enrichment.adapters.geo.GeoLiteDatabase;
+
+import javax.annotation.Nullable;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+import java.util.Map;
+
+public class GeoEnrichmentLoader {
+ private static abstract class OptionHandler implements Function<String, Option> {
+ }
+
+ public enum GeoEnrichmentOptions {
+ HELP("h", new GeoEnrichmentLoader.OptionHandler() {
+ @Nullable
+ @Override
+ public Option apply(@Nullable String s) {
+ return new Option(s, "help", false, "Generate Help screen");
+ }
+ }), GEO_URL("g", new GeoEnrichmentLoader.OptionHandler() {
+ @Nullable
+ @Override
+ public Option apply(@Nullable String s) {
+ Option o = new Option(s, "geo_url", true, "GeoIP URL - defaults to http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz");
+ o.setArgName("GEO_URL");
+ o.setRequired(false);
+ return o;
+ }
+ }), REMOTE_DIR("r", new GeoEnrichmentLoader.OptionHandler() {
+ @Nullable
+ @Override
+ public Option apply(@Nullable String s) {
+ Option o = new Option(s, "remote_dir", true, "HDFS directory to land formatted GeoIP file - defaults to /apps/metron/geo/<epoch millis>/");
+ o.setArgName("REMOTE_DIR");
+ o.setRequired(false);
+ return o;
+ }
+ }), TMP_DIR("t", new GeoEnrichmentLoader.OptionHandler() {
+ @Nullable
+ @Override
+ public Option apply(@Nullable String s) {
+ Option o = new Option(s, "tmp_dir", true, "Directory for landing the temporary GeoIP data - defaults to /tmp");
+ o.setArgName("TMP_DIR");
+ o.setRequired(false);
+ return o;
+ }
+ }), ZK_QUORUM("z", new GeoEnrichmentLoader.OptionHandler() {
+ @Nullable
+ @Override
+ public Option apply(@Nullable String s) {
+ Option o = new Option(s, "zk_quorum", true, "Zookeeper Quorum URL (zk1:port,zk2:port,...)");
+ o.setArgName("ZK_QUORUM");
+ o.setRequired(true);
+ return o;
+ }
+ });
+ Option option;
+ String shortCode;
+
+ GeoEnrichmentOptions(String shortCode, GeoEnrichmentLoader.OptionHandler optionHandler) {
+ this.shortCode = shortCode;
+ this.option = optionHandler.apply(shortCode);
+ }
+
+ public boolean has(CommandLine cli) {
+ return cli.hasOption(shortCode);
+ }
+
+ public String get(CommandLine cli) {
+ return cli.getOptionValue(shortCode);
+ }
+
+ public String get(CommandLine cli, String defaultValue) {
+ return cli.getOptionValue(shortCode, defaultValue);
+ }
+
+ public static CommandLine parse(CommandLineParser parser, String[] args) {
+ try {
+ CommandLine cli = parser.parse(getOptions(), args);
+
+ if (GeoEnrichmentLoader.GeoEnrichmentOptions.HELP.has(cli)) {
+ printHelp();
+ System.exit(0);
+ }
+ return cli;
+ } catch (ParseException e) {
+ System.err.println("Unable to parse args: " + Joiner.on(' ').join(args));
+ e.printStackTrace(System.err);
+ printHelp();
+ System.exit(-1);
+ return null;
+ }
+ }
+
+ public static void printHelp() {
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printHelp("GeoEnrichmentLoader", getOptions());
+ }
+
+ public static Options getOptions() {
+ Options ret = new Options();
+ for (GeoEnrichmentLoader.GeoEnrichmentOptions o : GeoEnrichmentLoader.GeoEnrichmentOptions.values()) {
+ ret.addOption(o.option);
+ }
+ return ret;
+ }
+ }
+
+ protected void loadGeoIpDatabase(CommandLine cli) throws IOException {
+ // Retrieve the database file
+ System.out.println("Retrieving GeoLite2 archive");
+ String url = GeoEnrichmentOptions.GEO_URL.get(cli, "http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz");
+ String tmpDir = GeoEnrichmentOptions.TMP_DIR.get(cli, "/tmp") + "/"; // Make sure there's a file separator at the end
+ File localGeoFile = downloadGeoFile(url, tmpDir);
+ // Want to delete the tar in event of failure
+ localGeoFile.deleteOnExit();
+ System.out.println("GeoIP files downloaded successfully");
+
+ // Push the file to HDFS and update Configs to ensure clients get new view
+ String zookeeper = GeoEnrichmentOptions.ZK_QUORUM.get(cli);
+ long millis = LocalDateTime.now().toInstant(ZoneOffset.UTC).toEpochMilli();
+ String hdfsLoc = GeoEnrichmentOptions.REMOTE_DIR.get(cli, "/apps/metron/geo/" + millis);
+ System.out.println("Putting GeoLite2 file into HDFS at: " + hdfsLoc);
+
+ // Put into HDFS
+ Path srcPath = new Path(localGeoFile.getAbsolutePath());
+ Path dstPath = new Path(hdfsLoc);
+ putDbFile(srcPath, dstPath);
+ pushConfig(srcPath, dstPath, zookeeper);
+
+ System.out.println("GeoLite2 file placement complete");
+ System.out.println("Successfully created and updated new GeoIP information");
+ }
+
+ protected File downloadGeoFile(String urlStr, String tmpDir) {
+ File localFile = null;
+ try {
+ URL url = new URL(urlStr);
+ localFile = new File(tmpDir + new File(url.getPath()).getName());
+
+ System.out.println("Downloading " + url.toString() + " to " + localFile.getAbsolutePath());
+ if (localFile.exists() && !localFile.delete()) {
+ System.err.println("File already exists locally and can't be deleted. Please delete before continuing");
+ System.exit(3);
+ }
+ FileUtils.copyURLToFile(url, localFile, 5000, 10000);
+ } catch (MalformedURLException e) {
+ System.err.println("Malformed URL - aborting: " + e);
+ e.printStackTrace();
+ System.exit(4);
+ } catch (IOException e) {
+ System.err.println("Unable to copy remote GeoIP database to local file: " + e);
+ e.printStackTrace();
+ System.exit(5);
+ }
+ return localFile;
+ }
+
+ protected void pushConfig(Path srcPath, Path dstPath, String zookeeper) {
+ System.out.println("Beginning update of global configs");
+ try (CuratorFramework client = ConfigurationsUtils.getClient(zookeeper)) {
+ client.start();
+ // Use the parent and place a new file. Has to be a new file so we can update the configs and trigger updates.
+ // Fetch the global configuration
+ Map<String, Object> global = JSONUtils.INSTANCE.load(
+ new ByteArrayInputStream(ConfigurationsUtils.readGlobalConfigBytesFromZookeeper(client)),
+ new TypeReference<Map<String, Object>>() {
+ });
+
+ // Update the global config and push it back
+ global.put(GeoLiteDatabase.GEO_HDFS_FILE, dstPath.toString() + "/" + srcPath.getName());
+ ConfigurationsUtils.writeGlobalConfigToZookeeper(global, client);
+ } catch (Exception e) {
+ System.err.println("Unable to load new GeoIP info into HDFS: " + e);
+ e.printStackTrace();
+ System.exit(2);
+ }
+ System.out.println("Finished update of global configs");
+ }
+
+ protected void putDbFile(Path src, Path dst) throws IOException {
+ Configuration conf = new Configuration();
+ FileSystem fileSystem = FileSystem.get(conf);
+ System.out.println("Putting: " + src + " onto HDFS at: " + dst);
+ fileSystem.mkdirs(dst);
+ fileSystem.copyFromLocalFile(true, true, src, dst);
+ System.out.println("Done putting GeoLite file into HDFS");
+ }
+
+ public static void main(String... argv) throws IOException {
+ String[] otherArgs = new GenericOptionsParser(argv).getRemainingArgs();
+ CommandLine cli = GeoEnrichmentOptions.parse(new PosixParser(), otherArgs);
+
+ GeoEnrichmentLoader loader = new GeoEnrichmentLoader();
+ loader.loadGeoIpDatabase(cli);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-data-management/src/main/scripts/geo_enrichment_load.sh
----------------------------------------------------------------------
diff --git a/metron-platform/metron-data-management/src/main/scripts/geo_enrichment_load.sh b/metron-platform/metron-data-management/src/main/scripts/geo_enrichment_load.sh
new file mode 100644
index 0000000..3b6ab37
--- /dev/null
+++ b/metron-platform/metron-data-management/src/main/scripts/geo_enrichment_load.sh
@@ -0,0 +1,41 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+BIGTOP_DEFAULTS_DIR=${BIGTOP_DEFAULTS_DIR-/etc/default}
+[ -n "${BIGTOP_DEFAULTS_DIR}" -a -r ${BIGTOP_DEFAULTS_DIR}/hbase ] && . ${BIGTOP_DEFAULTS_DIR}/hbase
+
+# Autodetect JAVA_HOME if not defined
+if [ -e /usr/libexec/bigtop-detect-javahome ]; then
+ . /usr/libexec/bigtop-detect-javahome
+elif [ -e /usr/lib/bigtop-utils/bigtop-detect-javahome ]; then
+ . /usr/lib/bigtop-utils/bigtop-detect-javahome
+fi
+
+export HBASE_HOME=${HBASE_HOME:-/usr/hdp/current/hbase-client}
+HADOOP_CLASSPATH=${HBASE_HOME}/lib/hbase-server.jar:`${HBASE_HOME}/bin/hbase classpath`
+for jar in $(echo $HADOOP_CLASSPATH | sed 's/:/ /g');do
+ if [ -f $jar ];then
+ LIBJARS="$jar,$LIBJARS"
+ fi
+done
+export HADOOP_CLASSPATH
+export METRON_VERSION=${project.version}
+export METRON_HOME=/usr/metron/$METRON_VERSION
+export DM_JAR=${project.artifactId}-$METRON_VERSION.jar
+hadoop jar $METRON_HOME/lib/$DM_JAR org.apache.metron.dataloads.nonbulk.geo.GeoEnrichmentLoader "$@"
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-data-management/src/test/java/org/apache/metron/dataloads/nonbulk/geo/GeoEnrichmentLoaderTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-data-management/src/test/java/org/apache/metron/dataloads/nonbulk/geo/GeoEnrichmentLoaderTest.java b/metron-platform/metron-data-management/src/test/java/org/apache/metron/dataloads/nonbulk/geo/GeoEnrichmentLoaderTest.java
new file mode 100644
index 0000000..3fa0270
--- /dev/null
+++ b/metron-platform/metron-data-management/src/test/java/org/apache/metron/dataloads/nonbulk/geo/GeoEnrichmentLoaderTest.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.metron.dataloads.nonbulk.geo;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.PosixParser;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.util.GenericOptionsParser;
+import org.junit.*;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.File;
+
+import static org.junit.Assert.assertTrue;
+
+public class GeoEnrichmentLoaderTest {
+ private class MockGeoEnrichmentLoader extends GeoEnrichmentLoader {
+ @Override
+ protected void pushConfig(Path srcPath, Path dstPath, String zookeeper) {
+ }
+ }
+
+ @Rule
+ public TemporaryFolder testFolder = new TemporaryFolder();
+
+ private File remoteDir;
+ private File tmpDir;
+
+ @Before
+ public void setup() throws Exception {
+ testFolder.create();
+ remoteDir = testFolder.newFolder("remoteDir");
+ tmpDir = testFolder.newFolder("tmpDir");
+ }
+
+ @Test
+ public void testCommandLineShortOpts() throws Exception {
+ String[] argv = {"-g testGeoUrl", "-r /test/remoteDir", "-t /test/tmpDir", "-z test:2181"};
+ String[] otherArgs = new GenericOptionsParser(argv).getRemainingArgs();
+
+ CommandLine cli = GeoEnrichmentLoader.GeoEnrichmentOptions.parse(new PosixParser(), otherArgs);
+ Assert.assertEquals("testGeoUrl", GeoEnrichmentLoader.GeoEnrichmentOptions.GEO_URL.get(cli).trim());
+ Assert.assertEquals("/test/remoteDir", GeoEnrichmentLoader.GeoEnrichmentOptions.REMOTE_DIR.get(cli).trim());
+ Assert.assertEquals("/test/tmpDir", GeoEnrichmentLoader.GeoEnrichmentOptions.TMP_DIR.get(cli).trim());
+ Assert.assertEquals("test:2181", GeoEnrichmentLoader.GeoEnrichmentOptions.ZK_QUORUM.get(cli).trim());
+ }
+
+ @Test
+ public void testCommandLineLongOpts() throws Exception {
+ String[] argv = {"--geo_url", "testGeoUrl", "--remote_dir", "/test/remoteDir", "--tmp_dir", "/test/tmpDir", "--zk_quorum", "test:2181"};
+ String[] otherArgs = new GenericOptionsParser(argv).getRemainingArgs();
+
+ CommandLine cli = GeoEnrichmentLoader.GeoEnrichmentOptions.parse(new PosixParser(), otherArgs);
+ Assert.assertEquals("testGeoUrl", GeoEnrichmentLoader.GeoEnrichmentOptions.GEO_URL.get(cli).trim());
+ Assert.assertEquals("/test/remoteDir", GeoEnrichmentLoader.GeoEnrichmentOptions.REMOTE_DIR.get(cli).trim());
+ Assert.assertEquals("/test/tmpDir", GeoEnrichmentLoader.GeoEnrichmentOptions.TMP_DIR.get(cli).trim());
+ Assert.assertEquals("test:2181", GeoEnrichmentLoader.GeoEnrichmentOptions.ZK_QUORUM.get(cli).trim());
+ }
+
+ @Test
+ public void testLoadGeoIpDatabase() throws Exception {
+ File dbFile = new File(remoteDir.getAbsolutePath() + "/GeoEnrichmentLoaderTest.mmdb");
+ dbFile.createNewFile();
+ String[] argv = {"--geo_url", "file://" + dbFile.getAbsolutePath(), "--remote_dir", remoteDir.getAbsolutePath(), "--tmp_dir", tmpDir.getAbsolutePath(), "--zk_quorum", "test:2181"};
+ String[] otherArgs = new GenericOptionsParser(argv).getRemainingArgs();
+ CommandLine cli = GeoEnrichmentLoader.GeoEnrichmentOptions.parse(new PosixParser(), otherArgs);
+
+ GeoEnrichmentLoader loader = new MockGeoEnrichmentLoader();
+ loader.loadGeoIpDatabase(cli);
+ Configuration config = new Configuration();
+ FileSystem fs = FileSystem.get(config);
+ assertTrue(fs.exists(new Path(remoteDir + "/" + dbFile.getName())));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-enrichment/pom.xml
----------------------------------------------------------------------
diff --git a/metron-platform/metron-enrichment/pom.xml b/metron-platform/metron-enrichment/pom.xml
index 0802f47..e46ee95 100644
--- a/metron-platform/metron-enrichment/pom.xml
+++ b/metron-platform/metron-enrichment/pom.xml
@@ -24,9 +24,10 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
- <mysql.version>5.1.31</mysql.version>
<slf4j.version>1.7.7</slf4j.version>
<storm.hdfs.version>0.1.2</storm.hdfs.version>
+ <commons-compress.version>1.13</commons-compress.version>
+ <geoip.version>2.8.0</geoip.version>
<guava.version>${global_hbase_guava_version}</guava.version>
</properties>
<dependencies>
@@ -72,9 +73,9 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>${mysql.version}</version>
+ <groupId>com.maxmind.geoip2</groupId>
+ <artifactId>geoip2</artifactId>
+ <version>${geoip.version}</version>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
@@ -240,6 +241,11 @@
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-compress</artifactId>
+ <version>${commons-compress.version}</version>
+ </dependency>
</dependencies>
<reporting>
<plugins>
@@ -322,6 +328,10 @@
<pattern>com.fasterxml.jackson</pattern>
<shadedPattern>org.apache.metron.jackson</shadedPattern>
</relocation>
+ <relocation>
+ <pattern>com.google.common</pattern>
+ <shadedPattern>org.apache.metron.guava.enrichment</shadedPattern>
+ </relocation>
</relocations>
<artifactSet>
<excludes>
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-enrichment/src/main/config/enrichment.properties
----------------------------------------------------------------------
diff --git a/metron-platform/metron-enrichment/src/main/config/enrichment.properties b/metron-platform/metron-enrichment/src/main/config/enrichment.properties
index 10206ea..84d8461 100644
--- a/metron-platform/metron-enrichment/src/main/config/enrichment.properties
+++ b/metron-platform/metron-enrichment/src/main/config/enrichment.properties
@@ -23,13 +23,6 @@ enrichment.output.topic=indexing
enrichment.error.topic=enrichments_error
threat.intel.error.topic=threatintel_error
-##### MySQL #####
-
-mysql.ip=10.22.0.214
-mysql.port=3306
-mysql.username=root
-mysql.password=hadoop123
-
##### Metrics #####
#reporters
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-enrichment/src/main/flux/enrichment/remote.yaml
----------------------------------------------------------------------
diff --git a/metron-platform/metron-enrichment/src/main/flux/enrichment/remote.yaml b/metron-platform/metron-enrichment/src/main/flux/enrichment/remote.yaml
index 510bf18..054710f 100644
--- a/metron-platform/metron-enrichment/src/main/flux/enrichment/remote.yaml
+++ b/metron-platform/metron-enrichment/src/main/flux/enrichment/remote.yaml
@@ -34,25 +34,8 @@ components:
- "stellar"
- ref: "stellarEnrichmentAdapter"
- - id: "jdbcConfig"
- className: "org.apache.metron.enrichment.adapters.jdbc.MySqlConfig"
- properties:
- - name: "host"
- value: "${mysql.ip}"
- - name: "port"
- value: ${mysql.port}
- - name: "username"
- value: "${mysql.username}"
- - name: "password"
- value: "${mysql.password}"
- - name: "table"
- value: "GEO"
- id: "geoEnrichmentAdapter"
className: "org.apache.metron.enrichment.adapters.geo.GeoAdapter"
- configMethods:
- - name: "withJdbcConfig"
- args:
- - ref: "jdbcConfig"
- id: "geoEnrichment"
className: "org.apache.metron.enrichment.configuration.Enrichment"
constructorArgs:
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-enrichment/src/main/flux/enrichment/test.yaml
----------------------------------------------------------------------
diff --git a/metron-platform/metron-enrichment/src/main/flux/enrichment/test.yaml b/metron-platform/metron-enrichment/src/main/flux/enrichment/test.yaml
index f3ce2bc..077fedb 100644
--- a/metron-platform/metron-enrichment/src/main/flux/enrichment/test.yaml
+++ b/metron-platform/metron-enrichment/src/main/flux/enrichment/test.yaml
@@ -34,7 +34,7 @@ components:
- ref: "stellarEnrichmentAdapter"
- id: "geoEnrichmentAdapter"
- className: "org.apache.metron.enrichment.integration.mock.MockGeoAdapter"
+ className: "org.apache.metron.enrichment.adapters.geo.GeoAdapter"
- id: "geoEnrichment"
className: "org.apache.metron.enrichment.configuration.Enrichment"
constructorArgs:
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/cif/AbstractCIFAdapter.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/cif/AbstractCIFAdapter.java b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/cif/AbstractCIFAdapter.java
index 60ccc5e..e300e59 100644
--- a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/cif/AbstractCIFAdapter.java
+++ b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/cif/AbstractCIFAdapter.java
@@ -19,6 +19,7 @@
package org.apache.metron.enrichment.adapters.cif;
import java.io.Serializable;
+import java.util.Map;
import org.apache.metron.enrichment.bolt.CacheKey;
import org.slf4j.Logger;
@@ -36,7 +37,7 @@ public abstract class AbstractCIFAdapter implements EnrichmentAdapter<CacheKey>,
.getLogger(AbstractCIFAdapter.class);
@Override
- abstract public boolean initializeAdapter();
+ abstract public boolean initializeAdapter(Map<String, Object> config);
abstract public String enrichByIP(String metadata);
abstract public String enrichByDomain(String metadata);
abstract public String enrichByEmail(String metadata);
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/cif/CIFHbaseAdapter.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/cif/CIFHbaseAdapter.java b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/cif/CIFHbaseAdapter.java
index 4f81149..48b95da 100644
--- a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/cif/CIFHbaseAdapter.java
+++ b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/cif/CIFHbaseAdapter.java
@@ -93,7 +93,7 @@ public class CIFHbaseAdapter implements EnrichmentAdapter<CacheKey>,Serializable
}
@Override
- public boolean initializeAdapter() {
+ public boolean initializeAdapter(Map<String, Object> config) {
// Initialize HBase Table
Configuration conf = null;
@@ -117,6 +117,10 @@ public class CIFHbaseAdapter implements EnrichmentAdapter<CacheKey>,Serializable
return false;
}
+ @Override
+ public void updateAdapter(Map<String, Object> config) {
+ }
+
public String enrichByIP(String metadata) {
return null;
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/geo/GeoAdapter.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/geo/GeoAdapter.java b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/geo/GeoAdapter.java
index 9fd5d4d..afd5f97 100644
--- a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/geo/GeoAdapter.java
+++ b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/geo/GeoAdapter.java
@@ -17,71 +17,56 @@
*/
package org.apache.metron.enrichment.adapters.geo;
-import org.apache.commons.validator.routines.InetAddressValidator;
-import org.apache.metron.enrichment.adapters.jdbc.JdbcAdapter;
import org.apache.metron.enrichment.bolt.CacheKey;
+import org.apache.metron.enrichment.interfaces.EnrichmentAdapter;
import org.json.simple.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-import java.net.InetAddress;
-import java.sql.ResultSet;
-import java.sql.SQLException;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
-public class GeoAdapter extends JdbcAdapter {
-
- private InetAddressValidator ipvalidator = new InetAddressValidator();
+public class GeoAdapter implements EnrichmentAdapter<CacheKey>, Serializable {
+ protected static final Logger _LOG = LoggerFactory.getLogger(GeoAdapter.class);
@Override
public void logAccess(CacheKey value) {
-
}
@Override
- public String getOutputPrefix(CacheKey value) {
- return value.getField();
- }
+ public String getOutputPrefix(CacheKey value) {
+ return value.getField();
+ }
@SuppressWarnings("unchecked")
@Override
public JSONObject enrich(CacheKey value) {
JSONObject enriched = new JSONObject();
- if(!resetConnectionIfNecessary()) {
- _LOG.error("GEO Enrichment failure, cannot maintain a connection to JDBC. Please check connection. In the meantime, I'm not enriching.");
- return enriched;
- }
- try {
- InetAddress addr = InetAddress.getByName(value.coerceValue(String.class));
- if (addr.isAnyLocalAddress() || addr.isLoopbackAddress()
- || addr.isSiteLocalAddress() || addr.isMulticastAddress()
- || !ipvalidator.isValidInet4Address(value.coerceValue(String.class))) {
- return new JSONObject();
- }
- String locidQuery = "select IPTOLOCID(\"" + value.getValue()
- + "\") as ANS";
- ResultSet resultSet = statement.executeQuery(locidQuery);
- String locid = null;
- if (resultSet.next()) {
- locid = resultSet.getString("ANS");
- }
- resultSet.close();
- if (locid == null) return new JSONObject();
- String geoQuery = "select * from location where locID = " + locid;
- resultSet = statement.executeQuery(geoQuery);
- if (resultSet.next()) {
- enriched.put("locID", resultSet.getString("locID"));
- enriched.put("country", resultSet.getString("country"));
- enriched.put("city", resultSet.getString("city"));
- enriched.put("postalCode", resultSet.getString("postalCode"));
- enriched.put("latitude", resultSet.getString("latitude"));
- enriched.put("longitude", resultSet.getString("longitude"));
- enriched.put("dmaCode", resultSet.getString("dmaCode"));
- enriched.put("location_point", enriched.get("latitude") + "," + enriched.get("longitude"));
- }
- resultSet.close();
- } catch (Exception e) {
- _LOG.error("GEO Enrichment failure: " + e.getMessage(), e);
+ Optional<HashMap<String, String>> result = GeoLiteDatabase.INSTANCE.get(value.coerceValue(String.class));
+ if(!result.isPresent()) {
+ _LOG.error("GEO Enrichment failure: {}", value.coerceValue(String.class));
return new JSONObject();
}
- _LOG.trace("GEO Enrichment success: ", enriched);
+
+ enriched = new JSONObject(result.get());
+ _LOG.trace("GEO Enrichment success: {}", enriched);
return enriched;
}
+
+ @Override
+ public boolean initializeAdapter(Map<String, Object> config) {
+ GeoLiteDatabase.INSTANCE.update((String)config.get(GeoLiteDatabase.GEO_HDFS_FILE));
+ return true;
+ }
+
+ @Override
+ public void updateAdapter(Map<String, Object> config) {
+ GeoLiteDatabase.INSTANCE.updateIfNecessary(config);
+ }
+
+ @Override
+ public void cleanup() {
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/geo/GeoLiteDatabase.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/geo/GeoLiteDatabase.java b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/geo/GeoLiteDatabase.java
new file mode 100644
index 0000000..aa4731b
--- /dev/null
+++ b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/geo/GeoLiteDatabase.java
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.metron.enrichment.adapters.geo;
+
+import com.maxmind.db.CHMCache;
+import com.maxmind.geoip2.DatabaseReader;
+import com.maxmind.geoip2.exception.GeoIp2Exception;
+import com.maxmind.geoip2.model.CityResponse;
+import com.maxmind.geoip2.record.City;
+import com.maxmind.geoip2.record.Country;
+import com.maxmind.geoip2.record.Location;
+import com.maxmind.geoip2.record.Postal;
+import org.apache.commons.validator.routines.InetAddressValidator;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.zip.GZIPInputStream;
+
+public enum GeoLiteDatabase {
+ INSTANCE;
+
+ protected static final Logger LOG = LoggerFactory.getLogger(GeoLiteDatabase.class);
+ public static final String GEO_HDFS_FILE = "geo.hdfs.file";
+ public static final String GEO_HDFS_FILE_DEFAULT = "/apps/metron/geo/default/GeoLite2-City.mmdb.gz";
+
+ private static ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+ private static final Lock readLock = lock.readLock();
+ private static final Lock writeLock = lock.writeLock();
+ private static InetAddressValidator ipvalidator = new InetAddressValidator();
+ private static volatile String hdfsLoc = GEO_HDFS_FILE_DEFAULT;
+ private static DatabaseReader reader = null;
+
+ public synchronized void updateIfNecessary(Map<String, Object> globalConfig) {
+ // Reload database if necessary (file changes on HDFS)
+ LOG.trace("[Metron] Determining if GeoIpDatabase update required");
+ String hdfsFile = GEO_HDFS_FILE_DEFAULT;
+ if (globalConfig != null) {
+ hdfsFile = (String) globalConfig.getOrDefault(GEO_HDFS_FILE, GEO_HDFS_FILE_DEFAULT);
+ }
+
+ // Always update if we don't have a DatabaseReader
+ if (reader == null || !hdfsLoc.equals(hdfsFile)) {
+ // Update
+ hdfsLoc = hdfsFile;
+ update(hdfsFile);
+ } else {
+ LOG.trace("[Metron] Update to GeoIpDatabase unnecessary");
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void update(String hdfsFile) {
+ // If nothing is set (or it's been unset, use the defaults)
+ if (hdfsFile == null || hdfsFile.isEmpty()) {
+ LOG.debug("[Metron] Using default for {}: {}", GEO_HDFS_FILE, GEO_HDFS_FILE_DEFAULT);
+ hdfsFile = GEO_HDFS_FILE_DEFAULT;
+ }
+
+ FileSystem fs;
+ try {
+ fs = FileSystem.get(new Configuration());
+ } catch (IOException e) {
+ LOG.error("[Metron] Unable to retrieve get HDFS FileSystem");
+ throw new IllegalStateException("[Metron] Unable to get HDFS FileSystem");
+ }
+
+ try (GZIPInputStream gis = new GZIPInputStream(fs.open(new Path(hdfsFile)))) {
+ writeLock.lock();
+ LOG.info("[Metron] Update to GeoIP data started with {}", hdfsFile);
+ // InputStream based DatabaseReaders are always in memory.
+ DatabaseReader newReader = new DatabaseReader.Builder(gis).withCache(new CHMCache()).build();
+ DatabaseReader oldReader = reader;
+ reader = newReader;
+ // If we've never set a reader, don't close the old one
+ if (oldReader != null) {
+ oldReader.close();
+ }
+ LOG.info("[Metron] Finished update to GeoIP data started with {}", hdfsFile);
+ } catch (IOException e) {
+ LOG.error("[Metron] Unable to open new database file {}", hdfsFile, e);
+ throw new IllegalStateException("[Metron] Unable to update MaxMind database");
+ } finally {
+ // Don't unlock if the try failed
+ if (lock.isWriteLocked()) {
+ writeLock.unlock();
+ }
+ }
+ }
+
+ // Optional.empty means that we don't have any geo location in database.
+ // Optional exists, but empty means local IP (valid, but no info will be in the DB)
+ @SuppressWarnings("unchecked")
+ public Optional<HashMap<String, String>> get(String ip) {
+ // Call get every single time, returns current version. Updates behind the scenes.
+ LOG.trace("[Metron] Called GeoIpDatabase.get({})", ip);
+ InetAddress addr = null;
+ try {
+ addr = InetAddress.getByName(ip);
+ } catch (UnknownHostException e) {
+ LOG.warn("[Metron] No result found for IP {}", ip, e);
+ return Optional.empty();
+ }
+ if (isIneligibleAddress(ip, addr)) {
+ return Optional.of(new HashMap());
+ }
+
+ try {
+ readLock.lock();
+ addr = InetAddress.getByName(ip);
+ CityResponse cityResponse = reader.city(addr);
+ HashMap<String, String> geoInfo = new HashMap<>();
+
+ Country country = cityResponse.getCountry();
+ City city = cityResponse.getCity();
+ Postal postal = cityResponse.getPostal();
+ Location location = cityResponse.getLocation();
+
+ geoInfo.put("locID", convertNullToEmptyString(country.getGeoNameId()));
+ geoInfo.put("country", convertNullToEmptyString(country.getIsoCode()));
+ geoInfo.put("city", convertNullToEmptyString(city.getName()));
+ geoInfo.put("postalCode", convertNullToEmptyString(postal.getCode()));
+ geoInfo.put("dmaCode", convertNullToEmptyString(location.getMetroCode()));
+
+ Double latitudeRaw = location.getLatitude();
+ String latitude = convertNullToEmptyString(latitudeRaw);
+ geoInfo.put("latitude", latitude);
+
+ Double longitudeRaw = location.getLongitude();
+ String longitude = convertNullToEmptyString(longitudeRaw);
+ geoInfo.put("longitude", longitude);
+
+ if (latitudeRaw == null || longitudeRaw == null) {
+ geoInfo.put("location_point", "");
+ } else {
+ geoInfo.put("location_point", latitude + "," + longitude);
+ }
+
+ return Optional.of(geoInfo);
+ } catch (UnknownHostException e) {
+ LOG.warn("[Metron] No result found for IP {}", ip);
+ } catch (GeoIp2Exception | IOException e) {
+ LOG.warn("[Metron] GeoLite2 DB encountered an error", e);
+ } finally {
+ readLock.unlock();
+ }
+ return Optional.empty();
+ }
+
+ protected String convertNullToEmptyString(Object raw) {
+ return raw == null ? "" : String.valueOf(raw);
+ }
+
+ private boolean isIneligibleAddress(String ipStr, InetAddress addr) {
+ return addr.isAnyLocalAddress() || addr.isLoopbackAddress()
+ || addr.isSiteLocalAddress() || addr.isMulticastAddress()
+ || !ipvalidator.isValidInet4Address(ipStr);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/host/AbstractHostAdapter.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/host/AbstractHostAdapter.java b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/host/AbstractHostAdapter.java
index 9432613..2b076ee 100644
--- a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/host/AbstractHostAdapter.java
+++ b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/host/AbstractHostAdapter.java
@@ -19,6 +19,7 @@
package org.apache.metron.enrichment.adapters.host;
import java.io.Serializable;
+import java.util.Map;
import org.apache.metron.enrichment.bolt.CacheKey;
import org.json.simple.JSONObject;
@@ -38,7 +39,7 @@ public abstract class AbstractHostAdapter implements EnrichmentAdapter<CacheKey>
.getLogger(AbstractHostAdapter.class);
@Override
- abstract public boolean initializeAdapter();
+ abstract public boolean initializeAdapter(Map<String, Object> config);
@Override
abstract public JSONObject enrich(CacheKey metadata);
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/host/HostFromJSONListAdapter.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/host/HostFromJSONListAdapter.java b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/host/HostFromJSONListAdapter.java
index 8c8628a..779f66b 100644
--- a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/host/HostFromJSONListAdapter.java
+++ b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/host/HostFromJSONListAdapter.java
@@ -46,7 +46,7 @@ public class HostFromJSONListAdapter extends AbstractHostAdapter {
}
@Override
- public boolean initializeAdapter()
+ public boolean initializeAdapter(Map<String, Object> config)
{
if(_known_hosts.size() > 0)
@@ -56,6 +56,10 @@ public class HostFromJSONListAdapter extends AbstractHostAdapter {
}
@Override
+ public void updateAdapter(Map<String, Object> config) {
+ }
+
+ @Override
public void logAccess(CacheKey value) {
}
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/host/HostFromPropertiesFileAdapter.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/host/HostFromPropertiesFileAdapter.java b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/host/HostFromPropertiesFileAdapter.java
index 0555c1a..83d92e1 100644
--- a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/host/HostFromPropertiesFileAdapter.java
+++ b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/host/HostFromPropertiesFileAdapter.java
@@ -34,7 +34,7 @@ public class HostFromPropertiesFileAdapter extends AbstractHostAdapter {
}
@Override
- public boolean initializeAdapter()
+ public boolean initializeAdapter(Map<String, Object> config)
{
if(_known_hosts.size() > 0)
@@ -44,6 +44,10 @@ public class HostFromPropertiesFileAdapter extends AbstractHostAdapter {
}
@Override
+ public void updateAdapter(Map<String, Object> config) {
+ }
+
+ @Override
public String getOutputPrefix(CacheKey value) {
return value.getField();
}
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/jdbc/JdbcAdapter.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/jdbc/JdbcAdapter.java b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/jdbc/JdbcAdapter.java
index 708eb67..9eddc04 100644
--- a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/jdbc/JdbcAdapter.java
+++ b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/jdbc/JdbcAdapter.java
@@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory;
import java.io.Serializable;
import java.net.InetAddress;
import java.sql.*;
+import java.util.Map;
public abstract class JdbcAdapter implements EnrichmentAdapter<CacheKey>, Serializable {
@@ -53,7 +54,7 @@ public abstract class JdbcAdapter implements EnrichmentAdapter<CacheKey>, Serial
protected boolean resetConnectionIfNecessary() {
if(isConnectionClosed()) {
this.cleanup();
- return this.initializeAdapter();
+ return this.initializeAdapter(null);
}
return true;
}
@@ -69,7 +70,7 @@ public abstract class JdbcAdapter implements EnrichmentAdapter<CacheKey>, Serial
@Override
- public boolean initializeAdapter() {
+ public boolean initializeAdapter(Map<String, Object> config) {
try {
if (!InetAddress.getByName(host).isReachable(500)) {
throw new Exception("Unable to reach host " + host);
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/simplehbase/SimpleHBaseAdapter.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/simplehbase/SimpleHBaseAdapter.java b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/simplehbase/SimpleHBaseAdapter.java
index eae2e85..0ef51f8 100644
--- a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/simplehbase/SimpleHBaseAdapter.java
+++ b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/simplehbase/SimpleHBaseAdapter.java
@@ -67,7 +67,7 @@ public class SimpleHBaseAdapter implements EnrichmentAdapter<CacheKey>,Serializa
public JSONObject enrich(CacheKey value) {
JSONObject enriched = new JSONObject();
if(!isInitialized()) {
- initializeAdapter();
+ initializeAdapter(null);
}
List<String> enrichmentTypes = value.getConfig()
.getEnrichment().getFieldToTypeMap()
@@ -95,7 +95,7 @@ public class SimpleHBaseAdapter implements EnrichmentAdapter<CacheKey>,Serializa
}
catch (IOException e) {
_LOG.error("Unable to retrieve value: " + e.getMessage(), e);
- initializeAdapter();
+ initializeAdapter(null);
throw new RuntimeException("Unable to retrieve value: " + e.getMessage(), e);
}
}
@@ -104,7 +104,7 @@ public class SimpleHBaseAdapter implements EnrichmentAdapter<CacheKey>,Serializa
}
@Override
- public boolean initializeAdapter() {
+ public boolean initializeAdapter(Map<String, Object> configuration) {
String hbaseTable = config.getHBaseTable();
Configuration hbaseConfig = HBaseConfiguration.create();
try {
@@ -120,6 +120,10 @@ public class SimpleHBaseAdapter implements EnrichmentAdapter<CacheKey>,Serializa
}
@Override
+ public void updateAdapter(Map<String, Object> config) {
+ }
+
+ @Override
public void cleanup() {
try {
lookup.close();
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/stellar/StellarAdapter.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/stellar/StellarAdapter.java b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/stellar/StellarAdapter.java
index 4950ddb..bc5f2b6 100644
--- a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/stellar/StellarAdapter.java
+++ b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/stellar/StellarAdapter.java
@@ -112,12 +112,16 @@ public class StellarAdapter implements EnrichmentAdapter<CacheKey>,Serializable
}
@Override
- public boolean initializeAdapter() {
+ public boolean initializeAdapter(Map<String, Object> config) {
getHandler = EnrichmentType.valueOf(enrichmentType);
return true;
}
@Override
+ public void updateAdapter(Map<String, Object> config) {
+ }
+
+ @Override
public void cleanup() {
}
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/threatintel/ThreatIntelAdapter.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/threatintel/ThreatIntelAdapter.java b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/threatintel/ThreatIntelAdapter.java
index 05ac038..e4ab7b1 100644
--- a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/threatintel/ThreatIntelAdapter.java
+++ b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/threatintel/ThreatIntelAdapter.java
@@ -34,6 +34,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
+import java.util.Map;
import java.util.UUID;
public class ThreatIntelAdapter implements EnrichmentAdapter<CacheKey>,Serializable {
@@ -66,7 +67,7 @@ public class ThreatIntelAdapter implements EnrichmentAdapter<CacheKey>,Serializa
@Override
public JSONObject enrich(CacheKey value) {
if(!isInitialized()) {
- initializeAdapter();
+ initializeAdapter(null);
}
JSONObject enriched = new JSONObject();
List<String> enrichmentTypes = value.getConfig()
@@ -95,7 +96,7 @@ public class ThreatIntelAdapter implements EnrichmentAdapter<CacheKey>,Serializa
}
catch(IOException e) {
_LOG.error("Unable to retrieve value: " + e.getMessage(), e);
- initializeAdapter();
+ initializeAdapter(null);
throw new RuntimeException("Theat Intel Unable to retrieve value", e);
}
}
@@ -108,7 +109,7 @@ public class ThreatIntelAdapter implements EnrichmentAdapter<CacheKey>,Serializa
}
@Override
- public boolean initializeAdapter() {
+ public boolean initializeAdapter(Map<String, Object> configuration) {
PersistentAccessTracker accessTracker;
String hbaseTable = config.getHBaseTable();
int expectedInsertions = config.getExpectedInsertions();
@@ -136,6 +137,10 @@ public class ThreatIntelAdapter implements EnrichmentAdapter<CacheKey>,Serializa
}
@Override
+ public void updateAdapter(Map<String, Object> config) {
+ }
+
+ @Override
public void cleanup() {
try {
lookup.close();
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/bolt/GenericEnrichmentBolt.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/bolt/GenericEnrichmentBolt.java b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/bolt/GenericEnrichmentBolt.java
index 0ecc6b4..f3ed5b4 100644
--- a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/bolt/GenericEnrichmentBolt.java
+++ b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/bolt/GenericEnrichmentBolt.java
@@ -118,6 +118,7 @@ public class GenericEnrichmentBolt extends ConfiguredEnrichmentBolt {
return this;
}
+
@Override
public void reloadCallback(String name, ConfigurationType type) {
if(invalidateCacheOnReload) {
@@ -125,6 +126,9 @@ public class GenericEnrichmentBolt extends ConfiguredEnrichmentBolt {
cache.invalidateAll();
}
}
+ if(type == ConfigurationType.GLOBAL) {
+ adapter.updateAdapter(getConfigurations().getGlobalConfig());
+ }
}
@Override
@@ -147,9 +151,9 @@ public class GenericEnrichmentBolt extends ConfiguredEnrichmentBolt {
cache = CacheBuilder.newBuilder().maximumSize(maxCacheSize)
.expireAfterWrite(maxTimeRetain, TimeUnit.MINUTES)
.build(loader);
- boolean success = adapter.initializeAdapter();
+ boolean success = adapter.initializeAdapter(getConfigurations().getGlobalConfig());
if (!success) {
- LOG.error("[Metron] EnrichmentSplitterBolt could not initialize adapter");
+ LOG.error("[Metron] GenericEnrichmentBolt could not initialize adapter");
throw new IllegalStateException("Could not initialize adapter...");
}
initializeStellar();
@@ -238,7 +242,7 @@ public class GenericEnrichmentBolt extends ConfiguredEnrichmentBolt {
enrichedMessage.put("adapter." + adapter.getClass().getSimpleName().toLowerCase() + ".end.ts", "" + System.currentTimeMillis());
if(error) {
- throw new Exception("Unable to enrich " + enrichedMessage + " check logs for specifics.");
+ throw new Exception("Unable to enrich " + rawMessage + " check logs for specifics.");
}
if (!enrichedMessage.isEmpty()) {
collector.emit(enrichmentType, new Values(key, enrichedMessage, subGroup));
@@ -259,10 +263,6 @@ public class GenericEnrichmentBolt extends ConfiguredEnrichmentBolt {
collector.emit(ERROR_STREAM, new Values(error));
}
- protected void handleError() {
-
- }
-
@Override
public void cleanup() {
adapter.cleanup();
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/bolt/ThreatIntelJoinBolt.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/bolt/ThreatIntelJoinBolt.java b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/bolt/ThreatIntelJoinBolt.java
index ee67f83..6d0ea44 100644
--- a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/bolt/ThreatIntelJoinBolt.java
+++ b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/bolt/ThreatIntelJoinBolt.java
@@ -17,6 +17,8 @@
*/
package org.apache.metron.enrichment.bolt;
+import org.apache.metron.common.configuration.ConfigurationType;
+import org.apache.metron.enrichment.adapters.geo.GeoLiteDatabase;
import org.apache.storm.task.TopologyContext;
import com.google.common.base.Joiner;
import org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig;
@@ -63,12 +65,14 @@ public class ThreatIntelJoinBolt extends EnrichmentJoinBolt {
@Override
public void prepare(Map map, TopologyContext topologyContext) {
super.prepare(map, topologyContext);
+ GeoLiteDatabase.INSTANCE.update((String)getConfigurations().getGlobalConfig().get(GeoLiteDatabase.GEO_HDFS_FILE));
initializeStellar();
}
protected void initializeStellar() {
this.stellarContext = new Context.Builder()
.with(Context.Capabilities.ZOOKEEPER_CLIENT, () -> client)
+ .with(Context.Capabilities.GLOBAL_CONFIG, () -> getConfigurations().getGlobalConfig())
.build();
StellarFunctions.initialize(stellarContext);
this.functionResolver = StellarFunctions.FUNCTION_RESOLVER();
@@ -147,4 +151,12 @@ public class ThreatIntelJoinBolt extends EnrichmentJoinBolt {
return ret;
}
+
+ @Override
+ public void reloadCallback(String name, ConfigurationType type) {
+ super.reloadCallback(name, type);
+ if(type == ConfigurationType.GLOBAL) {
+ GeoLiteDatabase.INSTANCE.updateIfNecessary(getConfigurations().getGlobalConfig());
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/fa6f3df5/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/interfaces/EnrichmentAdapter.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/interfaces/EnrichmentAdapter.java b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/interfaces/EnrichmentAdapter.java
index c2682bc..1ee6ade 100644
--- a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/interfaces/EnrichmentAdapter.java
+++ b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/interfaces/EnrichmentAdapter.java
@@ -18,14 +18,16 @@
package org.apache.metron.enrichment.interfaces;
-import org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig;
import org.json.simple.JSONObject;
+import java.util.Map;
+
public interface EnrichmentAdapter<T>
{
void logAccess(T value);
JSONObject enrich(T value);
- boolean initializeAdapter();
+ boolean initializeAdapter(Map<String, Object> config);
+ void updateAdapter(Map<String, Object> config);
void cleanup();
String getOutputPrefix(T value);
default String getStreamSubGroup(String enrichmentType, String field) {