Is there any way to write loops inside filters or outputs plugins?
For a certain message
{"time"=100,"name"="test"}
I want to implement something like below:
c=0,
while c<=10
time=time+c
c=c+1
if c=10
reset to c=0
For every message the time needs to get updated until the count reaches 10 and the count needs to reset to 0.
where can i write this logic ? Filters ? outputs ?
I need every message i send to the input filter to get this udpdated before it transforms as output.
Thanks ! that did fix the error but i think my code is written wrong for the requirements. It's actually going to an infinite loop when i want to execute and update only once for every execution and i am getting a grok parse failure
code => "event.set('timestamp', event.get('timestamp_object').to_i * 1000);
event.set('time',event.get('timestamp_object').to_i*100000000);
count=0
if count<=10
count=count+1
puts count
time=event.get('time')
puts 'time'
time=(time+count)
puts time
end
if count==10
count=0
puts 'resetting count to 0'
end"
The reason I set "-b 3" is so that I do not have to post a thousand lines of data to demonstrate the issue of different threads interacting. If you set "-w 1" then the result does cycle between 100 and 109, but the solution does not scale.
This might not be the best approach and i am trying to avoid an issues with InfluxDB mentioned here. The only work arounds are to use uuid's as another field or to modify values for fields so that the timestamp values are not similar for at least 5-10 sec.
I thought running through a loop an adding it to timestamps is the best way.
Do you think if writing a shell script to update timestamp values for every record would help ?
I tried something similar to this but I get "Ruby exception occurred: undefined local variable or method `count' for #LogStash::Filters::Ruby:0x138f09da" error.
code:
ruby {
init => "count = 0"
code => "event.set('timestamp', event.get('timestamp_object').to_i * 1000);
event.set('time',event.get('timestamp_object').to_i*100000000);
if count<=10
count=count+1
puts count
event.set('time',event.get('time')+count)
puts time
end
if count==10
count=0
puts 'resetting count to 0'
end"
}
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.