Filter first match only using Grok or ruby code

I have a field that contains the following data

"REQUEST-941-APPLICATION-ATTACK-XSS, REQUEST-941-APPLICATION-ATTACK-XSS, REQUEST-941-APPLICATION-ATTACK-XSS, REQUEST-942-APPLICATION-ATTACK-SQLI, REQUEST-949-BLOCKING-EVALUATION, RESPONSE-980-CORRELATION

And I want to return the first item only ie: (REQUEST-941-APPLICATION-ATTACK-XSS), but when i use this grok filter

grok
    {
        match => {"attack_names" => "(?<attack>^[A-Z1-9-]+)"}
        remove_field => ["attack_names"]
    }

it return all occurrences

"REQUEST-941-APPLICATION-ATTACK-XSS, REQUEST-941-APPLICATION-ATTACK-XSS, REQUEST-941-APPLICATION-ATTACK-XSS, REQUEST-942-APPLICATION-ATTACK-SQLI, REQUEST-949-BLOCKING-EVALUATION, RESPONSE-980-CORRELATION

So, I tried this ruby code:

ruby 
    {
 	code => "
    		saveid = event.get('attack_names').split(',')[0]
    		event.set('attack',saveid)
    		"
    }

but this dosen't seem to do anything and the field isn't added to the data.

So, what I'm doing wrong here?

  1. Grok
grok
    {
        match => {"attack_names" => "%{USERNAME:attack},\s+"}
        remove_field => ["attack_names"]
    }
  1. Use csv plugin on attack_names, rename only column1
  2. Use mutate gsub to split by "," , your array will have 1st member [0]

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