# How to move ruby code from logstash.conf into ingest pipeline?

**URL:** <https://discuss.elastic.co/t/how-to-move-ruby-code-from-logstash-conf-into-ingest-pipeline/167690>\
**Category:** Beats\
**Tags:** filebeat\
**Created:** [February 8, 2019, 10:25pm UTC](https://discuss.elastic.co/t/how-to-move-ruby-code-from-logstash-conf-into-ingest-pipeline/167690 "2019-02-08T22:25:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![apaulsen](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@apaulsen](https://discuss.elastic.co/u/apaulsen)\
**Post date:** [February 8, 2019, 10:25pm UTC](https://discuss.elastic.co/t/how-to-move-ruby-code-from-logstash-conf-into-ingest-pipeline/167690/1 "2019-02-08T22:25:42Z")

</div>

I've a logstash configuration file which contains ruby code.  
**How can I script the ruby part of the logstash filter in ingest pipeline?**

It's a server with filebeat.  
All part except the ruby code I "moved" into the ingest pipline definition.

**my\_logstash.conf**

filter {  
csv {  
columns =\> ['BL','MA',OffsetByte,'LengthByte']  
separator =\> ";"  
autogenerate\_column\_names =\> false  
}  
mutate {  
add\_field =\> { "my\_stats" =\> "%{path}" }  
convert =\> {  
"LengthByte" =\> "integer"  
}  
}  
**ruby** {  
code =\> "  
stats = IO.read(event.get('my\_stats'), event.get('LengthByte'), event.get('OffsetByte') )  
linecount = stats.scan(/\n/).count  
event.set('Statistics', stats[0..-(linecount+1)])  
"  
}

}  
}

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [February 9, 2019, 6:31am UTC](https://discuss.elastic.co/t/how-to-move-ruby-code-from-logstash-conf-into-ingest-pipeline/167690/2 "2019-02-09T06:31:28Z")

</div>

Ingest node pipelines do not support Ruby, so the only way I can think of would be to try and move this logic into a painless script.

---

<div class="post-metadata">

**Author:** ![apaulsen](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@apaulsen](https://discuss.elastic.co/u/apaulsen)\
**Post date:** [February 10, 2019, 9:26am UTC](https://discuss.elastic.co/t/how-to-move-ruby-code-from-logstash-conf-into-ingest-pipeline/167690/3 "2019-02-10T09:26:14Z")

</div>

> [@apaulsen](#):
>
> stats = IO.read(event.get('my\_stats'), event.get('LengthByte'), event.get('OffsetByte') )  
> linecount = stats.scan(/\n/).count  
> event.set('Statistics', stats[0..-(linecount+1)])  
> "

I'll give a try

"filters": [  
{  
"ruby": {  
"code": "stats = IO.read(event.get('path\_stats'), event.get('LengthByte'),event.get('OffsetByte')) linecount = stats.scan(/\n/).count event.set('Statistics', stats[0..-(linecount+1)])"  
}  
}  
],

later more, when tested

---

<div class="post-metadata">

**Author:** ![apaulsen](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@apaulsen](https://discuss.elastic.co/u/apaulsen)\
**Post date:** [February 11, 2019, 11:56am UTC](https://discuss.elastic.co/t/how-to-move-ruby-code-from-logstash-conf-into-ingest-pipeline/167690/4 "2019-02-11T11:56:51Z")

</div>

> [@apaulsen](#):
>
> IO.read

IO.read -\> cannot access Input file via Pipeline, so this is not a solution

---

<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:** [March 11, 2019, 11:57am UTC](https://discuss.elastic.co/t/how-to-move-ruby-code-from-logstash-conf-into-ingest-pipeline/167690/5 "2019-03-11T11:57:03Z")

</div>

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