I wanted to know if it's possible to write an advanced ruby code into a logstash filter in order to keep specific value.
I have something like:
ruby {
code => "
_isInCyclic = false
_isJump = false
_loggerName = ''
_currentLine = event.get('message')
if _loggerName == ''
if _currentLine['[SynchronizedThreadPoolStatistics] Cyclic thread pool statistics']
_loggerName = 'SynchronizedThreadPoolStatistics'
event.tag('inCyclicSynchro')
else if _currentLine['[ThreadPoolStatistics] Cyclic thread pool statistics']
_loggerName = 'ThreadPoolStatistics'
event.tag('inCyclicThread')
end
end
end
if !_isInCyclic && _currentLine['[' + _loggerName + '] Cyclic thread pool statistics']
print(_loggerName)
_isInCyclic = true
_isJump = true
elsif _isInCyclic && _currentLine['Total thread pool statistics']
_isInCyclic = false
elsif _isInCyclic && _currentLine['Cyclic thread pool statistics']
_isJump = true
elsif _isInCyclic
if _isJump
_isJump = false
else
if _currentLine['[' + _loggerName + ']' + ' ']
event.tag('LineIwantToKeep')
end
end
end
"
}
When I run the code, logstash works normaly but it seems like he never going through the second if statement "if !_isInCyclic && _currentLine['[' + _loggerName......" so I don't see my tag "LineIwantToKeep" appears on lines that I want to send to ES.
I thought that this is because a filter is apply line by line no? Is it possible to tell logstash that we want have variables outside of the loop?