# Logstash 6.2.4 Ruby Issue

**URL:** <https://discuss.elastic.co/t/logstash-6-2-4-ruby-issue/133794>\
**Category:** Logstash\
**Created:** [May 30, 2018, 5:52am UTC](https://discuss.elastic.co/t/logstash-6-2-4-ruby-issue/133794 "2018-05-30T05:52:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MariumHassan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mariumhassan/32/30321_2.png) [@MariumHassan](https://discuss.elastic.co/u/MariumHassan)\
**Post date:** [May 30, 2018, 5:52am UTC](https://discuss.elastic.co/t/logstash-6-2-4-ruby-issue/133794/1 "2018-05-30T05:52:16Z")

</div>

Hi,  
I have a Logstash script in which I have created some ruby functions. I have placed them at the beginning of my logstash filter so in this way, they are declared before they are called.

The script works fine when I run it using logstash-5.5.2 but when I try to run it using logstash-6.2.4, it starts giving me method undefined error which I can't seem to resolve.

Any help in this matter will be appreciated.  
Thank you in anticipation.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [May 30, 2018, 6:05am UTC](https://discuss.elastic.co/t/logstash-6-2-4-ruby-issue/133794/2 "2018-05-30T06:05:23Z")

</div>

How could we possibly help out without knowing a) what your Logstash configuration looks like and b) what exact error message you're getting?

---

<div class="post-metadata">

**Author:** ![MariumHassan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mariumhassan/32/30321_2.png) [@MariumHassan](https://discuss.elastic.co/u/MariumHassan)\
**Post date:** [May 30, 2018, 7:44am UTC](https://discuss.elastic.co/t/logstash-6-2-4-ruby-issue/133794/3 "2018-05-30T07:44:52Z")

</div>

Below is my Logstash configuration:

```auto
input
{
  beats 
  {
    port => 5044
  }
}
filter
{
  ruby
  {
    code => "def setLogStatus(event, map)
                 if event.get('port') =~ /\d/
                    event.set('status','ORDER_ID_LOG_SENT');
                 else
                    event.set('status','ORDER_ID_LOG_RECEIVED');
                 end
             end"
  }

  # some other functions & grok here
  
  grok
  {
    match => ["message", "method=%{DATA:event}, %{DATA:data}, to local server: http://(?:%{IPV6}|%{IPV4}):%{NOTSPACE:port}/%{DATA:data}"] 
  }   
	
  ruby
  { 
    code => "setLogStatus(event, @@map);"
  }
}
output
{
  elasticsearch 
  { 
    hosts => ["${ELASTICSEARCH_URL}"]
    index => "${INDEX_NAME}-%{+YYYY-MM-dd}"
  }
}

```

The error I get is following:  
Ruby exception occurred: undefined method `setLogStatus' for #LogStash::Filters::Ruby:0x4f112952

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [May 30, 2018, 8:37am UTC](https://discuss.elastic.co/t/logstash-6-2-4-ruby-issue/133794/4 "2018-05-30T08:37:08Z")

</div>

Stuff inside `code` doesn't survive between different ruby filters. I think it'll work if you instead put it in the ruby filter's `init` option, but I don't understand why you're complicating things. What's the point of defining a function instead of just inlining the code in the ruby filter where you need the code?

---

<div class="post-metadata">

**Author:** ![MariumHassan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mariumhassan/32/30321_2.png) [@MariumHassan](https://discuss.elastic.co/u/MariumHassan)\
**Post date:** [June 12, 2018, 8:30am UTC](https://discuss.elastic.co/t/logstash-6-2-4-ruby-issue/133794/5 "2018-06-12T08:30:01Z")

</div>

I have a file which has almost 800 lines of code so inlining the code is not a good idea for me specially if I consider re-usability.

Yes, you are right. Stuff inside `code` doesn't survive between different ruby filters but what I don't understand is how it was working in the previous version of logstash.

Also, I tried it in `init` but it wasn't working so I had to use inline option.

---

<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:** [July 10, 2018, 8:30am UTC](https://discuss.elastic.co/t/logstash-6-2-4-ruby-issue/133794/6 "2018-07-10T08:30:04Z")

</div>

Closed on July 10, 2018, 8:30am UTC

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