# Ruby syntax error

**URL:** <https://discuss.elastic.co/t/ruby-syntax-error/252197>\
**Category:** Logstash\
**Created:** [October 15, 2020, 12:56pm UTC](https://discuss.elastic.co/t/ruby-syntax-error/252197 "2020-10-15T12:56:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jan\_Kabelka](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jan_kabelka/32/72840_2.png) [@Jan\_Kabelka](https://discuss.elastic.co/u/Jan_Kabelka)\
**Post date:** [October 15, 2020, 12:56pm UTC](https://discuss.elastic.co/t/ruby-syntax-error/252197/1 "2020-10-15T12:56:46Z")

</div>

Hi, I did not find anything what would work therefore please let me ask... I need to create new field with length of DNS domain. Also I would like to have another field with entropy value for that DNS domain.

What field I have:  
dns.domain.name (e.g: "dns.domain.name" : "[translate.google.com](http://translate.google.com)")

What fields I would like to have:  
dns.domain.name\_length (e.g: "dns.domain.name\_length" : "20")  
dns.domain.name\_entropy (e.g: "dns.domain.name\_entropy" : "3.48")

What I wrote for "length" part (and does not work) is:  
ruby {

code =\> "event.set('[dns][domain][name\_length]', event.get('[dns][domain][name]').length)"

}

How to create new field "dns.domain.name\_entropy" I do not know at all.

Thanks anybody for help! Jan

---

<div class="post-metadata">

**Author:** ![mastersmit](https://avatars.discourse-cdn.com/v4/letter/m/f475e1/32.png) [@mastersmit](https://discuss.elastic.co/u/mastersmit)\
**Post date:** [October 15, 2020, 1:57pm UTC](https://discuss.elastic.co/t/ruby-syntax-error/252197/2 "2020-10-15T13:57:01Z")

</div>

I dont see this is a valid ruby script

event.set('[dns][domain][name\_length]', event.get('[dns][domain][name]').length)

you can try this in order to debug if you are getting correct value for each attribute:

```
ruby {

code => "
puts [dns]
puts [dns][domain]
puts [dns][domain][name]
event.set('[dns][domain][name_length]', event.get('[dns][domain][name]').length)"

}
```

---

<div class="post-metadata">

**Author:** ![Jan\_Kabelka](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jan_kabelka/32/72840_2.png) [@Jan\_Kabelka](https://discuss.elastic.co/u/Jan_Kabelka)\
**Post date:** [November 2, 2020, 10:39am UTC](https://discuss.elastic.co/t/ruby-syntax-error/252197/3 "2020-11-02T10:39:58Z")

</div>

Hi, thanks. It works like below:

if [dns][question][subdomain] {  
ruby {

```
    code => 'event.set("[dns][question_subdomain_length]", event.get("[dns][question][subdomain]").length);'

```

}

---

<div class="post-metadata">

**Author:** ![Jan\_Kabelka](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jan_kabelka/32/72840_2.png) [@Jan\_Kabelka](https://discuss.elastic.co/u/Jan_Kabelka)\
**Post date:** [November 2, 2020, 10:40am UTC](https://discuss.elastic.co/t/ruby-syntax-error/252197/4 "2020-11-02T10:40:21Z")

</div>

Any idea for entropy calculation? Thanks!

---

<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:** [November 30, 2020, 10:40am UTC](https://discuss.elastic.co/t/ruby-syntax-error/252197/5 "2020-11-30T10:40:31Z")

</div>

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