# How to use logstash keystore values in ruby script

**URL:** https://discuss.elastic.co/t/how-to-use-logstash-keystore-values-in-ruby-script/208329
**Category:** Logstash
**Created:** [November 18, 2019, 2:21pm UTC](https://discuss.elastic.co/t/how-to-use-logstash-keystore-values-in-ruby-script/208329 "2019-11-18T14:21:41Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![HansPeterSloot](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hanspetersloot/32/51132_2.png) [@HansPeterSloot](https://discuss.elastic.co/u/HansPeterSloot)
#### Post date: [November 18, 2019, 2:21pm UTC](https://discuss.elastic.co/t/how-to-use-logstash-keystore-values-in-ruby-script/208329/1 "2019-11-18T14:21:42Z")

</div>

Hi,  
When using an external ruby script parameters can be used with  
path =\> "script.rb"  
script\_params =\> {  
"url\_host\_port" =\> "[http://localhost:9200](http://localhost:9200)"  
"url\_username" =\> "{es\_user}" "url\_password" =\> "{es\_password}"  
}

How can I do the same with an 'inline' script?  
Can I just use {es\_user} and {es\_password} in the script directly?

Regards Hans

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [November 18, 2019, 2:32pm UTC](https://discuss.elastic.co/t/how-to-use-logstash-keystore-values-in-ruby-script/208329/2 "2019-11-18T14:32:30Z")

</div>

Use the [event API](https://www.elastic.co/guide/en/logstash/current/event-api.html).

---

<div class="post-metadata">

### Author: ![HansPeterSloot](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hanspetersloot/32/51132_2.png) [@HansPeterSloot](https://discuss.elastic.co/u/HansPeterSloot)
#### Post date: [November 18, 2019, 5:07pm UTC](https://discuss.elastic.co/t/how-to-use-logstash-keystore-values-in-ruby-script/208329/3 "2019-11-18T17:07:39Z")

</div>

It is still not clear to me.  
Can I just reference : event.get("es\_user" ) then if es\_user is defined in the keystore of logstash?  
Or via @metadata  
The documentation is very concise.

Regards Hans

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [November 18, 2019, 5:35pm UTC](https://discuss.elastic.co/t/how-to-use-logstash-keystore-values-in-ruby-script/208329/4 "2019-11-18T17:35:31Z")

</div>

If [es\_user] is a field on the event then in script.rb you can fetch its value using event.get("es\_user")

---

<div class="post-metadata">

### Author: ![HansPeterSloot](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hanspetersloot/32/51132_2.png) [@HansPeterSloot](https://discuss.elastic.co/u/HansPeterSloot)
#### Post date: [November 18, 2019, 7:03pm UTC](https://discuss.elastic.co/t/how-to-use-logstash-keystore-values-in-ruby-script/208329/5 "2019-11-18T19:03:49Z")

</div>

Sorry there is a misunderstanding.  
I want to use logstash keystore values in the inline script.  
Just as my example in my first post.

Parameters can be passed to a ruby script (external).  
How can I do it with an inline ruby script?

Regards Hans

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [November 18, 2019, 11:39pm UTC](https://discuss.elastic.co/t/how-to-use-logstash-keystore-values-in-ruby-script/208329/6 "2019-11-18T23:39:26Z")

</div>

Sorry, I missed that you were referring to the keystore. If the keystore substitutions are done by event.sprintf() then you could try using that. I'm not in a position to test that tonight.

---

<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: [December 16, 2019, 11:46pm UTC](https://discuss.elastic.co/t/how-to-use-logstash-keystore-values-in-ruby-script/208329/7 "2019-12-16T23:46:10Z")

</div>

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