Forum Discussion

Joe_Tran's avatar
Joe_Tran
Icon for Advisor rankAdvisor
7 years ago

Groovy hostProps method to fetch device properties using wildcard/glob/regex

I've setup a few custom properties that define if an Oracle database exists and the port it listens on in a key-value pair/JSON syntax. These properties are named in <ApplicationName>.databases format (e.g. app1.databases & app2.databases).

Not wanting to repeat myself, I have a set of datasources that query the common Oracle datapoints, but I would like a way to combine all of these *.databases properties together without having to constantly update the datasources or a propertysource whenever I have a new application to monitor.

It would be nice to have a method in the hostProps class that supports getting device properties using a wildcard, glob, or regular expression.

2 Replies

Replies have been turned off for this discussion
  • Hey Joe,

    I'm not sure that this exactly meets your needs, but I think it's a good start.  Basically, you can call hostProps.toProperties() method which spits out an array that you can now dig through and filter using regex.  Something like this:

    def allProps = hostProps.toProperties()
    allProps.each{
        if(it ==~ /.*\.databases=/){
            println it
        }
    }

    Let me know if this doesn't address what you're trying to accomplish.