Joe Tran

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

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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.

 

  • Upvote 2

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.