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
Hi,
But how do I get the number of values I need to search for?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, I thought that since you were mentioning "match()" that you already know about smart values. The formula above needs to be integrated between {{ and }}.
{{issue.customfield.split(",").size}}
You can either create a custom field to store the value, and then you need to have an "edit work item" action -> set value -> use the formula
Or, let's say you want to send an email with this information, you can use the formula as is in the email body. e.g. "this string contains {{issue.customfield.split(",").size}} hostnames"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
Hi,
I think that I cannot follow you. Could you please give me an example using lookupissues?
Best regards,
Florian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
First thing: if you are having difficulty following that explanation, please pause to review these documentation pages before proceeding. They will help you understand how rules, smart value lists, and the match() function will interact:
Next, the example I provided would work for a single work item. The expression might be slightly different for a Lookup Work Items result...dependent upon what you are trying to do with that information.
Please post images of the following for context:
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.