Passing parameters to Java filter plugin during runtime

The Java filter plugin example ( was called without any inputs because everything is fixed during compilation time. This makes the plugin less generic. Is it possible to pass some user inputs to the Java plugin during runtime? I could not find any examples or documentations.

If you asking whether a filter can have options then the answer is yes. The example you linked to includes an option.

Would you please be more specific? I could not find the "options" in this example. Thanks.

Just to make sure we are using the same terminology. When I speak of options I am talking about things like the allow_duplicate_values option of a kv filter, or the source and target options of a json filter.

The java plugin documentation refers to these as settings, which is inconsistent with most logstash documentation.

The PluginConfigSpec code allows the filter writer to define options using just the name, or the name and default value (the example in the documentation), all the way up to the name, the type, the defaultValue, whether the option is deprecated, whether it is required, and what its children are. And no, I have no idea what children means in this context.

I assume if you are writing a Java plugin you can figure out what PluginConfigSpec java code does, since your knowledge of Java is almost certainly far better than mine :smiley:


Here is my use case.

I am writing a plugin to calculate time duration. In my logs, there are fields called "timetaken" or "sqltime" or "acltime", and many other names. But they all in the form of "hour:minute:second:millisecond". With the information provided by the Java plugin example, I have to hardcode the field name (e.getField("timetaken")) in order to get the value. This limits the plugin only works for logs with field name as "timetaken". I want to be able to use e.getField(input_parameter), where this input_parameter (can be "timetaken", "sqltime", "acltime",...) is passed in from Logstash pipeline. This will make plugin generic. In other words, can I invoke the plugin just like making an api call with parameters? I could not find any examples or documents on this. Logstash built-in Java plugins are not implemented with these APIs.

Read through the documentation and focus on how sourceField is used. The example plugin only has one option, but you could have more than one.

The helper code may help you see how to configuration multiple options.

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