Http filter for each array item

I have a filter that I need to apply to each item of an array that I obtain from an earlier filter. It works fine for a single input like this:

http {
    url => "http://my.api.com/api/v1/%{id}?verbose=false"
    headers => {
      "auth" => "auth_string_here"
    }
} 

However I need to run this same request over an array of ids. I can loop over them with a ruby filter but I can't find a way to make the http request and put the results in a new array of the same length. Is this possible?

mutate {
    split => {"ids" => ","}
}
ruby {
    event.get('ids').each do |item|
    ## make get request to 'http://my.api.com/api/v1/item' with auth header
    ## and put the response in a new array
}

If you don't mind making some adjustement in the result, something like that could work:

filter {
  
 mutate {
   split => {"ids" => ","}
 }

 split {
   field => "ids"
   target => "id"
   remove_field => ["ids"]
 }
 
 http {
    url => "http://my.api.com/api/v1/%{id}?verbose=false"
    headers => {
      "auth" => "auth_string_here"
    }
  } 

}

One new event will be created for each id, and you will be able to apply on him the filter http.

The downside of this solution is that you will have a lot more events than initialy, and if you have a lot of data passing through, it may be problematic in term of storage.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.