New logstash output plugin not getting config value correctly

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

input {

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

output {

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

Then in my plugin I simply have:

# 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

  def register
    # Add instance variables
  end # def register

  def receive(event)"/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:


but I expect it to be:


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

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

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

Ok, that did indeed get me over the hump:

interp_value = event.sprintf(@value_to_plugin)

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

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