karaf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (KARAF-5792) Support add, rename, remove to the custom fields of Decanter collectors
Date Wed, 05 Sep 2018 19:57:01 GMT

    [ https://issues.apache.org/jira/browse/KARAF-5792?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16604854#comment-16604854 ] 

ASF GitHub Bot commented on KARAF-5792:
---------------------------------------

fpapon closed pull request #42: [KARAF-5792] Add support of add/rename/remove of properties in all collectors
URL: https://github.com/apache/karaf-decanter/pull/42
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/collector/eventadmin/pom.xml b/collector/eventadmin/pom.xml
index 501e720..a77594b 100644
--- a/collector/eventadmin/pom.xml
+++ b/collector/eventadmin/pom.xml
@@ -33,8 +33,36 @@
     <packaging>bundle</packaging>
     <name>Apache Karaf :: Decanter :: Collector :: EventAdmin</name>
 
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.karaf.decanter.collector</groupId>
+            <artifactId>org.apache.karaf.decanter.collector.utils</artifactId>
+        </dependency>
+    </dependencies>
+
     <build>
         <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <inherited>true</inherited>
+                <extensions>true</extensions>
+                <configuration>
+                    <obrRepository>NONE</obrRepository>
+                    <instructions>
+                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+                        <Export-Package>!*</Export-Package>
+                        <Import-Package>
+                            *
+                        </Import-Package>
+                        <Private-Package>
+                            org.apache.karaf.decanter.collector.eventadmin,
+                            org.apache.karaf.decanter.collector.utils
+                        </Private-Package>
+                        <_dsannotations>*</_dsannotations>
+                    </instructions>
+                </configuration>
+            </plugin>
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>build-helper-maven-plugin</artifactId>
diff --git a/collector/eventadmin/src/main/java/org/apache/karaf/decanter/collector/eventadmin/EventCollector.java b/collector/eventadmin/src/main/java/org/apache/karaf/decanter/collector/eventadmin/EventCollector.java
index 77c7312..f23e651 100644
--- a/collector/eventadmin/src/main/java/org/apache/karaf/decanter/collector/eventadmin/EventCollector.java
+++ b/collector/eventadmin/src/main/java/org/apache/karaf/decanter/collector/eventadmin/EventCollector.java
@@ -16,6 +16,7 @@
  */
 package org.apache.karaf.decanter.collector.eventadmin;
 
+import org.apache.karaf.decanter.collector.utils.PropertiesPreparator;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
@@ -25,7 +26,6 @@
 import org.osgi.service.event.EventHandler;
 
 import javax.security.auth.Subject;
-import java.net.InetAddress;
 import java.security.Principal;
 import java.util.*;
 
@@ -50,23 +50,6 @@ public void handleEvent(Event event) {
         String topic = event.getTopic();
         Map<String, Object> data = new HashMap<>();
         data.put("type", "eventadmin");
-        String karafName = System.getProperty("karaf.name");
-        if (karafName != null) {
-            data.put("karafName", karafName);
-        }
-        try {
-            data.put("hostAddress", InetAddress.getLocalHost().getHostAddress());
-            data.put("hostName", InetAddress.getLocalHost().getHostName());
-        } catch (Exception e) {
-            // nothing to do
-        }
-
-        // custom fields
-        Enumeration<String> keys = properties.keys();
-        while (keys.hasMoreElements()) {
-            String key = keys.nextElement();
-            data.put(key, properties.get(key));
-        }
 
         for (String property : event.getPropertyNames()) {
             if (property.equals("type")) {
@@ -83,6 +66,13 @@ public void handleEvent(Event event) {
                 data.put(property, event.getProperty(property));
             }
         }
+
+        try {
+            PropertiesPreparator.prepare(data, properties);
+        } catch (Exception e) {
+            // nothing to do
+        }
+
         Event bridge = new Event("decanter/collect/eventadmin/" + topic, data);
         dispatcher.sendEvent(bridge);
     }
diff --git a/collector/file/pom.xml b/collector/file/pom.xml
index b09f800..37ab46a 100644
--- a/collector/file/pom.xml
+++ b/collector/file/pom.xml
@@ -39,6 +39,36 @@
             <artifactId>commons-io</artifactId>
             <version>2.6</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.karaf.decanter.collector</groupId>
+            <artifactId>org.apache.karaf.decanter.collector.utils</artifactId>
+        </dependency>
     </dependencies>
 
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <inherited>true</inherited>
+                <extensions>true</extensions>
+                <configuration>
+                    <obrRepository>NONE</obrRepository>
+                    <instructions>
+                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+                        <Export-Package>!*</Export-Package>
+                        <Import-Package>
+                            *
+                        </Import-Package>
+                        <Private-Package>
+                            org.apache.karaf.decanter.collector.file,
+                            org.apache.karaf.decanter.collector.utils
+                        </Private-Package>
+                        <_dsannotations>*</_dsannotations>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
 </project>
\ No newline at end of file
diff --git a/collector/file/src/main/java/org/apache/karaf/decanter/collector/file/DecanterTailerListener.java b/collector/file/src/main/java/org/apache/karaf/decanter/collector/file/DecanterTailerListener.java
index a6db6dd..098ae6d 100644
--- a/collector/file/src/main/java/org/apache/karaf/decanter/collector/file/DecanterTailerListener.java
+++ b/collector/file/src/main/java/org/apache/karaf/decanter/collector/file/DecanterTailerListener.java
@@ -17,18 +17,15 @@
 package org.apache.karaf.decanter.collector.file;
 
 import java.io.File;
-import java.net.InetAddress;
 import java.util.Dictionary;
-import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.concurrent.Executor;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
-import java.util.concurrent.ThreadPoolExecutor;
 
 import org.apache.commons.io.input.Tailer;
 import org.apache.commons.io.input.TailerListenerAdapter;
+import org.apache.karaf.decanter.collector.utils.PropertiesPreparator;
 import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.component.annotations.Activate;
@@ -94,36 +91,20 @@ public void handle(String line) {
         Map<String, Object> data = new HashMap<>();
         data.put("type", type);
         data.put("path", path);
-        String karafName = System.getProperty("karaf.name");
-        if (karafName != null) {
-            data.put("karafName", karafName);
-        }
+
+        // TODO: try some line parsing
+        data.put("line", line);
 
         try {
-            data.put("hostAddress", InetAddress.getLocalHost().getHostAddress());
-            data.put("hostName", InetAddress.getLocalHost().getHostName());
+            PropertiesPreparator.prepare(data, properties);
         } catch (Exception e) {
-            LOGGER.debug("Can't get host address and name", e);
+            LOGGER.warn("Can't fully prepare data for the dispatcher", e);
         }
 
-        // custom fields
-        addPropertiesTo(data);
-
-        // TODO: try some line parsing
-        data.put("line", line);
-
         Event event = new Event("decanter/collect/file/" + type, data);
         dispatcher.postEvent(event);
     }
 
-    private void addPropertiesTo(Map<String, Object> data) {
-        Enumeration<String> keys = properties.keys();
-        while (keys.hasMoreElements()) {
-            String key = keys.nextElement();
-            data.put(key, properties.get(key));
-        }
-    }
-
     @Override
     public void handle(Exception e) {
         LOGGER.warn("Handle exception on file {}", path, e);
diff --git a/collector/jms/pom.xml b/collector/jms/pom.xml
index 892cb1a..2f5c55d 100644
--- a/collector/jms/pom.xml
+++ b/collector/jms/pom.xml
@@ -43,6 +43,10 @@
             <artifactId>geronimo-jms_1.1_spec</artifactId>
             <version>1.1.1</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.karaf.decanter.collector</groupId>
+            <artifactId>org.apache.karaf.decanter.collector.utils</artifactId>
+        </dependency>
 
         <!-- test -->
         <dependency>
@@ -85,7 +89,8 @@
                             *
                         </Import-Package>
                         <Private-Package>
-                            org.apache.karaf.decanter.collector.jms
+                            org.apache.karaf.decanter.collector.jms,
+                            org.apache.karaf.decanter.collector.utils
                         </Private-Package>
                         <_dsannotations>*</_dsannotations>
                         <_dsannotations-options>nocapabilities,norequirements</_dsannotations-options>
diff --git a/collector/jms/src/main/java/org/apache/karaf/decanter/collector/jms/JmsCollector.java b/collector/jms/src/main/java/org/apache/karaf/decanter/collector/jms/JmsCollector.java
index 47acf2d..356157a 100644
--- a/collector/jms/src/main/java/org/apache/karaf/decanter/collector/jms/JmsCollector.java
+++ b/collector/jms/src/main/java/org/apache/karaf/decanter/collector/jms/JmsCollector.java
@@ -17,6 +17,7 @@
 package org.apache.karaf.decanter.collector.jms;
 
 import org.apache.karaf.decanter.api.marshaller.Unmarshaller;
+import org.apache.karaf.decanter.collector.utils.PropertiesPreparator;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
@@ -30,7 +31,6 @@
 
 import javax.jms.*;
 import java.io.ByteArrayInputStream;
-import java.net.InetAddress;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.HashMap;
@@ -144,20 +144,7 @@ public void onMessage(Message message) {
 
                 try {
                     Map<String, Object> data = new HashMap<>();
-
-                    try {
-                        data.put("hostAddress", InetAddress.getLocalHost().getHostAddress());
-                        data.put("hostName", InetAddress.getLocalHost().getHostName());
-                    } catch (Exception e) {
-                        LOGGER.warn("Can't populate local host name and address", e);
-                    }
-
-                    // custom fields
-                    Enumeration<String> keys = properties.keys();
-                    while (keys.hasMoreElements()) {
-                        String key = keys.nextElement();
-                        data.put(key, properties.get(key));
-                    }
+                    data.put("type", "jms");
 
                     Enumeration names = mapMessage.getMapNames();
                     while (names.hasMoreElements()) {
@@ -165,11 +152,7 @@ public void onMessage(Message message) {
                         data.put(name, mapMessage.getObject(name));
                     }
 
-                    data.put("type", "jms");
-                    String karafName = System.getProperty("karaf.name");
-                    if (karafName != null) {
-                        data.put("karafName", karafName);
-                    }
+                    PropertiesPreparator.prepare(data, properties);
 
                     Event event = new Event(dispatcherTopic, data);
                     dispatcher.postEvent(event);
@@ -182,29 +165,12 @@ public void onMessage(Message message) {
 
                 try {
                     Map<String, Object> data = new HashMap<>();
-
-                    try {
-                        data.put("hostAddress", InetAddress.getLocalHost().getHostAddress());
-                        data.put("hostName", InetAddress.getLocalHost().getHostName());
-                    } catch (Exception e) {
-                        LOGGER.warn("Can't populate local host name and address", e);
-                    }
-
-                    // custom fields
-                    Enumeration<String> keys = properties.keys();
-                    while (keys.hasMoreElements()) {
-                        String key = keys.nextElement();
-                        data.put(key, properties.get(key));
-                    }
+                    data.put("type", "jms");
 
                     ByteArrayInputStream is = new ByteArrayInputStream(textMessage.getText().getBytes());
                     data.putAll(unmarshaller.unmarshal(is));
 
-                    data.put("type", "jms");
-                    String karafName = System.getProperty("karaf.name");
-                    if (karafName != null) {
-                        data.put("karafName", karafName);
-                    }
+                    PropertiesPreparator.prepare(data, properties);
 
                     Event event = new Event(dispatcherTopic, data);
                     dispatcher.postEvent(event);
diff --git a/collector/jmx/pom.xml b/collector/jmx/pom.xml
index 8c3c3bb..ad39042 100644
--- a/collector/jmx/pom.xml
+++ b/collector/jmx/pom.xml
@@ -34,6 +34,12 @@
     <name>Apache Karaf :: Decanter :: Collector :: JMX</name>
 
     <dependencies>
+        <dependency>
+            <groupId>org.apache.karaf.decanter.collector</groupId>
+            <artifactId>org.apache.karaf.decanter.collector.utils</artifactId>
+        </dependency>
+
+        <!-- test -->
     	<dependency>
 			<groupId>org.mockito</groupId>
 			<artifactId>mockito-core</artifactId>
@@ -50,6 +56,27 @@
 
     <build>
         <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <inherited>true</inherited>
+                <extensions>true</extensions>
+                <configuration>
+                    <obrRepository>NONE</obrRepository>
+                    <instructions>
+                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+                        <Export-Package>!*</Export-Package>
+                        <Import-Package>
+                            *
+                        </Import-Package>
+                        <Private-Package>
+                            org.apache.karaf.decanter.collector.jmx,
+                            org.apache.karaf.decanter.collector.utils
+                        </Private-Package>
+                        <_dsannotations>*</_dsannotations>
+                    </instructions>
+                </configuration>
+            </plugin>
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>build-helper-maven-plugin</artifactId>
diff --git a/collector/jmx/src/main/java/org/apache/karaf/decanter/collector/jmx/BeanHarvester.java b/collector/jmx/src/main/java/org/apache/karaf/decanter/collector/jmx/BeanHarvester.java
index 30322ef..614d740 100644
--- a/collector/jmx/src/main/java/org/apache/karaf/decanter/collector/jmx/BeanHarvester.java
+++ b/collector/jmx/src/main/java/org/apache/karaf/decanter/collector/jmx/BeanHarvester.java
@@ -16,7 +16,6 @@
  */
 package org.apache.karaf.decanter.collector.jmx;
 
-import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -43,23 +42,10 @@
 
     private MBeanServerConnection connection;
     private String type;
-    private String hostName;
-    private String hostAddress;
-    private String karafName;
     
-    BeanHarvester(MBeanServerConnection connection, String type, String hostName, String karafName) throws UnknownHostException {
+    BeanHarvester(MBeanServerConnection connection, String type) throws UnknownHostException {
         this.connection = connection;
         this.type = type;
-        this.hostName = hostName;
-        if (hostName == null || hostName.isEmpty()) {
-            this.karafName = karafName;
-            this.hostAddress = InetAddress.getLocalHost().getHostAddress();
-            this.hostName =InetAddress.getLocalHost().getHostName();
-        } else {
-            this.karafName = null;
-            this.hostAddress = null;
-            this.hostName = hostName;
-        }
     }
 
     Map<String, Object> harvestBean(ObjectName name) throws Exception {
@@ -68,13 +54,6 @@
         Map<String, Object> data = new HashMap<>();
         data.put("type", type);
         data.put("ObjectName", name.toString());
-        if (this.karafName != null) {
-            data.put("karafName", this.karafName);
-        }
-        if (this.hostAddress != null) {
-            data.put("hostAddress", this.hostAddress);
-        }
-        data.put("hostName", hostName);
 
         for (MBeanAttributeInfo attribute : attributes) {
             try {
diff --git a/collector/jmx/src/main/java/org/apache/karaf/decanter/collector/jmx/JmxCollector.java b/collector/jmx/src/main/java/org/apache/karaf/decanter/collector/jmx/JmxCollector.java
index c74ffdc..7930812 100644
--- a/collector/jmx/src/main/java/org/apache/karaf/decanter/collector/jmx/JmxCollector.java
+++ b/collector/jmx/src/main/java/org/apache/karaf/decanter/collector/jmx/JmxCollector.java
@@ -32,6 +32,7 @@
 import javax.management.remote.JMXConnectorFactory;
 import javax.management.remote.JMXServiceURL;
 
+import org.apache.karaf.decanter.collector.utils.PropertiesPreparator;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Reference;
@@ -128,9 +129,8 @@ public void run() {
 
         String currentObjectName = null;
         try {
-            String karafName = System.getProperty("karaf.name");
             LOGGER.debug("Creating harvester");
-            BeanHarvester harvester = new BeanHarvester(connection, this.type, host, karafName);
+            BeanHarvester harvester = new BeanHarvester(connection, this.type);
 
             LOGGER.debug("Populating names ({})", this.objectNames);
             Set<ObjectName> names = new HashSet<> ();
@@ -148,7 +148,8 @@ public void run() {
                 LOGGER.debug("Harvesting {}", name);
                 try {
                     Map<String, Object> data = harvester.harvestBean(name);
-                    addUserProperties(data);
+                    PropertiesPreparator.prepare(data, properties);
+                    data.put("host", host);
                     Event event = new Event("decanter/collect/jmx/" + this.type + "/" + getTopic(name), data);
                     LOGGER.debug("Posting for {}", name);
                     this.dispatcher.postEvent(event);
@@ -180,16 +181,6 @@ public void run() {
         return env;
     }
 
-    private void addUserProperties(Map<String, Object> data) {
-        if (this.properties != null) {
-            Enumeration<String> keys = this.properties.keys();
-            while (keys.hasMoreElements()) {
-                String property = keys.nextElement();
-                data.put(property, this.properties.get(property));
-            }
-        }
-    }
-
     private ObjectName getObjectName(String objectName) throws MalformedObjectNameException {
         return objectName == null ? null : new ObjectName(objectName);
     }
diff --git a/collector/jmx/src/test/java/org/apache/karaf/decanter/collector/jmx/TestMapAttribute.java b/collector/jmx/src/test/java/org/apache/karaf/decanter/collector/jmx/TestMapAttribute.java
index 3d7e51d..aa2d1ac 100644
--- a/collector/jmx/src/test/java/org/apache/karaf/decanter/collector/jmx/TestMapAttribute.java
+++ b/collector/jmx/src/test/java/org/apache/karaf/decanter/collector/jmx/TestMapAttribute.java
@@ -33,7 +33,7 @@
     @Test
     public void testOperatingSystemMBean() throws MalformedObjectNameException, Exception {
         MBeanServerConnection server = ManagementFactory.getPlatformMBeanServer();
-        BeanHarvester harvester = new BeanHarvester(server, "local", "local", "localhost");
+        BeanHarvester harvester = new BeanHarvester(server, "local");
         Map<String, Object> data = harvester.harvestBean(new ObjectName("java.lang:type=OperatingSystem"));
         Assert.assertTrue(data.size() >= 15);
         Object freeMem = data.get("FreePhysicalMemorySize");
diff --git a/collector/kafka/pom.xml b/collector/kafka/pom.xml
index 95cc11c..cdccd21 100644
--- a/collector/kafka/pom.xml
+++ b/collector/kafka/pom.xml
@@ -38,6 +38,10 @@
             <groupId>org.apache.karaf.decanter</groupId>
             <artifactId>org.apache.karaf.decanter.api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.karaf.decanter.collector</groupId>
+            <artifactId>org.apache.karaf.decanter.collector.utils</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.apache.kafka</groupId>
             <artifactId>kafka-clients</artifactId>
@@ -47,6 +51,27 @@
 
     <build>
         <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <inherited>true</inherited>
+                <extensions>true</extensions>
+                <configuration>
+                    <obrRepository>NONE</obrRepository>
+                    <instructions>
+                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+                        <Export-Package>!*</Export-Package>
+                        <Import-Package>
+                            *
+                        </Import-Package>
+                        <Private-Package>
+                            org.apache.karaf.decanter.collector.kafka,
+                            org.apache.karaf.decanter.collector.utils
+                        </Private-Package>
+                        <_dsannotations>*</_dsannotations>
+                    </instructions>
+                </configuration>
+            </plugin>
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>build-helper-maven-plugin</artifactId>
diff --git a/collector/kafka/src/main/java/org/apache/karaf/decanter/collector/kafka/KafkaCollector.java b/collector/kafka/src/main/java/org/apache/karaf/decanter/collector/kafka/KafkaCollector.java
index 7805840..a805de3 100644
--- a/collector/kafka/src/main/java/org/apache/karaf/decanter/collector/kafka/KafkaCollector.java
+++ b/collector/kafka/src/main/java/org/apache/karaf/decanter/collector/kafka/KafkaCollector.java
@@ -18,10 +18,8 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.UnsupportedEncodingException;
-import java.net.InetAddress;
 import java.util.Arrays;
 import java.util.Dictionary;
-import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
@@ -31,6 +29,7 @@
 import org.apache.kafka.clients.consumer.ConsumerRecords;
 import org.apache.kafka.clients.consumer.KafkaConsumer;
 import org.apache.karaf.decanter.api.marshaller.Unmarshaller;
+import org.apache.karaf.decanter.collector.utils.PropertiesPreparator;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
@@ -172,19 +171,7 @@ private void consume() throws UnsupportedEncodingException {
             return;
         }
         Map<String, Object> data = new HashMap<>();
-        try {
-            data.put("hostAddress", InetAddress.getLocalHost().getHostAddress());
-            data.put("hostName", InetAddress.getLocalHost().getHostName());
-        } catch (Exception e) {
-            LOGGER.warn("Can't populate local host name and address", e);
-        }
-
-        // custom fields
-        Enumeration<String> keys = properties.keys();
-        while (keys.hasMoreElements()) {
-            String key = keys.nextElement();
-            data.put(key, properties.get(key));
-        }
+        data.put("type", "kafka");
         
         for (ConsumerRecord<String, String> record : records) {
             String value = record.value();
@@ -192,11 +179,12 @@ private void consume() throws UnsupportedEncodingException {
             data.putAll(unmarshaller.unmarshal(is));
         }
 
-        data.put("type", "kafka");
-        String karafName = System.getProperty("karaf.name");
-        if (karafName != null) {
-            data.put("karafName", karafName);
+        try {
+            PropertiesPreparator.prepare(data, properties);
+        } catch (Exception e) {
+            LOGGER.warn("Can't prepare data for the dispatcher", e);
         }
+
         Event event = new Event(eventAdminTopic, data);
         dispatcher.postEvent(event);
     }
diff --git a/collector/log/pom.xml b/collector/log/pom.xml
index 5c3d66b..3dd1408 100644
--- a/collector/log/pom.xml
+++ b/collector/log/pom.xml
@@ -39,10 +39,35 @@
             <artifactId>pax-logging-service</artifactId>
             <version>1.7.3</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.karaf.decanter.collector</groupId>
+            <artifactId>org.apache.karaf.decanter.collector.utils</artifactId>
+        </dependency>
     </dependencies>
 
     <build>
         <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <inherited>true</inherited>
+                <configuration>
+                    <obrRepository>NONE</obrRepository>
+                    <instructions>
+                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+                        <Export-Package>!*</Export-Package>
+                        <Import-Package>
+                            *
+                        </Import-Package>
+                        <Private-Package>
+                            org.apache.karaf.decanter.collector.log,
+                            org.apache.karaf.decanter.collector.utils
+                        </Private-Package>
+                        <_dsannotations>*</_dsannotations>
+                    </instructions>
+                </configuration>
+            </plugin>
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>build-helper-maven-plugin</artifactId>
diff --git a/collector/log/src/main/java/org/apache/karaf/decanter/collector/log/LogAppender.java b/collector/log/src/main/java/org/apache/karaf/decanter/collector/log/LogAppender.java
index e1bb0c3..3b82547 100644
--- a/collector/log/src/main/java/org/apache/karaf/decanter/collector/log/LogAppender.java
+++ b/collector/log/src/main/java/org/apache/karaf/decanter/collector/log/LogAppender.java
@@ -16,17 +16,13 @@
  */
 package org.apache.karaf.decanter.collector.log;
 
-import java.net.InetAddress;
-import java.text.SimpleDateFormat;
-import java.util.Date;
 import java.util.Dictionary;
-import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.UUID;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.apache.karaf.decanter.collector.utils.PropertiesPreparator;
 import org.apache.log4j.MDC;
 import org.ops4j.pax.logging.spi.PaxAppender;
 import org.ops4j.pax.logging.spi.PaxLocationInfo;
@@ -57,15 +53,10 @@
     private static final String MDC_IN_LOG_APPENDER = "inLogAppender";
     private final static Logger LOGGER = LoggerFactory.getLogger(LogAppender.class);
     private final static Pattern PATTERN = Pattern.compile("[^A-Za-z0-9]");
-    private final static String FIELDS_ADD = "fields.add.";
-    private final static String FIELDS_RENAME = "fields.rename.";
-    private final static String FIELDS_REMOVE = "fields.remove.";
 
     private Dictionary<String, Object> properties;
     protected String[] ignoredCategories;
 
-    private SimpleDateFormat tsFormat;
-
     @SuppressWarnings("unchecked")
     @Activate
     public void activate(ComponentContext context) {
@@ -73,8 +64,6 @@ public void activate(ComponentContext context) {
         if (this.properties.get("ignored.categories") != null) {
             ignoredCategories = ((String)this.properties.get("ignored.categories")).split(",");
         }
-
-        tsFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
     }
     
     public void doAppend(PaxLoggingEvent event) {
@@ -101,14 +90,6 @@ private void appendInternal(PaxLoggingEvent event) throws Exception {
         LOGGER.debug("Publishing log event to the appenders ...");
 
         Map<String, Object> data = new HashMap<>();
-        data.put("type", "log");
-        String karafName = System.getProperty("karaf.name");
-        if (karafName != null) {
-            data.put("karafName", karafName);
-        }
-
-        data.put("hostAddress", InetAddress.getLocalHost().getHostAddress());
-        data.put("hostName", InetAddress.getLocalHost().getHostName());
 
         data.put("timestamp", event.getTimeStamp());
         data.put("loggerClass", event.getFQNOfLoggerClass());
@@ -124,34 +105,7 @@ private void appendInternal(PaxLoggingEvent event) throws Exception {
             data.put("throwable", join(throwableAr));
         }
 
-        // custom fields
-        Enumeration<String> keys = properties.keys();
-        while (keys.hasMoreElements()) {
-            String key = keys.nextElement();
-            if (key.startsWith(FIELDS_ADD)) {
-                if ("UUID".equals(properties.get(key).toString().trim())) {
-                    String uuid = UUID.randomUUID().toString();
-                    data.put(key.substring(FIELDS_ADD.length()), uuid);
-                } else if ("TIMESTAMP".equals(properties.get(key).toString().trim())) {
-                    Date date = new Date();
-                    data.put(key.substring(FIELDS_ADD.length()), tsFormat.format(date));
-                } else {
-                    data.put(key.substring(FIELDS_ADD.length()), properties.get(key));
-                }
-            } else if (key.startsWith(FIELDS_RENAME)) {
-                if (data.containsKey(key.substring(FIELDS_RENAME.length()))) {
-                    Object value = data.get(key.substring(FIELDS_RENAME.length()));
-                    data.remove(key.substring(FIELDS_RENAME.length()));
-                    data.put(properties.get(key).toString().trim(), value);
-                }
-            } else if (key.startsWith(FIELDS_REMOVE)) {
-                if (data.containsKey(key.substring(FIELDS_REMOVE.length()))) {
-                    data.remove(key.substring(FIELDS_REMOVE.length()));
-                }
-            } else {
-                data.put(key, properties.get(key));
-            }
-        }
+        PropertiesPreparator.prepare(data, properties);
 
         String loggerName = event.getLoggerName();
         if (loggerName == null || loggerName.isEmpty()) {
diff --git a/collector/log4j-socket/pom.xml b/collector/log4j-socket/pom.xml
index 6857d01..1363ed2 100644
--- a/collector/log4j-socket/pom.xml
+++ b/collector/log4j-socket/pom.xml
@@ -38,6 +38,10 @@
             <artifactId>log4j</artifactId>
             <version>1.2.17</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.karaf.decanter.collector</groupId>
+            <artifactId>org.apache.karaf.decanter.collector.utils</artifactId>
+        </dependency>
 
         <dependency>
             <groupId>org.slf4j</groupId>
@@ -48,6 +52,27 @@
 
     <build>
         <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <inherited>true</inherited>
+                <extensions>true</extensions>
+                <configuration>
+                    <obrRepository>NONE</obrRepository>
+                    <instructions>
+                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+                        <Export-Package>!*</Export-Package>
+                        <Import-Package>
+                            *
+                        </Import-Package>
+                        <Private-Package>
+                            org.apache.karaf.decanter.collector.log.socket,
+                            org.apache.karaf.decanter.collector.utils
+                        </Private-Package>
+                        <_dsannotations>*</_dsannotations>
+                    </instructions>
+                </configuration>
+            </plugin>
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>build-helper-maven-plugin</artifactId>
diff --git a/collector/log4j-socket/src/main/java/org/apache/karaf/decanter/collector/log/socket/SocketCollector.java b/collector/log4j-socket/src/main/java/org/apache/karaf/decanter/collector/log/socket/SocketCollector.java
index 39835ce..8ba35f5 100644
--- a/collector/log4j-socket/src/main/java/org/apache/karaf/decanter/collector/log/socket/SocketCollector.java
+++ b/collector/log4j-socket/src/main/java/org/apache/karaf/decanter/collector/log/socket/SocketCollector.java
@@ -21,18 +21,17 @@
 import java.io.EOFException;
 import java.io.IOException;
 import java.io.ObjectInputStream;
-import java.net.InetAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.net.UnknownHostException;
 import java.util.Dictionary;
-import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.karaf.decanter.collector.utils.PropertiesPreparator;
 import org.apache.log4j.spi.LocationInfo;
 import org.apache.log4j.spi.LoggingEvent;
 import org.osgi.service.component.ComponentContext;
@@ -110,42 +109,32 @@ ExecutorService getExecutorService() {
         return executor;
     }
 
-    private void handleLog4j(LoggingEvent event) throws UnknownHostException {
-        LOGGER.debug("Received log event {}", event.getLoggerName());
+    private void handleLog4j(LoggingEvent loggingEvent) throws UnknownHostException {
+        LOGGER.debug("Received log event {}", loggingEvent.getLoggerName());
         Map<String, Object> data = new HashMap<>();
-        data.put("hostAddress", InetAddress.getLocalHost().getHostAddress());
-        data.put("hostName", InetAddress.getLocalHost().getHostName());
-
-        // custom fields
-        Enumeration<String> keys = properties.keys();
-        while (keys.hasMoreElements()) {
-            String key = keys.nextElement();
-            data.put(key, properties.get(key));
-        }
+        data.put("type", "log");
 
-        data.put("timestamp", event.getTimeStamp());
-        data.put("loggerClass", event.getFQNOfLoggerClass());
-        data.put("loggerName", event.getLoggerName());
-        data.put("threadName", event.getThreadName());
-        data.put("message", event.getMessage());
-        data.put("level", event.getLevel().toString());
-        data.put("renderedMessage", event.getRenderedMessage());
-        data.put("MDC", event.getProperties());
-        putLocation(data, event.getLocationInformation());
-        String[] throwableAr = event.getThrowableStrRep();
+        data.put("timestamp", loggingEvent.getTimeStamp());
+        data.put("loggerClass", loggingEvent.getFQNOfLoggerClass());
+        data.put("loggerName", loggingEvent.getLoggerName());
+        data.put("threadName", loggingEvent.getThreadName());
+        data.put("message", loggingEvent.getMessage());
+        data.put("level", loggingEvent.getLevel().toString());
+        data.put("renderedMessage", loggingEvent.getRenderedMessage());
+        data.put("MDC", loggingEvent.getProperties());
+        putLocation(data, loggingEvent.getLocationInformation());
+        String[] throwableAr = loggingEvent.getThrowableStrRep();
         if (throwableAr != null) {
             data.put("throwable", join(throwableAr));
         }
-        sendEvent(event.getLoggerName(), data);
-    }
 
-    private void sendEvent(String loggerName, Map<String, Object> data) {
-        String topic = loggerName2Topic(loggerName);
-        data.put("type", "log");
-        String karafName = System.getProperty("karaf.name");
-        if (karafName != null) {
-            data.put("karafName", karafName);
+        try {
+            PropertiesPreparator.prepare(data, properties);
+        } catch (Exception e) {
+            LOGGER.warn("Can't prepare data for the dispatcher", e);
         }
+
+        String topic = loggerName2Topic(loggingEvent.getLoggerName());
         Event event = new Event(topic, data);
         dispatcher.postEvent(event);
     }
diff --git a/collector/mqtt/pom.xml b/collector/mqtt/pom.xml
index 4ca301b..0f3fea5 100644
--- a/collector/mqtt/pom.xml
+++ b/collector/mqtt/pom.xml
@@ -38,6 +38,10 @@
             <groupId>org.apache.karaf.decanter</groupId>
             <artifactId>org.apache.karaf.decanter.api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.karaf.decanter.collector</groupId>
+            <artifactId>org.apache.karaf.decanter.collector.utils</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.eclipse.paho</groupId>
             <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
@@ -77,6 +81,27 @@
 
     <build>
         <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <inherited>true</inherited>
+                <extensions>true</extensions>
+                <configuration>
+                    <obrRepository>NONE</obrRepository>
+                    <instructions>
+                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+                        <Export-Package>!*</Export-Package>
+                        <Import-Package>
+                            *
+                        </Import-Package>
+                        <Private-Package>
+                            org.apache.karaf.decanter.collector.mqtt,
+                            org.apache.karaf.decanter.collector.utils
+                        </Private-Package>
+                        <_dsannotations>*</_dsannotations>
+                    </instructions>
+                </configuration>
+            </plugin>
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>build-helper-maven-plugin</artifactId>
diff --git a/collector/mqtt/src/main/java/org/apache/karaf/decanter/collector/mqtt/MqttCollector.java b/collector/mqtt/src/main/java/org/apache/karaf/decanter/collector/mqtt/MqttCollector.java
index ccd42b2..da7f942 100644
--- a/collector/mqtt/src/main/java/org/apache/karaf/decanter/collector/mqtt/MqttCollector.java
+++ b/collector/mqtt/src/main/java/org/apache/karaf/decanter/collector/mqtt/MqttCollector.java
@@ -17,6 +17,7 @@
 package org.apache.karaf.decanter.collector.mqtt;
 
 import org.apache.karaf.decanter.api.marshaller.Unmarshaller;
+import org.apache.karaf.decanter.collector.utils.PropertiesPreparator;
 import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
 import org.eclipse.paho.client.mqttv3.MqttCallback;
 import org.eclipse.paho.client.mqttv3.MqttClient;
@@ -33,9 +34,7 @@
 import org.slf4j.LoggerFactory;
 
 import java.io.ByteArrayInputStream;
-import java.net.InetAddress;
 import java.util.Dictionary;
-import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -83,28 +82,17 @@ public void messageArrived(String topic, MqttMessage message) {
                 }
 
                 Map<String, Object> data = new HashMap<>();
-                try {
-                    data.put("hostAddress", InetAddress.getLocalHost().getHostAddress());
-                    data.put("hostName", InetAddress.getLocalHost().getHostName());
-                } catch (Exception e) {
-                    LOGGER.warn("Can't populate local host name and address", e);
-                }
-
-                // custom fields
-                Enumeration<String> keys = properties.keys();
-                while (keys.hasMoreElements()) {
-                    String key = keys.nextElement();
-                    data.put(key, properties.get(key));
-                }
+                data.put("type", "mqtt");
 
                 ByteArrayInputStream is = new ByteArrayInputStream(message.getPayload());
                 data.putAll(unmarshaller.unmarshal(is));
 
-                data.put("type", "mqtt");
-                String karafName = System.getProperty("karaf.name");
-                if (karafName != null) {
-                    data.put("karafName", karafName);
+                try {
+                    PropertiesPreparator.prepare(data, properties);
+                } catch (Exception e) {
+                    LOGGER.warn("Can't prepare data for the dispatcher", e);
                 }
+
                 Event event = new Event(dispatcherTopic, data);
                 dispatcher.postEvent(event);
             }
diff --git a/collector/pom.xml b/collector/pom.xml
index 7dafb49..cef98c1 100644
--- a/collector/pom.xml
+++ b/collector/pom.xml
@@ -34,6 +34,7 @@
     <name>Apache Karaf :: Decanter :: Collector</name>
 
     <modules>
+        <module>utils</module>
         <module>camel</module>
         <module>dropwizard</module>
         <module>eventadmin</module>
diff --git a/collector/process/pom.xml b/collector/process/pom.xml
index 0c1d450..149c703 100644
--- a/collector/process/pom.xml
+++ b/collector/process/pom.xml
@@ -26,8 +26,36 @@
 	<packaging>bundle</packaging>
 	<name>Apache Karaf :: Decanter :: Collector :: Process</name>
 
+	<dependencies>
+        <dependency>
+            <groupId>org.apache.karaf.decanter.collector</groupId>
+            <artifactId>org.apache.karaf.decanter.collector.utils</artifactId>
+        </dependency>
+	</dependencies>
+
 	<build>
 		<plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <inherited>true</inherited>
+                <extensions>true</extensions>
+                <configuration>
+                    <obrRepository>NONE</obrRepository>
+                    <instructions>
+                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+                        <Export-Package>!*</Export-Package>
+                        <Import-Package>
+                            *
+                        </Import-Package>
+                        <Private-Package>
+                            org.apache.karaf.decanter.collector.process,
+                            org.apache.karaf.decanter.collector.utils
+                        </Private-Package>
+                        <_dsannotations>*</_dsannotations>
+                    </instructions>
+                </configuration>
+            </plugin>
 			<plugin>
 				<groupId>org.codehaus.mojo</groupId>
 				<artifactId>build-helper-maven-plugin</artifactId>
diff --git a/collector/process/src/main/java/org/apache/karaf/decanter/collector/process/BeanHarvester.java b/collector/process/src/main/java/org/apache/karaf/decanter/collector/process/BeanHarvester.java
index d908f01..f0bbb8e 100644
--- a/collector/process/src/main/java/org/apache/karaf/decanter/collector/process/BeanHarvester.java
+++ b/collector/process/src/main/java/org/apache/karaf/decanter/collector/process/BeanHarvester.java
@@ -16,7 +16,6 @@
  */
 package org.apache.karaf.decanter.collector.process;
 
-import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -41,23 +40,10 @@
     private final static Logger LOGGER = LoggerFactory.getLogger(BeanHarvester.class);
     private MBeanServerConnection connection;
     private String type;
-    private String hostName;
-    private String hostAddress;
-    private String karafName;
     
-    BeanHarvester(MBeanServerConnection connection, String type, String hostName, String karafName) throws UnknownHostException {
+    BeanHarvester(MBeanServerConnection connection, String type) throws UnknownHostException {
         this.connection = connection;
         this.type = type;
-        this.hostName = hostName;
-        if (hostName == null || hostName.isEmpty()) {
-            this.karafName = karafName;
-            this.hostAddress = InetAddress.getLocalHost().getHostAddress();
-            this.hostName =InetAddress.getLocalHost().getHostName();
-        } else {
-            this.karafName = null;
-            this.hostAddress = null;
-            this.hostName = hostName;
-        }
     }
 
     Map<String, Object> harvestBean(ObjectName name) throws Exception {
@@ -65,13 +51,6 @@
         Map<String, Object> data = new HashMap<>();
         data.put("type", type);
         data.put("ObjectName", name.toString());
-        if (this.karafName != null) {
-            data.put("karafName", this.karafName);
-        }
-        if (this.hostAddress != null) {
-            data.put("hostAddress", this.hostAddress);
-        }
-        data.put("hostName", hostName);
 
         for (MBeanAttributeInfo attribute : attributes) {
             try {
diff --git a/collector/process/src/main/java/org/apache/karaf/decanter/collector/process/JmxProcessCollector.java b/collector/process/src/main/java/org/apache/karaf/decanter/collector/process/JmxProcessCollector.java
index 29ed1f9..8b82693 100644
--- a/collector/process/src/main/java/org/apache/karaf/decanter/collector/process/JmxProcessCollector.java
+++ b/collector/process/src/main/java/org/apache/karaf/decanter/collector/process/JmxProcessCollector.java
@@ -18,7 +18,6 @@
 
 import java.io.File;
 import java.util.Dictionary;
-import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.Map;
 import java.util.Set;
@@ -30,6 +29,7 @@
 import javax.management.remote.JMXConnectorFactory;
 import javax.management.remote.JMXServiceURL;
 
+import org.apache.karaf.decanter.collector.utils.PropertiesPreparator;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Reference;
@@ -125,12 +125,14 @@ public void run() {
 
         try {
             String karafName = System.getProperty("karaf.name");
-            BeanHarvester harvester = new BeanHarvester(connection, type, host, karafName);
+            BeanHarvester harvester = new BeanHarvester(connection, type);
             Set<ObjectName> names = connection.queryNames(getObjectName(objectName), null);
             for (ObjectName name : names) {
                 try {
                     Map<String, Object> data = harvester.harvestBean(name);
-                    addUserProperties(data);
+
+                    PropertiesPreparator.prepare(data, properties);
+
                     Event event = new Event("decanter/collect/jmx/" + type + "/" + getTopic(name), data);
                     dispatcher.postEvent(event);
                 } catch (Exception e) {
@@ -150,16 +152,6 @@ public void run() {
         LOGGER.debug("Karaf Decanter  JMX Local Process Collector harvesting {} done", type);
     }
 
-    private void addUserProperties(Map<String, Object> data) {
-        if (properties != null) {
-            Enumeration<String> keys = properties.keys();
-            while (keys.hasMoreElements()) {
-                String property = keys.nextElement();
-                data.put(property, properties.get(property));
-            }
-        }
-    }
-
     private ObjectName getObjectName(String objectName) throws MalformedObjectNameException {
         return objectName == null ? null : new ObjectName(objectName);
     }
diff --git a/collector/rest-servlet/pom.xml b/collector/rest-servlet/pom.xml
index d9b7c5c..811d3c5 100644
--- a/collector/rest-servlet/pom.xml
+++ b/collector/rest-servlet/pom.xml
@@ -19,6 +19,10 @@
             <groupId>org.apache.karaf.decanter</groupId>
             <artifactId>org.apache.karaf.decanter.api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.karaf.decanter.collector</groupId>
+            <artifactId>org.apache.karaf.decanter.collector.utils</artifactId>
+        </dependency>
         <dependency>
         	<groupId>javax.servlet</groupId>
         	<artifactId>javax.servlet-api</artifactId>
@@ -28,6 +32,27 @@
 
     <build>
         <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <inherited>true</inherited>
+                <extensions>true</extensions>
+                <configuration>
+                    <obrRepository>NONE</obrRepository>
+                    <instructions>
+                        <Bnudle-SymbolicName>${project.artifactId}</Bnudle-SymbolicName>
+                        <Export-Package>!*</Export-Package>
+                        <Import-Package>
+                            *
+                        </Import-Package>
+                        <Private-Package>
+                            org.apache.karaf.decanter.collector.rest,
+                            org.apache.karaf.decanter.collector.utils
+                        </Private-Package>
+                        <_dsannotations>*</_dsannotations>
+                    </instructions>
+                </configuration>
+            </plugin>
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>build-helper-maven-plugin</artifactId>
diff --git a/collector/rest-servlet/src/main/java/org/apache/karaf/decanter/collector/rest/RestCollector.java b/collector/rest-servlet/src/main/java/org/apache/karaf/decanter/collector/rest/RestCollector.java
index 9e63da9..a18ea91 100644
--- a/collector/rest-servlet/src/main/java/org/apache/karaf/decanter/collector/rest/RestCollector.java
+++ b/collector/rest-servlet/src/main/java/org/apache/karaf/decanter/collector/rest/RestCollector.java
@@ -16,10 +16,11 @@
  */
 package org.apache.karaf.decanter.collector.rest;
 
+import java.io.BufferedReader;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.net.MalformedURLException;
 import java.util.Dictionary;
-import java.util.Enumeration;
 import java.util.Map;
 
 import javax.servlet.Servlet;
@@ -29,6 +30,7 @@
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.karaf.decanter.api.marshaller.Unmarshaller;
+import org.apache.karaf.decanter.collector.utils.PropertiesPreparator;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
@@ -77,13 +79,18 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
         throws ServletException, IOException {
         try {
             Map<String, Object> data = unmarshaller.unmarshal(req.getInputStream());
+            data.put("type", "restservlet");
 
-            // custom fields
-            Enumeration<String> keys = properties.keys();
-            while (keys.hasMoreElements()) {
-                String key = keys.nextElement();
-                data.put(key, properties.get(key));
+            StringBuilder builder = new StringBuilder();
+            BufferedReader reader = new BufferedReader(new InputStreamReader(req.getInputStream()));
+            String line;
+            while ((line = reader.readLine()) != null) {
+                builder.append(line);
             }
+            reader.close();
+            data.put("payload", builder.toString());
+
+            PropertiesPreparator.prepare(data, properties);
 
             Event event = new Event(baseTopic, data);
             dispatcher.postEvent(event);
diff --git a/collector/rest/pom.xml b/collector/rest/pom.xml
index c2c6af6..761d8e7 100644
--- a/collector/rest/pom.xml
+++ b/collector/rest/pom.xml
@@ -19,10 +19,35 @@
             <groupId>org.apache.karaf.decanter</groupId>
             <artifactId>org.apache.karaf.decanter.api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.karaf.decanter.collector</groupId>
+            <artifactId>org.apache.karaf.decanter.collector.utils</artifactId>
+        </dependency>
     </dependencies>
 
     <build>
         <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <inherited>true</inherited>
+                <extensions>true</extensions>
+                <configuration>
+                    <obrRepository>NONE</obrRepository>
+                    <instructions>
+                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+                        <Export-Package>!*</Export-Package>
+                        <Import-Package>
+                            *
+                        </Import-Package>
+                        <Private-Package>
+                            org.apache.karaf.decanter.collector.rest,
+                            org.apache.karaf.decanter.collector.utils
+                        </Private-Package>
+                        <_dsannotations>*</_dsannotations>
+                    </instructions>
+                </configuration>
+            </plugin>
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>build-helper-maven-plugin</artifactId>
diff --git a/collector/rest/src/main/java/org/apache/karaf/decanter/collector/rest/RestCollector.java b/collector/rest/src/main/java/org/apache/karaf/decanter/collector/rest/RestCollector.java
index ad2ef7e..ef78594 100644
--- a/collector/rest/src/main/java/org/apache/karaf/decanter/collector/rest/RestCollector.java
+++ b/collector/rest/src/main/java/org/apache/karaf/decanter/collector/rest/RestCollector.java
@@ -24,6 +24,7 @@
 import java.util.Map;
 
 import org.apache.karaf.decanter.api.marshaller.Unmarshaller;
+import org.apache.karaf.decanter.collector.utils.PropertiesPreparator;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
@@ -96,7 +97,6 @@ public void run() {
                 URLConnection connection = complete.openConnection();
                 Map<String, Object> data = unmarshaller.unmarshal(connection.getInputStream());
                 data.put("type", "rest");
-                data.put("hostName", url.getHost());
                 data.put("remote.url", complete);
 
                 // custom fields
@@ -106,7 +106,9 @@ public void run() {
                     data.put(key, properties.get(key));
                 }
 
-                addUserProperties(data);
+                PropertiesPreparator.prepare(data, properties);
+
+                data.put("hostName", url.getHost());
                 dispatcher.postEvent(new Event(toTopic(complete), data));
                 repeatedError = false;
             } catch (Exception e) {
@@ -126,14 +128,4 @@ private String toTopic(URL url) {
         return baseTopic + "/" + url.getHost() + url.getPath();
     }
 
-    private void addUserProperties(Map<String, Object> data) {
-        if (properties != null) {
-            Enumeration<String> keys = properties.keys();
-            while (keys.hasMoreElements()) {
-                String property = keys.nextElement();
-                data.put(property, properties.get(property));
-            }
-        }
-    }
-
 }
diff --git a/collector/socket/pom.xml b/collector/socket/pom.xml
index eba1356..cf5a200 100644
--- a/collector/socket/pom.xml
+++ b/collector/socket/pom.xml
@@ -38,10 +38,35 @@
             <groupId>org.apache.karaf.decanter</groupId>
             <artifactId>org.apache.karaf.decanter.api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.karaf.decanter.collector</groupId>
+            <artifactId>org.apache.karaf.decanter.collector.utils</artifactId>
+        </dependency>
     </dependencies>
 
     <build>
         <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <inherited>true</inherited>
+                <extensions>true</extensions>
+                <configuration>
+                    <obrRepository>NONE</obrRepository>
+                    <instructions>
+                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+                        <Export-Package>!*</Export-Package>
+                        <Import-Package>
+                            *
+                        </Import-Package>
+                        <Private-Package>
+                            org.apache.karaf.decanter.collector.socket,
+                            org.apache.karaf.decanter.collector.utils
+                        </Private-Package>
+                        <_dsannotations>*</_dsannotations>
+                    </instructions>
+                </configuration>
+            </plugin>
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>build-helper-maven-plugin</artifactId>
diff --git a/collector/socket/src/main/java/org/apache/karaf/decanter/collector/socket/SocketCollector.java b/collector/socket/src/main/java/org/apache/karaf/decanter/collector/socket/SocketCollector.java
index b37d18a..65b8d28 100644
--- a/collector/socket/src/main/java/org/apache/karaf/decanter/collector/socket/SocketCollector.java
+++ b/collector/socket/src/main/java/org/apache/karaf/decanter/collector/socket/SocketCollector.java
@@ -19,11 +19,9 @@
 import java.io.*;
 import java.net.DatagramPacket;
 import java.net.DatagramSocket;
-import java.net.InetAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.util.Dictionary;
-import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.ExecutorService;
@@ -31,6 +29,7 @@
 import java.util.concurrent.TimeUnit;
 
 import org.apache.karaf.decanter.api.marshaller.Unmarshaller;
+import org.apache.karaf.decanter.collector.utils.PropertiesPreparator;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
@@ -165,24 +164,17 @@ public SocketRunnable(Socket clientSocket) {
         public void run() {
             try (BufferedInputStream bis = new BufferedInputStream(clientSocket.getInputStream())) {
                 Map<String, Object> data = new HashMap<>();
-                data.put("hostAddress", InetAddress.getLocalHost().getHostAddress());
-                data.put("hostName", InetAddress.getLocalHost().getHostName());
                 data.put("type", "socket");
-                String karafName = System.getProperty("karaf.name");
-                if (karafName != null) {
-                    data.put("karafName", karafName);
-                }
                 try {
                     data.putAll(unmarshaller.unmarshal(bis));
                 } catch (Exception e) {
                     // nothing to do
                 }
 
-                // custom fields
-                Enumeration<String> keys = properties.keys();
-                while (keys.hasMoreElements()) {
-                    String key = keys.nextElement();
-                    data.put(key, properties.get(key));
+                try {
+                    PropertiesPreparator.prepare(data, properties);
+                } catch (Exception e) {
+                    LOGGER.warn("Can't prepare data for the dispatcher", e);
                 }
 
                 Event event = new Event(eventAdminTopic, data);
@@ -212,24 +204,17 @@ public void run() {
             
             try (ByteArrayInputStream bais = new ByteArrayInputStream(packet.getData())) {
                 Map<String, Object> data = new HashMap<>();
-                data.put("hostAddress", InetAddress.getLocalHost().getHostAddress());
-                data.put("hostName", InetAddress.getLocalHost().getHostName());
                 data.put("type", "socket");
-                String karafName = System.getProperty("karaf.name");
-                if (karafName != null) {
-                    data.put("karafName", karafName);
-                }
                 try {
                     data.putAll(unmarshaller.unmarshal(bais));
                 } catch (Exception e) {
                     // nothing to do
                 }
 
-                // custom fields
-                Enumeration<String> keys = properties.keys();
-                while (keys.hasMoreElements()) {
-                    String key = keys.nextElement();
-                    data.put(key, properties.get(key));
+                try {
+                    PropertiesPreparator.prepare(data, properties);
+                } catch (Exception e) {
+                    LOGGER.warn("Can't prepare data for the dispatcher", e);
                 }
 
                 Event event = new Event(eventAdminTopic, data);
diff --git a/collector/utils/pom.xml b/collector/utils/pom.xml
new file mode 100644
index 0000000..6aa3bba
--- /dev/null
+++ b/collector/utils/pom.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <!--
+
+        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.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.karaf.decanter</groupId>
+        <artifactId>collector</artifactId>
+        <version>2.1.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <groupId>org.apache.karaf.decanter.collector</groupId>
+    <artifactId>org.apache.karaf.decanter.collector.utils</artifactId>
+    <packaging>jar</packaging>
+    <name>Apache Karaf :: Decanter :: Collector :: Utils</name>
+
+</project>
\ No newline at end of file
diff --git a/collector/utils/src/main/java/org/apache/karaf/decanter/collector/utils/PropertiesPreparator.java b/collector/utils/src/main/java/org/apache/karaf/decanter/collector/utils/PropertiesPreparator.java
new file mode 100644
index 0000000..672afc7
--- /dev/null
+++ b/collector/utils/src/main/java/org/apache/karaf/decanter/collector/utils/PropertiesPreparator.java
@@ -0,0 +1,82 @@
+/*
+ * 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.karaf.decanter.collector.utils;
+
+import java.net.InetAddress;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.UUID;
+
+public class PropertiesPreparator {
+
+    private final static String FIELDS_ADD = "fields.add.";
+    private final static String FIELDS_RENAME = "fields.rename.";
+    private final static String FIELDS_REMOVE = "fields.remove.";
+
+    private static SimpleDateFormat tsFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
+
+    /**
+     * Prepare the data sent to the dispatcher using default properties and provided custom fields.
+     *
+     * @param data Data container sent to the dispatcher by the collector.
+     * @param properties Custom properties included in the data.
+     */
+    public static void prepare(Map<String, Object> data, Dictionary<String, Object> properties) throws Exception {
+        // add the karaf instance name
+        String karafName = System.getProperty("karaf.name");
+        if (karafName != null) {
+            data.put("karafName", karafName);
+        }
+
+        // add the network details
+        data.put("hostAddress", InetAddress.getLocalHost().getHostAddress());
+        data.put("hostName", InetAddress.getLocalHost().getHostName());
+
+        // custom fields
+        Enumeration<String> keys = properties.keys();
+        while (keys.hasMoreElements()) {
+            String key = keys.nextElement();
+            if (key.startsWith(FIELDS_ADD)) {
+                if ("UUID".equals(properties.get(key).toString().trim())) {
+                    String uuid = UUID.randomUUID().toString();
+                    data.put(key.substring(FIELDS_ADD.length()), uuid);
+                } else if ("TIMESTAMP".equals(properties.get(key).toString().trim())) {
+                    Date date = new Date();
+                    data.put(key.substring(FIELDS_ADD.length()), tsFormat.format(date));
+                } else {
+                    data.put(key.substring(FIELDS_ADD.length()), properties.get(key));
+                }
+            } else if (key.startsWith(FIELDS_RENAME)) {
+                if (data.containsKey(key.substring(FIELDS_RENAME.length()))) {
+                    Object value = data.get(key.substring(FIELDS_RENAME.length()));
+                    data.remove(key.substring(FIELDS_RENAME.length()));
+                    data.put(properties.get(key).toString().trim(), value);
+                }
+            } else if (key.startsWith(FIELDS_REMOVE)) {
+                if (data.containsKey(key.substring(FIELDS_REMOVE.length()))) {
+                    data.remove(key.substring(FIELDS_REMOVE.length()));
+                }
+            } else {
+                data.put(key, properties.get(key));
+            }
+        }
+    }
+
+}
diff --git a/manual/src/main/asciidoc/user-guide/collectors.adoc b/manual/src/main/asciidoc/user-guide/collectors.adoc
index 32b13c2..94340c8 100644
--- a/manual/src/main/asciidoc/user-guide/collectors.adoc
+++ b/manual/src/main/asciidoc/user-guide/collectors.adoc
@@ -702,4 +702,31 @@ karaf@root()> feature:install decanter-collector-dropwizard
 ----
 
 As soon as a `MetricSet` (like `MetricRegistry`) service will be available, the collector will get the metrics and
-send to the Decanter dispatcher.
\ No newline at end of file
+send to the Decanter dispatcher.
+
+==== Customizing properties in collectors
+
+You can add, rename or remove properties collected by the collectors before sending it to the dispatcher.
+
+In the collector configuration file (for instance `etc/org.apache.karaf.decanter.collector.jmx-local.cfg` for the local JMX collector), you
+can add any property. By default, the property is added to the data sent to the dispatcher.
+
+You can prefix the configuration property with the action you can perform before sending:
+
+* `fields.add.` adds a property to the data sent. The following add property `hello` with value `world`:
+
+    ----
+    fields.add.hello=world
+    ----
+
+* `fields.remove.` removes a property to the data sent:
+
+    ----
+    fields.remove.hello=
+    ----
+
+* `fields.rename.` rename a property with another name:
+
+    ----
+    fields.rename.helo=hello
+    ----
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 98ce56b..d42f055 100644
--- a/pom.xml
+++ b/pom.xml
@@ -290,6 +290,11 @@
                 <artifactId>org.apache.karaf.decanter.marshaller.csv</artifactId>
                 <version>${project.version}</version>
             </dependency>
+            <dependency>
+                <groupId>org.apache.karaf.decanter.collector</groupId>
+                <artifactId>org.apache.karaf.decanter.collector.utils</artifactId>
+                <version>${project.version}</version>
+            </dependency>
 
             <!-- OSGi -->
             <dependency>


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Support add, rename, remove to the custom fields of Decanter collectors
> -----------------------------------------------------------------------
>
>                 Key: KARAF-5792
>                 URL: https://issues.apache.org/jira/browse/KARAF-5792
>             Project: Karaf
>          Issue Type: Improvement
>          Components: decanter
>    Affects Versions: decanter-2.0.0
>            Reporter: Xilai Dai
>            Assignee: Jean-Baptiste Onofré
>            Priority: Major
>             Fix For: decanter-2.1.0
>
>
> Now user can only "add" some custom fields with constant value in the org.apache.karaf.decanter.collector.log.cfg.
> {code}
> key1=value1
> key2=value2
> {code}
> But there is no chance to "rename" or "remove" some of the generated fields from the log collector, or add dynamic value e.g. UUID, Timestamp to the field.
> It would be benifit for user if the custom fields impl get improved in the log collector of Decanter. Configuration like this:
> {code}
> # custom fields
> fields.add.eventType=LOGEvent
> fields.add.eventUUID=UUID
> fields.add.serverTimestamp=TIMESTAMP
> fields.rename.MDC=customInfo
> fields.rename.level=severity
> fields.rename.renderedMessage=logMessage
> fields.remove.timestamp=true
> {code}
> Then it provides ability to "transformer" the json data on collector level, which will reduce the overhead user has to "transformer" the data later (using Filebeat or custom transformer bundle)



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message