# Arbitrary hash to CEF custom fields?

**URL:** <https://discuss.elastic.co/t/arbitrary-hash-to-cef-custom-fields/321422>\
**Category:** Logstash\
**Created:** [December 16, 2022, 3:57pm UTC](https://discuss.elastic.co/t/arbitrary-hash-to-cef-custom-fields/321422 "2022-12-16T15:57:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![j00bar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/j00bar/32/114777_2.png) [@j00bar](https://discuss.elastic.co/u/j00bar)\
**Post date:** [December 16, 2022, 3:57pm UTC](https://discuss.elastic.co/t/arbitrary-hash-to-cef-custom-fields/321422/1 "2022-12-16T15:57:49Z")

</div>

I'm using the `cef` codec for encoding data.

CEF lets you add custom attributes with a series of `deviceCustom*` fields. If you've got an attribute `confidence` and its value is `high`, you can say in CEF: `deviceCustomString1Label=confidence deviceCustomString1=high`. This requires the message itself be a hash with separate keys for `deviceCustomString1` and `deviceCustomString1Label`.

So I need to transform my input to fit. My input as JSON includes `"attributes": {"confidence": "high"}` but I need to mutate this to `{"deviceCustomString1Label": "confidence", "deviceCustomString1": "high"}`. What's more, I need to do this not knowing what the keys of `attributes` are - I want to iterate over the keys, enumerating them, and creating the CEF structure that way.

This feels beyond what the built in filters support, but I figured I'd ask to see if anybody has any wisdom. Thanks!

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [December 16, 2022, 4:37pm UTC](https://discuss.elastic.co/t/arbitrary-hash-to-cef-custom-fields/321422/2 "2022-12-16T16:37:14Z")

</div>

You can do something like this, but you will need to use the `ruby` filter and write a ruby code to create your custom fields.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 13, 2023, 4:37pm UTC](https://discuss.elastic.co/t/arbitrary-hash-to-cef-custom-fields/321422/3 "2023-01-13T16:37:50Z")

</div>

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