#转UTF8
require 'cgi';event.set('tes',CGI.unescape(event.get('message')).dup.force_encoding('utf-8'));
#中文转16进制
"哎哎哎".bytes.map{|x| x}.pack "C*" #"\xE4\xBA\xB2"
#16进制转中文
"\xE4\xBA\xB2".force_encoding 'utf-8' #"哎哎哎"
#时间戳转时间
require 'date'
puts Time.at(1574213037000/1000+28800).strftime('%Y-%m-%d %H:%M:%S')
puts DateTime.strptime("1574213037",'%s')
puts Time.at(1574213037).to_datetime
puts "Hello World!";
#以下未测试,也是转字符格式
ruby {
init => "require 'base64'"
code => "
string = event.get('string')
if string
begin
b64 = Base64.decode64(string).force_encoding('utf-8')
#puts b64, event.get('message')
event.set('b64_decode', b64)
rescue ArgumentError
event.set('b64_decode', '')
end
else
event.set('b64_decode', '')
end
"
}
if [b64_decode == ""]{
drop {}
}
kv {
source => "b64_decode"
field_split => "&?"
value_split => "="
}