# New logstash output plugin not getting config value correctly

**URL:** <https://discuss.elastic.co/t/new-logstash-output-plugin-not-getting-config-value-correctly/218786>\
**Category:** Logstash\
**Created:** [February 11, 2020, 2:25pm UTC](https://discuss.elastic.co/t/new-logstash-output-plugin-not-getting-config-value-correctly/218786 "2020-02-11T14:25:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fostec82](https://avatars.discourse-cdn.com/v4/letter/f/b782af/32.png) [@fostec82](https://discuss.elastic.co/u/fostec82)\
**Post date:** [February 11, 2020, 2:25pm UTC](https://discuss.elastic.co/t/new-logstash-output-plugin-not-getting-config-value-correctly/218786/1 "2020-02-11T14:25:58Z")

</div>

I am attempting to create a new output plugin. The conf is pretty simple

```auto
input {
    stdin{}
}

filter {
  mutate {
    add_field => {
      "[some_new_field]" => "some_new_field_value"
    }
  }
}

output {

  mynewplugin{
    value_to_plugin => "%{[some_new_field]}"
  }
 
  stdout { codec => rubydebug { metadata => true }}
}

```

Then in my plugin I simply have:

```auto
# encoding: utf-8
require "logstash/outputs/base"
require "logstash/namespace"

class LogStash::Outputs::MyNewPlugin < LogStash::Outputs::Base

  config_name "mynewplugin"
  default :codec, 'plain'

  # Replace the message with this value.
  config :value_to_plugin, :validate => :string, :default => "default_value"
  
  concurrency :single

  public
  def register
    # Add instance variables
  end # def register

  public
  def receive(event)

    File.open("/tmp/log.txt", "w") { |f| f.write @value_to_plugin }

    return "Event received"

  end # def filter

end # class LogStash::Outputs::MyNewPlugin

```

The plugin is getting called correctly but the string written to /tmp/log.txt is:

```auto
%{[some_new_field]}

```

but I expect it to be:

```auto
some_new_field_value

```

I have checked many other plugins as this is a pretty common operation, but can not find my mistake.

---

<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:** [February 11, 2020, 2:30pm UTC](https://discuss.elastic.co/t/new-logstash-output-plugin-not-getting-config-value-correctly/218786/2 "2020-02-11T14:30:08Z")

</div>

I believe you would need to call event.sprintf to make that transformation.

---

<div class="post-metadata">

**Author:** ![fostec82](https://avatars.discourse-cdn.com/v4/letter/f/b782af/32.png) [@fostec82](https://discuss.elastic.co/u/fostec82)\
**Post date:** [February 11, 2020, 2:39pm UTC](https://discuss.elastic.co/t/new-logstash-output-plugin-not-getting-config-value-correctly/218786/3 "2020-02-11T14:39:28Z")

</div>

Within the \*.rb file? I will give that a try.

---

<div class="post-metadata">

**Author:** ![fostec82](https://avatars.discourse-cdn.com/v4/letter/f/b782af/32.png) [@fostec82](https://discuss.elastic.co/u/fostec82)\
**Post date:** [February 11, 2020, 3:52pm UTC](https://discuss.elastic.co/t/new-logstash-output-plugin-not-getting-config-value-correctly/218786/4 "2020-02-11T15:52:19Z")

</div>

Ok, that did indeed get me over the hump:

```auto
interp_value = event.sprintf(@value_to_plugin)

```

The resulting `interp_value` is what I would expect it to be. Thanks for quick feedback.

---

<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 10, 2020, 3:52pm UTC](https://discuss.elastic.co/t/new-logstash-output-plugin-not-getting-config-value-correctly/218786/5 "2020-03-10T15:52:22Z")

</div>

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