Convert a field value from Decimal to Hexa

Hello,
So after applying the GROK filter ,i have a field that it's value is in decimal. I need to convert it to Hexa. i tried this :

 ruby { 
	code => "event.set('%{AgentID}', event.get('%{AgentID}').to_s.hex)" 
	} 

the AgentID is the field containing the decimal value that need to be converted to Hexa.
the value remains in decimal with this code.
Any suggestions ?

    mutate { add_field => { "someField" => 65533 } }
    ruby { code => 'event.set("hexField", event.get("someField").to_i.to_s(16))' }

gets me

 "someField" => "65533",
  "hexField" => "fffd"

Thanks @Badger , it worked just fine

ruby { code => 'event.set("someField", event.get("someField").to_i.to_s(16))' }

will also work.

1 Like

sorry @Badger if i might ask,
where did you find the description of these functions like .to_i.to_s,
i didn't find it in the documentation. could you give me a link where to find such functions ?

It is a ruby filter, so you will find those functions in the Ruby language documentation, not in the logstash documentation.

@Badger again thank you so much

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