Hello everyone,
I'm having a problem with one of my automations. I have vulnerability tickets that contain a paragraph field with different host names.
Now I want to go through this field with host names in an automation and count how many hosts that match a regex are contained in total.
But it just doesn't work. I think it's because of my wrong approach.
have vulnerability tickets that contain a paragraph (multi-line) text field listing multiple hostnames, for example:
example-ce003.example.local, example-ce004.example.local, example-cf104.example.local, example-cf116.example.local
My goal is:
Go through this paragraph field in the automation and count how many hostnames match a certain regex pattern, such as:
example-cf*.example.local
The soltuion should be: 2
Unfortunately, match() hasn't worked so far.
Ultimately, I want to store the number of my results in a variable. For example, when I use log, the field of the field is displayed, but when I use size, match, or a function, nothing is displayed. Can anyone help me with the solution?
Best regards!
Hi @Florian Beqiri !
I would go for a more simplistic approach:
If the texts is always of this format, I would use the split(",") function and then apply the size() function.
it would be something like this: issue.customfield.split(",").size
For a question like this, context is important for the community to help. Please post the following:
Until we see those...
The automation match() function can have challenges with some field formatting and there is no documentation of what does (or does not) work with regex. Instead, the doc only states the "underlying implementation is based on Java's Pattern class". Experimentation is key to confirm what works, perhaps starting with a very simple expression, testing that, and incrementally adding edge cases.
Maybe try this as a start, using an example custom field ID:
{{issue.customfield_12345.replace("\n", " ").match("(example\-cf.*\.example\.local)").size|0}}
Please note the replacement of any newlines and adding escaping for characters that could be interpreted as reserved tokens in the expression.
That would be the total count. If you want the unique count, add a distinct function:
{{issue.customfield_12345.replace("\n", " ").match("(example\-cf.*\.example\.local)").distinct.size|0}}
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.