22 May 2025
09:44 PM
- last edited on
23 May 2025
08:49 AM
by
MaciejNeumann
Hi all,
I've been diving into DPL and the matchesPattern() function to get around the lack of regex in filtering DQL results, so far all is well but I'm running into an issue.
Say for example, I'm filtering a set of hosts from a fetch dt.entity.host DQL query and I want to filter down specific hosts. I understand the way to create a DPL pattern that filters down some of those hosts, in the same vein as Regex.
The only roadblock I seem to not be able to get around is understanding how wildcards are implemented in DPL, if any. If I have multiple hosts names like this:
My original thought was creating a matchesPattern() along the line of -
This would capture the first two host names listed above but to capture all three, I would of course use a wildcard to optionally include anything after the four digits of the name. However, unless I'm missing something while reading through the documentation for DPL, I don't see a case for using a wildcard. Something that would allow me to match any cases where the pattern is explicitly matched *and* is contained in a larger string.
I may be going about this wrong but in a use case where I want to filter based off of a specific pattern (explicitly or included in a larger string), would DPL still be the correct way? Or should I be using something like contains()?
Solved! Go to Solution.
22 May 2025 10:42 PM
filter matchesPattern(name, "LD? 'AB' LD{3} '-' DIGIT{4} LD?")
fetch dt.entity.host
| filter in(managementZones, "my_mz")
timeseries avg(dt.host.cpu.idle), filter: in(dt.entity.host, classicEntitySelector("type(HOST),mzName(my_mz)"))
23 May 2025 05:33 PM
Thanks for the reply, Rafael
The first solution with LD? worked perfectly, don't know how I missed that. The other solutions were also valuable- will keep those two in mind if this ever becomes a larger scope!
Thanks again!