增加 set 函数。
This commit is contained in:
@@ -38,31 +38,7 @@ public class CustomizedKafkaSpout extends BaseRichSpout {
|
||||
props.put("max.poll.records", 3000);
|
||||
props.put("max.partition.fetch.bytes", 31457280);
|
||||
props.put("auto.offset.reset", FlowWriteConfig.AUTO_OFFSET_RESET);
|
||||
// switch (FlowWriteConfig.KAFKA_TOPIC) {
|
||||
// case "PROXY-EVENT-LOG":
|
||||
// props.put("client.id", "proxy");
|
||||
// break;
|
||||
// case "RADIUS-RECORD-LOG":
|
||||
// props.put("client.id", "radius");
|
||||
// break;
|
||||
// case "CONNECTION-RECORD-LOG":
|
||||
// props.put("client.id", "connection");
|
||||
// break;
|
||||
// case "SECURITY-EVENT-LOG":
|
||||
// props.put("client.id", "security");
|
||||
// break;
|
||||
// case "CONNECTION-SKETCH":
|
||||
// props.put("client.id", "sketch");
|
||||
// break;
|
||||
// case "ACTIVE-DEFENCE-EVENT-LOG":
|
||||
// props.put("client.id", "active");
|
||||
// break;
|
||||
// case "SYS-PACKET-CAPTURE-LOG":
|
||||
// props.put("client.id", "packet");
|
||||
// break;
|
||||
//
|
||||
// default:
|
||||
// }
|
||||
|
||||
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
|
||||
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
|
||||
|
||||
|
||||
@@ -128,6 +128,11 @@ public class TransFormUtils {
|
||||
JsonParseUtil.setValue(object, appendToKeyName, getGeoIpCountry(ipLookup, name.toString()));
|
||||
}
|
||||
break;
|
||||
case "set_value":
|
||||
if (name != null && param != null) {
|
||||
JsonParseUtil.setValue(object, appendToKeyName, setValue(param));
|
||||
}
|
||||
break;
|
||||
case "get_value":
|
||||
if (name != null) {
|
||||
JsonParseUtil.setValue(object, appendToKeyName, name);
|
||||
|
||||
@@ -189,4 +189,24 @@ class TransFunction {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置固定值函数 若为数字则转为long返回
|
||||
* @param param 默认值
|
||||
* @return 返回数字或字符串
|
||||
*/
|
||||
static Object setValue(String param) {
|
||||
try {
|
||||
Matcher isNum = pattern.matcher(param);
|
||||
if (isNum.matches()) {
|
||||
return Long.parseLong(param);
|
||||
} else {
|
||||
return param;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("SetValue 函数异常,异常信息:" + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user