# How to use ruby script file with parameter?

**URL:** <https://discuss.elastic.co/t/how-to-use-ruby-script-file-with-parameter/117537>\
**Category:** Logstash\
**Created:** [January 29, 2018, 9:20pm UTC](https://discuss.elastic.co/t/how-to-use-ruby-script-file-with-parameter/117537 "2018-01-29T21:20:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![asp](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@asp](https://discuss.elastic.co/u/asp)\
**Post date:** [January 29, 2018, 9:20pm UTC](https://discuss.elastic.co/t/how-to-use-ruby-script-file-with-parameter/117537/1 "2018-01-29T21:20:49Z")

</div>

Hi,

sometimes I used ruby as logstash filter plugin - only the inline functionality until now. Additionally I have to admit, that I am not really fond of ruby.

Now I wanna outsource the code to a script file, but I do not understand the explanation at [https://www.elastic.co/guide/en/logstash/current/plugins-filters-ruby.html](https://www.elastic.co/guide/en/logstash/current/plugins-filters-ruby.html)

I would like to do the following:

- create a field which has the current timestamp as value and store it in the event
- set a part of the name as variable (variable name)

Following ruby code snipped should work:

```
myTime=timeStart=DateTime.now.strftime("%Q").to_i    
event.set("[logstash][debug][" + name + "]",myTime )    

```

But I do not understand how to outsource this to a file and how to give the name as parameter.

Can anyone provide an example on this simple issue?

Thanks, Andreas

---

<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:** [January 30, 2018, 6:41am UTC](https://discuss.elastic.co/t/how-to-use-ruby-script-file-with-parameter/117537/2 "2018-01-30T06:41:45Z")

</div>

From where would `name` come in your inline Ruby snippet?

---

<div class="post-metadata">

**Author:** ![asp](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@asp](https://discuss.elastic.co/u/asp)\
**Post date:** [January 30, 2018, 6:59am UTC](https://discuss.elastic.co/t/how-to-use-ruby-script-file-with-parameter/117537/3 "2018-01-30T06:59:53Z")

</div>

its not done yet.

I am looking for a way to set this as parameter / argument when I call the script file inside the logstash filter clause.

---

<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:** [January 30, 2018, 7:12am UTC](https://discuss.elastic.co/t/how-to-use-ruby-script-file-with-parameter/117537/4 "2018-01-30T07:12:33Z")

</div>

Did you look at the `script_params` option described in the documentation?

---

<div class="post-metadata">

**Author:** ![asp](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@asp](https://discuss.elastic.co/u/asp)\
**Post date:** [January 30, 2018, 7:14am UTC](https://discuss.elastic.co/t/how-to-use-ruby-script-file-with-parameter/117537/5 "2018-01-30T07:14:09Z")

</div>

yes, but unfortunately I did not understand it. Maybe too few ruby knowledge...

---

<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:** [February 27, 2018, 7:14am UTC](https://discuss.elastic.co/t/how-to-use-ruby-script-file-with-parameter/117537/6 "2018-02-27T07:14:29Z")

</div>

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