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.
Joe_Tran
Posted 8 years ago·Last reply 8 years ago
2 comments
Joe_Tran
OP8 years agoHi @Brandon,
It actually does! I was not aware of the toProperties() method.
Thank you!
Brandon Woods
·8 years agoHey 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.