Comparing two string in ruby filter / comparing two string fields


(Navneet Mathpal) #1

Hi ,

I was trying to compare two string in logstash ruby filter inside code , it it always showing wrong result . same if I am trying in ruby IDE is working perfectly fine .
I am trying to do something

code => "
event['id']=File.open('D:/json/samplefile2.txt', &:readline)
latestid=File.open('D:/json/samplefile2.txt', &:readline)
previousid=File.open('D:/json/rubycheck.txt', &:readline)
if(latestid.eql?(previousid) )
event['check'] = 'oldid'
else
event['check'] = 'latestid'
end
File.open('D:/json/rubycheck.txt', 'w') {|rubycheck| rubycheck.truncate(0) }
previousIDfile = File.open('D:/json/rubycheck.txt', 'w')
previousIDfile.puts (File.open('D:/json/samplefile2.txt', &:readline))
previousIDfile.close
"

OR

if x==y
event['check'] = 'oldid'
else
event['check'] = 'latestid'
end

It was not working so I thought to do it with logstash so I have changed it

if[oldid] == [newid] #or I tried if[oldid] == "%{newid}"
{
mutate {
add_field => ["status" , "old"]
}
}
else
{
mutate {
add_field => ["status" , "latest"]
}

  }

Its not working , any idea why . and how we can resolve it ?


(Magnus B├Ąck) #2

Have you verified that the oldpid and newpid fields contain the expected values, e.g. by using a stdout { codec => rubydebug } } output?


(Navneet Mathpal) #3

yes,

It is coming as below

"newid" => "1234",
"oldid" => "1234",
"status" => "latest"


(system) #4