Hi,

In the documentation for graylog. It is written that Functions are written 
in Java and are pluggable, allowing extending the capabilities of Graylog. 
There is no place in documentation where I could find how I could add 
custom Functions. I also looked at the source code from the following 
https://github.com/Graylog2/graylog-plugin-pipeline-processor

I followed the instructions on how to create a plugin and tried to add my 
function by copying certain classes from the above package and building a 
custom plugin. Here are the steps that I followed to do that.

1) Created a plugin skeleton project based on the instructions provided in 
the Plugins section
2) Created a function called to_integer. Copied all the required classes to 
build the function. Here is my sample code to create the to_integer 
function.

public class IntegerConversion extends AbstractFunction<Integer> {


    public static final String NAME = "to_integer";


    private static final String VALUE = "value";

    private static final String DEFAULT = "default";

    private final ParameterDescriptor<Object, Object> valueParam;

    private final ParameterDescriptor<Integer, Integer> defaultParam;


    public IntegerConversion() {

        valueParam = object(VALUE).build();

        defaultParam = toint(DEFAULT).optional().build();

    }


    @Override

    public Integer evaluate(FunctionArgs args, EvaluationContext context) {

        final Object evaluated = valueParam.required(args, context);

        final Integer defaultValue = defaultParam.optional(args, context
).orElse(0);

        if (evaluated == null) {

            return defaultValue;

        }

        return firstNonNull(Ints.tryParse(evaluated.toString()),

                            defaultValue);

    }


    @Override

    public FunctionDescriptor<Integer> descriptor() {

        return FunctionDescriptor.<Integer>builder()

                .name(NAME)

                .returnType(Integer.class)

                .params(of(

                        valueParam,

                        defaultParam

                ))

                .build();

    }

}

3) I was not sure what should be done after that. I also added the Function 
the FunctionPluginModule and then installed it. But I did not see any error 
or the function getting created. Please let me know if I am missing 
something.

-- 
You received this message because you are subscribed to the Google Groups 
"Graylog Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/graylog2/3d6971cc-37d5-41d1-b688-4945b6a0d193%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to