Regular expression support in systemFilter?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Regular expression support in systemFilter?

Jason
Hello there,

I have a question regarding creating your own systemFilter and passing that via the REST API.  Is there any way to specify a regular expression?  I see in the documentation here: http://pongasoft.github.io/glu/docs/latest/html/filtering.html#filter-syntax that you can use "and" "or" and "not" , but don't see anything about pattern matching or wildcards or anything.

In a systemFilter, I'd like to search across multiple fabrics with a pattern for the mountPoint.  For instance, I have dozens of mountPoints, tagged as "webserver", some are tagged with "production" and and some tagged with "staging" also. Inside this set, I only want to target mountPoints that are /server/w*

Is it possible to do something like this:
    and {
        tags='webserver'
        or {
            tags='production'
            tags='staging'
        }
        mountPoint='/server/w.*'
    }

Or something like:  
    or {
        mountPoint=.*test.*
        mountPoint=/mon.*/
    }

Is this possible to do?  If its not currently possible, how could I go about doing something like this?

Thanks very much!
Jason
Reply | Threaded
Open this post in threaded view
|

Re: Regular expression support in systemFilter?

frenchyan
Administrator
Unfortunately at this time, regular expression is not supported in the filter syntax. Besides changing the code to support it I would suggest tagging your entries with what you want to filter on. In your last example it seems that you have some "test" mountPoints, so you could add "test" tag...


which lets you write your own groovy filter code

c("test") {
  it.mountPoint.toString().contains("test")
}

Yan
Reply | Threaded
Open this post in threaded view
|

Re: Regular expression support in systemFilter?

Jason
Yan, thanks very much for the response.

I didn't realize you could inject your own groovy filter code.  I'm not very familiar with groovy at all, but looking at some of the documentation, there's a "matches()" method which supports "patterns" (these are standard regexps I believe?)

   http://groovy.codehaus.org/groovy-jdk/java/lang/String.html#matches(java.util.regex.Pattern)
   http://docs.oracle.com/javase/1.5.0/docs/api/java/util/regex/Pattern.html

So, this actually appears to do what I want (from my limited testing).

and {
    c("servtest") {
        it.mountPoint.toString().contains("servtest")
    }
    or {
        c(".*serv.*") {
            it.mountPoint.toString().matches(".*serv.*")
        }
        c("/s[ader].*r\$") {
            it.mountPoint.toString().matches("/s[ader].*r\$")
        }
    }
}

The regexps are pretty ugly, but such is the live of a regexp :)

It appears to take all sorts of valid regexps.  It looks as though I can put the c() functions in any "and" "or" or "not" block. This appears to be exactly what I need, do you see any "gotchas" with this approach?  Or anything that I'm missing?

Thanks again for the response,
Jason
Reply | Threaded
Open this post in threaded view
|

Re: Regular expression support in systemFilter?

frenchyan
Administrator
I am glad that it works. I think the only huge gotcha I can think of is that the closure is executed for every single entry in your model... so the regexps are going to be recompiled for every entry in your model. So it will definitely work but it might be slow if your models are big. Unfortunately there is no way around it​ at this stage as the filter syntax does not let you define a variable for example (which sounds like a cool feature to add :). At this stage I would suggest testing it on your typical model and see how it behaves.

Yan
Reply | Threaded
Open this post in threaded view
|

Re: Regular expression support in systemFilter?

Jason
Awesome!

Last question, since this is undocumented, could it disappear from future releases?  Or do you foresee leaving it in there?

Thanks again,
Jason
Reply | Threaded
Open this post in threaded view
|

Re: Regular expression support in systemFilter?

frenchyan
Administrator
No it won't disappear. It needs to be added to the documentation.

Yan