offbyone
Contributor
Contributor

Conditional filter values

I have a metric template where part of it depends on one of the options in the server. Specifically, if an option is non-blank I want to add " WHERE column=${option}" to the SQL query specified in my template.

Is there any way to do that?
0 Kudos
1 Reply
dougm_hyperic
VMware Employee
VMware Employee

Afraid this isn't possible in the xml file, you'd need some code. Closest in this case I suppose would be:

<config>
<option name="column_name" description="Column name" default="" optional="true"/>
</config>

template=WHERE column like '%%column_name%%'

If the config option is empty, that'd turn into:
WHERE column like '%%' (which would match all)
otherwise:
WHERE column like '%the_option_value%' (which may match too much)

Might be other sql tricks you could pull?
We can help with the code if you're interested in that route. With 4.0 this could actually be done w/ a snippet of groovy code embedded in the .xml file.
0 Kudos