So I'm an amateur ruby user and I'm trying to figure this out, but a bit hard trying to mesh my limited ruby knowledge and trying to incorporate it with how the ruby plugin works in logstash.
I'd like to somehow save a global variable or array that I can use in consecutive logstash ingest events.
For example:
The first time logstash starts, it imports a document with field AppDomain: 12345. I'd like to store this document's field, "subject", in an array, FlaggedSubjects, and then logstash finishes its run and outputs as normal to ES. Then the next time it runs, I want all of the next documents with a subject to come through and check if it's AppDomain is the same as the first one by looking at FlaggedSubjects[0]. If it isn't then it can go through and if it is, I want to do some action.
I can't seem to get an array to be "global" or usable between different logstash ingest events. Is this at all possible with logstash? Before I spend another couple days on this, it would be good to know if I'm even going in the right direction.
Here's what I've written thus far:
if 12345 in [AppDomain]{
ruby {
init => ""
code => "
FlaggedSubjects = Array.new;
FlaggedSubjects << event.get('subject')"
}
if [subject]{
ruby {
init => ""
code => "
if event.get('AppDomain') == FlaggedSubjects[0]
event.set('tags','HELLO')
end"
}
Any help?