Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment with JavaScript as a pipeline language #19351

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

thll
Copy link
Contributor

@thll thll commented May 15, 2024

This is a prototypical implementation of JavaScript as a pipeline language. It should enable us to evaluate whether using JavaScript is generally feasible. The implementation is expected to have many rough edges and may cut corners.

How to test this:

Create a JavaScript test rule in a file called test.js:

"use strict";

const name = 'javascript test';

const when = (msg) => !!msg.json;

const then = (msg, {set_fields}) => {
    let json = JSON.parse(msg.json);
    set_fields(json, "js_", null, null, null);

    Object.assign(msg, {'js_a' : 'a', 'js_b' : 'b'});

    for (let i = 0; i < 10; i++) {
        msg[`js_field_${i}`] = i;
    }
};

export default { 'name': name, 'when': when, 'then': then };

Upload it with httpie:

http --auth admin:admin POST :9000/api/system/pipelines/rule X-Requested-By:me content_type=application/javascript+module source=@./test.js

Remember the ID of the created rule, and, if you want to modify it later, upload the changed code like this:

http --auth admin:admin PUT :9000/api/system/pipelines/rule/<rule-id> X-Requested-By:me content_type=application/javascript+module source=@./test.js

Use the Graylog UI to assign the rule to a pipeline and then send messages with a json field set. You should see the additional fields set on the message.

/nocl Not planned as a feature right now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant