package com.dtstack.logstash.filters;

import java.util.Map;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.dtstack.logstash.annotation.Required;


/**
 * 
 * Reason: TODO ADD REASON(可选)
 * Date: 2016年8月31日 下午1:52:37
 * Company: www.dtstack.com
 * @author sishu.yss
 *
 */
@SuppressWarnings("serial")
public class Add extends BaseFilter {
	private static final Logger logger = LoggerFactory.getLogger(Add.class.getName());

	@Required(required=true)
	private static Map<String, Object> fields=null;
	
	@SuppressWarnings("rawtypes")
	public Add(Map config) {
		super(config);
	}

	public void prepare() {

	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	protected Map filter(final Map event) {
		Set<Map.Entry<String,Object>> sets =fields.entrySet();
		for(Map.Entry<String,Object> entry:sets){
			Object value = entry.getValue();
			String key = entry.getKey();
			event.put(key, value);
			if(event.get(value)!=null){
				event.put(key, event.get(value));
			}	
		}
		return event;
	}
}

@@ -32,16 +32,45 @@
 lters;%0A%0A
+import java.net.InetAddress;%0A
 import j
@@ -105,16 +105,47 @@
 il.Set;%0A
+import org.joda.time.DateTime;%0A
 import o
@@ -242,16 +242,81 @@
 quired;%0A
+import java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;;%0A
 %0A%0A/**%0A *
@@ -584,16 +584,98 @@
 ame());%0A
+%09%0A%09private static final Pattern pattern =Pattern.compile(%22%5E%25%5C%5C%7B%5Ba-zA-Z%5D+%5C%5C%7D%25$%22);%0A%09
 %0A%09@Requi
@@ -1224,31 +1224,1190 @@
 %09%09%09%7D
-%09%0A%09%09%7D%0A%09%09return event;%0A%09%7D
+else if(value instanceof String)%7B%0A            %09Matcher matcher =pattern.matcher(value.toString());%0A            %09if(matcher.find())%7B%0A            %09%09String group =matcher.group();%0A            %09%09if (%22%25%7Bhostname%7D%25%22.equals(group))%7B%0A            %09%09%09event.put(key, getHostName());%0A            %09%09%7Delse if(%22%25%7Btimestamp%7D%25%22.equals(group))%7B%0A            %09%09%09event.put(key, getTimeStamp());%0A            %09%09%7Delse if(%22%25%7Bip%7D%25%22.equals(group))%7B%0A            %09%09%09event.put(key, getHostAddress());%0A            %09%09%7D%0A            %09%7D%0A            %7D%0A            %09%0A%09%09%7D%0A%09%09return event;%0A%09%7D%0A%09%0A%09%0A%09private String getHostName()%7B%0A        try %7B%0A%09%09%09InetAddress ia = InetAddress.getLocalHost();%0A%09%09%09return ia.getHostName();%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09// TODO Auto-generated catch block%0A%09%09%09logger.error(%22getHostName:%7B%7D%22,e.getCause());%0A%09%09%7D   %0A        return %22localhost%22;%0A%09%7D%0A%09%0A%09private String getHostAddress()%7B%0A        try %7B%0A%09%09%09InetAddress ia = InetAddress.getLocalHost();%0A%09%09%09return ia.getHostAddress();%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09// TODO Auto-generated catch block%0A%09%09%09logger.error(%22getHostAddress:%7B%7D%22,e.getCause());%0A%09%09%7D   %0A        return %22localhost%22;%0A%09%7D%0A%09%0A%09private String getTimeStamp()%7B%0A%09%09return DateTime.now().toString();%0A%09%7D%09
 %0A%7D%0A

add inner func