cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using a wildcard in DPL and matchesPattern()

Inaylor01
Observer

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:

  • "ABCDE-1234"
  • "ABXYZ-3492"
  • "ABLOL-1000.some.name"

My original thought was creating a matchesPattern() along the line of -

  • matchesPattern(entity.name, "'AB' LD{3} '-' DIGIT{4}")

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()?

 

 

 

 

2 REPLIES 2

RafaelF
Visitor
Hello.
 
I'm not sure if there is a correct way, but there are probably many ways to achieve what you are trying to do.
 
For the DPL pattern including the "LD?" will match anything (optionaly), adding it at the end will capture all the 3 examples, you can also add it on the start if necessary.
filter matchesPattern(name, "LD? 'AB' LD{3} '-' DIGIT{4} LD?")
 
Other possible solutions I could think of:
 
1. You can still use managementZones even though somewhat limited
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)"))
 
2. If you are using this for the new dashboards you could also create a hidden variable with a predefined list of hosts name/ids, set it to select all by default and use it to filter for the ones you want.
 
Let me know if you need more help!
Best Regards,
Rafael Fernandes

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!

Featured Posts