I am using a template variable that resolves correctly in the Item field but when I try to use it in setAlias() it does not resolve. It does get coloured light blue in the editor as a known variable but does not get replaced in the Legend.
Yes, I need to implement it.
Imported from #217.
I am in the process of migrating a Grafana 2.6 dashboard using grafana-zabbix to 3.x and am noticing a loss of flexibility in the handling of query aliases which is useful in particular when it comes to Zabbix items that have very long names and using template variables to select Zabbix hosts.
While when using a template variable and a query alias in 2.6 the resulting item name was a concatenation of the $hostname: $itemname and only $itemname was replaced with the query alias, in Grafana 3 and latest grafana-zabbix when using the function setAlias($alias) to set an alias instead, the resulting item name is just $alias.
This makes the feature less useful when used in conjunction with template variables: Previously, you could go and have i.e. a load average graph for 50 hosts with data series labels reading $hostname:$itemname where $itemname was empty because we replaced it by setting an alias. After all, it doesn't make sense to repeat 50 times $hostname: Processor load (5 min average per core) in the graph legend - putting that into the graph title does. Because of the new behaviour of the setAlias() function, in Grafana 3, we can't have just $hostname in the legend anymore when using the same hostname templating technique. This prevents us from using our dashboard screens efficiently, so I'm sticking with 2.6 for the time being.
In order to be able to do the same in Grafana 3 with grafana-zabbix, please expand template variables used as the function argument to setAlias(). As of this moment, the variables are not expanded but printed literally to the UI.
Template variable would be useful in other functions asides from the setAlias as well. For example using an interval template with groupBy would allow me to smooth the graphs on larger time periods.
Yes, it would be useful.
@alexanderzobnin Thank you very much for resolving the issue; however even with this the application as described in my previous post can't be implemented correctly.
Supposing I have a line graph that plots a single metric from multiple hosts, and the hosts are automatically selected using a template variable called $HOSTS which contains 1000 hosts. This works well as for every single one of the 1000 hosts, I get a data series plotted in the graph. When I apply setAlias($HOSTS) however, the name of every metric gets set to the name of _all_ 1000 hosts and not just the one host from which the metric originates. Obviously this is not very useful. Because it's impossible to tell which is which.
Is there a already special template variable that allows me to only pass the name of the host from which the given metric originated to setAlias()?
I have found what change I need -- I've applied this to my working copy. It's an ugly workaround that probably breaks stuff elsewhere but for my specific purpose it does the job just fine.
In https://github.com/alexanderzobnin/grafana-zabbix/blob/develop/src/datasource-zabbix/queryProcessor.service.js#L240 as of 2882a48, change
alias = host.name + ": " + alias;
to
alias = host.name;
and I get what I've been looking for, without having to resort to setAlias():

Metric name is yanked from the series, leaving only the host name, hosts are selected using a template variable from a single group.
@2ion I think you need a special macros for hostname and intemname supported by setAlias() function. Like {HOST.NAME} and {ITEM.NAME} in Zabbix.
so, to be sure how to use this functionality? i tried to read code and understand, but no luck for me.
@Atoms what do you mean? This commit allows you to use grafana variables as function parameter, for example: aggregateBy($agg_interval, avg) where $agg_interval is template variable.
What i wanted was setAlias to get only hostname without item name
@Atoms I think you should open issue for this feature - it's interesting, but not the same as templating feature.
I just tested it and setAlias does resolve template variables now. The issue is that a template variable that contains more than one value resolves all of its values into every metric of a graph.
For example:
A template variable $nodes with the values host1, host2 and host3.
Select the special "All" option.
Set Host = /$nodes/
Functions = setAlias($nodes)
The result is that any Items that are graphed have the alias = {host1,host2,host3}
It would be great if there was a way to have the Functions resolve multi value variables to the value that is used by that particular item.
The other option would be to be to directly reference the Group/Host/Application/Item name in setAlias.
Most helpful comment
I just tested it and setAlias does resolve template variables now. The issue is that a template variable that contains more than one value resolves all of its values into every metric of a graph.
For example:
A template variable $nodes with the values host1, host2 and host3.
Select the special "All" option.
Set Host = /$nodes/
Functions = setAlias($nodes)
The result is that any Items that are graphed have the alias = {host1,host2,host3}
It would be great if there was a way to have the Functions resolve multi value variables to the value that is used by that particular item.
The other option would be to be to directly reference the Group/Host/Application/Item name in setAlias.