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

Replacing a value at the end of a string #643

Closed
ppcad opened this issue Aug 8, 2024 · 5 comments
Closed

Replacing a value at the end of a string #643

ppcad opened this issue Aug 8, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@ppcad
Copy link
Collaborator

ppcad commented Aug 8, 2024

I would like to replace certain values in a string with other values.

i.e. replace the number in the following string with NUMBER:

Input: "...this is a variable text... CONSTANT 543435"
Output: "...this is a variable text... CONSTANT NUMBER"

There can be multiple rules with a different CONSTANT that also require this replacement.

Is it possible to achieve this with a single processor, except for the normalizer?
I have found a work-around using the dissector. Here I use & to get a prefix at the end, assuming & never appears in the string:
%{target} CONSTANT %{}&%{+( CONSTANT NUMBER)target}
Is there a better way using one processor? This work-around would not be necessary if the dissector could add a suffix.

@ppcad ppcad added the question Further information is requested label Aug 8, 2024
@ekneg54 ekneg54 added the enhancement New feature or request label Aug 9, 2024
@ekneg54
Copy link
Collaborator

ekneg54 commented Aug 9, 2024

no... there is no solution yet.
we could implement a new processor for this. I do not suggest to extend the dissector for that, because it is build to dissect not to replace. A new processor replacer should do the job.

@ppcad
Copy link
Collaborator Author

ppcad commented Aug 9, 2024

Thanks, this sounds like a good solution to me.

@ekneg54
Copy link
Collaborator

ekneg54 commented Aug 9, 2024

we could implement this with the same syntax as the dissector. Then translate this to a python string template in the rule and then process the event with this built template. see: https://docs.python.org/3/library/string.html#template-strings

@ppcad
Copy link
Collaborator Author

ppcad commented Aug 9, 2024

This looks good. We would also need to handle the case where some variable part of a text shouldn't be replaced.

Input: Replace this number 4325435, but not this one 645354
Output: Replace this number NUMBER, but not this one 645354

@ppcad
Copy link
Collaborator Author

ppcad commented Dec 5, 2024

Will be solved by #699

@ppcad ppcad closed this as completed Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants