Dynamic external hyperlink on scripted field

Hi,

I'm using 7.5.1 ELK stack and trying to build a dashboard for our CI pipelines. I'm focusing on visualizing SonarQube quality gate data, especially highlighting error counter when code issues are detected.

I'm using a painless scripted field in Kibana to do a basic sum over json fields to detect failures:

...
for (int i = 0; i < params['_source']['component']['measures'][0]['value']['conditions'].length ; i++)   {
   gateFailedCount += params['_source']['component']['measures'][0]['value']['conditions'][i]['failure'];
...
}

This is working as expected and I can build Metric visualization based on this scripted field.

Now I would like to make this metric (e.g. 2 gate_failures) clickable so that users can go to the matching SonarQube url.

The url itself is buildable from the Json payload (http://sonarqubehost/dashboard?id=" + params['_source']['component']['key']).

When I'm using this url to build the return value of the scripted field like this

...
return "<a href='http://sonarqubehost/dashboard?id=" + params['_source']['component']['key'] + "'>" + gateFailedCount + "</a>";

the Metric visualisation get messed up: the whole <a href ...> string is used as display text without any hyperlink. Looking at the DOM, the < and > symbol have been transformed into a &lt; and &gt; which explain the issue.

I also tried to declare the scripted field as a url format but could not make this work.

Is there a way to make this work?

Thanks
Fabrice

If you return only the URL portion, without the HTML, using the URL field formatter should then turn that into a clickable link

Hi,
Thanks for the quick response.

If I return only the URL I indeed get a clickable link but I loose the gateFailedCount information.
I would to combine both: displaying the count as the anchor and the hyperlink to the sonarqube server. Something equivalent to <a href="http://...>2</a>

Cheers.

Oh, sorry, didn't catch that when I first looked.

Unfortunately that's not possible today with a scripted field. You could probably get something like that with a custom field formatter which you can load through a custom plugin or you'll have to split the field into two (the label, and the link).

There are a few related open issues in the Kibana repo that have a similar ask so it's definitely on the team's radar as something people want.

There are a few related open issues in the Kibana repo that have a similar ask so it's definitely on the team's radar as something people want

Yes, it would be very useful to build interactive dashboards

you'll have to split the field into two (the label, and the link)

You mean via 2 visualizations (1 Metric and 1 Markdown for instance)? I don't think the Metric viz allows this kind of split, right?

Not sure what kind of visualizations you're going for but in my mind it was two columns of a table

Thanks for your time and advice Michail.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.