I have a simple table where one column contains a URL. I would like to redirect to that url and if possible in a new window.
like so:
$row.link$
it redirects to the current URL plus $row.link$ 😞
I suspect, that Splunk checks if the link tag starts with http*
this worked for me. no JS required.
<condition field="URL">
<link target="_blank">$click.value2|n$</link>
</condition>
How to achieve this if I want to navigate to a folder path
Consider the result of splunk query
Name| path
Path1 | \abc\p1
Path2 | \abc\p2
I want to click and navigate to the paths .
For weburls i can achieve using $click.value2|n$
But in the case of folders and shared paths how to achieve this???
I found the pipe n needed for it to work for me:
this worked for me. no JS required.
<condition field="URL">
<link target="_blank">$click.value2|n$</link>
</condition>
I managed to get it work. Both are not the best way, but it works for me.
1
Convert it yo HTML
Change the below line:-
// var url = TokenUtils.replaceTokenNames("{{SPLUNKWEB_URL_PREFIX}}/app/lionel/$click.value2$", _.extend(submittedTokenModel.toJSON(), e.data), TokenUtils.getEscaper('url'));
var url = TokenUtils.replaceTokenNames("$click.value2$", _.extend(submittedTokenModel.toJSON(), e.data));
2
Write a javascript that will accept the full url as a get data, which will redirect to the url.
Here is the redirect javascript:- (eg:- http://mydomain/redirect.html)
<script>
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
window.location = getParameterByName("goto");
</script>
so now, from the simpleXML of the dashboard, it should look like this:-
<drilldown target="_blank">
<link>http://mydomain/redirect.html?goto=$click.value2$</link>
</drilldown>
This behavior is due to purposeful url escaping in the dynamic drilldown feature.
There is an example of using an external link in the Splunk 6.x Dashboard Examples app version 2.0.1 (NB: The external link example is not available in version 1.0 of that app). The page named "Drilldown URL Field Value" provides an example of how to render an external link in a separate clickable column. Below, I'll paste a generic example, using that example's JS as a base, but updating it to make the original column a clickable link to an external page.
In the simple XML, we reference a JavaScript file named drilldown_external_url.js
(which should be in the app's appserver/static directory), we add an ID to the table (external_link
), and we disable drilldown. Here's the simple XML:
<dashboard script="drilldown_external_url.js">
<row>
<table id="external_link">
<searchString>| stats count | eval target="http://splunk.com"</searchString>
<earliestTime>$earliest$</earliestTime>
<latestTime>$latest$</latestTime>
<option name="wrap">true</option>
<option name="rowNumbers">false</option>
<option name="dataOverlayMode">none</option>
<option name="drilldown">none</option>
<option name="count">10</option>
</table>
</row>
</dashboard>
We update the JavaScript to reference the table ID (external_link
) and the field name's column (target
). If the table name or field name is different in your simple XML, be sure to update the JS accordingly. Here is the drilldown_external_url.js
require([
'underscore',
'jquery',
'splunkjs/mvc',
'splunkjs/mvc/tableview',
'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc, TableView) {
var CustomLinkRenderer = TableView.BaseCellRenderer.extend({
canRender: function(cell) {
return cell.field === 'target';
},
render: function($td, cell) {
var link = cell.value;
var a = $('<a>').attr("href", cell.value).text(cell.value);
$td.addClass('table-link').empty().append(a);
a.click(function(e) {
e.preventDefault();
window.location = $(e.currentTarget).attr('href');
// or for popup:
// window.open($(e.currentTarget).attr('href'));
});
}
});
// Get the table view by id
mvc.Components.get('external_link').getVisualization(function(tableView){
// Register custom cell renderer
tableView.table.addCellRenderer(new CustomLinkRenderer());
// Force the table to re-render
tableView.table.render();
});
});
Great answer - works like a charm.
@jhupka, you should click Accept
to award him karma.
I am seeing this exact same issue. I am surprised it hasnt been fixed almost a year on.
My row is like this but it still leaves everything encoded
<row>
<panel>
<table>
<title>Asset threats over last 60 days</title>
<searchString>index=cve-details vendor_id=$vendor_id$ | join vendor_id [ | inputlookup asset-list.csv ] | eval url=urldecode(url) | sort update_date desc | table asset_code, asset_name, vendor_name, cve_id, cwe_name, publish_date, update_date, summary, url</searchString>
<earliestTime>-60d</earliestTime>
<latestTime>now</latestTime>
<option name="wrap">true</option>
<option name="rowNumbers">false</option>
<option name="dataOverlayMode">none</option>
<option name="drilldown">cell</option>
<option name="count">10</option>
<drilldown>
<link><![CDATA[ $row.url$ ]]></link>
</drilldown>
</table>
</panel>
</row>
My link ends up looking like this. (not it is still encoded for URLs which is should not be)
So for a row with
url = http://www.cvedetails.com/cve/cve-2013-1763//
The drilldown link is
http://my.splunk.server.com.au:8000/en-US/app/cvedetails/http%3A%2F%2Fwww.cvedetails.com%2Fcve%2FCVE...
Is there anyway to get the raw text of the field to be the link?