Ruby – Array

Logstash – Array Split

mutate {
split => {“Set” => ” “}
}

ruby {
code => ” event[‘name’] = event[‘Set’][-1]; ”
}

—–
http://stackoverflow.com/questions/31031895/logstash-kv-filter-converting-strings-to-integers-using-dynamic-mapping

filter {
ruby {
code => ”
fieldArray = event[‘message’].split(‘ ‘);
for field in fieldArray
name = field.split(‘=’)[0];
value = field.split(‘=’)[1];
if value =~ /\A\d+\Z/
event[name] = value.to_i
else
event[name] = value
end
end

}
}

—–
convert to int
“1,112”.delete(‘,’).to_i

—-

ruby {
code => ”
tArray = event[‘MyLog’].split(‘~’);
event[‘My_Number’] = tArray.fetch(0,0);
event[‘My_Name’] = tArray.fetch(1,’Domain’);
event[‘MyId’] = Integer(tArray.fetch(2,0));
event[‘MyJob’] = tArray.fetch(3,”);

}

Advertisements