All Apps and Add-ons

Static redirects per table row sideview utils

jfraiberg
Communicator

I am using sideview utils and I have a table that I want to tie static redirects to. For instance, if you click on the first row in the table it sends you to some HTTP URL, if you click on the 2nd row in the table it sends you to a view, etc, etc...

currently im using a SimpleResultsTable that pushes to a Redirector. I was able to hack that together by creating html files that redirect you to a static link like so: http://10.1.1.1/$click.fields.series$.html. those html files would then just redirect to the static page of my choice.

Any ideas on how to achieve this natively without me having to call external html files to redirect?

here is the relevant piece of code I was using -

<module name="URLLoader" layoutPanel="panel_row1_col1">
<module name="Search" autoRun="True">
<param name="earliest">-4h</param>
<param name="search"><![CDATA[
index=_internal source="*metrics.log" group="per_sourcetype_thruput" | stats avg(eps) by series| eval actions="PLACEHOLDER" | sort - avg(eps)
]]></param>
<module name="JobProgressIndicator" />
<module name="SimpleResultsTable">
<param name="count">4</param>
<param name="fields">series</param>
<param name="drilldown">row</param>
<param name="allowTransformedFieldSelect">True</param>
<module name="Redirector">
<param name="popup">True</param>
<param name="url">http://10.1.1.1/$click.fields.series$.html</param>
</module>
</module>
</module>
</module>

1 Solution

sideview
SplunkTrust
SplunkTrust

Alright. Thanks for the additional detail.

1) If there's only two classes of rows - one where you want to go to a single view, and a second where you want to go to an external URL, I would look into using the ValueSetter module to create the url conditionally.

here's an example:

  <module name="ValueSetter">
    <param name="name">fancyUrl</param>
    <param name="if.$click.fields.series$=splunkd">viewName?foo=$bar$</param>
    <param name="default">http://10.1.1.1/$click.fields.series$.html</param>

    <module name="Redirector">
      <param name="popup">True</param>
      <param name="url">$fancyUrl$</param>
    </module>
  </module>

Note the ?foo=$bar$ is intended to show that you can put other $foo$ tokens in there. If you do put querystring vars in there, unless you know that they're only ever alphanumeric characters, you may need to use ValueSetter's urlEncodeKeys param. (Normally you wouldn't have to worry about url encoding, because you would normally use the <param name="arg.foo">$bar$</param> on Redirector, and it would handle it all. Since here you're making the whole URL using ValueSetter, you have to worry about url encoding. )

Check out the ValueSetter documentation and examples page in Sideview Utils. And if you want a deeper set of examples you can look around in the views directory in Sideview Utils and crack open the various hidden testcase views for ValueSetter. There is one specifically for its conditional features, and that will give you a slightly broader range of working examples to crib from.

2) If your requirements get any more complicated you may want to define a customBehavior on Redirector and override the getURL method. If that sentence made no sense to you, pretend I didn't say anything at all.

View solution in original post

0 Karma

sideview
SplunkTrust
SplunkTrust

Alright. Thanks for the additional detail.

1) If there's only two classes of rows - one where you want to go to a single view, and a second where you want to go to an external URL, I would look into using the ValueSetter module to create the url conditionally.

here's an example:

  <module name="ValueSetter">
    <param name="name">fancyUrl</param>
    <param name="if.$click.fields.series$=splunkd">viewName?foo=$bar$</param>
    <param name="default">http://10.1.1.1/$click.fields.series$.html</param>

    <module name="Redirector">
      <param name="popup">True</param>
      <param name="url">$fancyUrl$</param>
    </module>
  </module>

Note the ?foo=$bar$ is intended to show that you can put other $foo$ tokens in there. If you do put querystring vars in there, unless you know that they're only ever alphanumeric characters, you may need to use ValueSetter's urlEncodeKeys param. (Normally you wouldn't have to worry about url encoding, because you would normally use the <param name="arg.foo">$bar$</param> on Redirector, and it would handle it all. Since here you're making the whole URL using ValueSetter, you have to worry about url encoding. )

Check out the ValueSetter documentation and examples page in Sideview Utils. And if you want a deeper set of examples you can look around in the views directory in Sideview Utils and crack open the various hidden testcase views for ValueSetter. There is one specifically for its conditional features, and that will give you a slightly broader range of working examples to crib from.

2) If your requirements get any more complicated you may want to define a customBehavior on Redirector and override the getURL method. If that sentence made no sense to you, pretend I didn't say anything at all.

0 Karma

jfraiberg
Communicator

That all made sense and it is exactly the answer I was looking for! Thank you very much for the help and the awesome app!

0 Karma

jfraiberg
Communicator

Some go to views, and some go to an external URL. The table in the end will be a merging of 2 tables, some of the rows will redirect to a Splunk view, and other ones may redirect to a 3rd party dashboard. It is a table that will reside on the first page of a dashboard and the rows will change colors depending on availability/response, etc. but the data comes from Splunk AND non Splunk sources such as custom monitoring application logs. It is possible that I am making things more complicated doing it this way (using a dynamic table as a referrer) but its what came to my head at the time.

0 Karma

sideview
SplunkTrust
SplunkTrust

No, I mean what determines whether a given row should link to a view or should link to an external URL? Spell out how that all works and what fields and values are involved and I can give you a nice clear answer.

0 Karma

jfraiberg
Communicator

Thanks for the interest! I have updated my original question with the relevant code I used.

0 Karma

jhowkins
Path Finder

Without knowing where you want to get your static list of redirects, I have worked out the following solution:

  1. Start by creating a lookup file. For this example, we'll call it "url_loader_config.csv"
  2. Add the following header row to the lookup file:

    ID,URL

  3. Add rows for as many static URLs you want based on a matching field: Your_ID_Field

Example:

ID,URL
123,http_COLON_//www_DOT_splunk_DOT_com
456,your_dashboard_name
789,http_COLON_//www_DOT_your-static-url_DOT_com

Note: Your_ID_Field will serve as a value to match against the lookup table.

3.) Enter your search that produces the table (replace #your-table-producing-search-here#) and change $click.fields.Your_ID_Field$ to whatever field (I'm guessing $click.fields.series$ maybe?):

<module name="Search" autoRun="true">
    <param name="search">#your-table-producing-search-here#</param>
    <module name="SimpleResultsTable">
        <param name="drilldown">row</param>
        <module name="Search">
            <param name="search">|inputlookup url_loader_config.csv | table ID,URL | where ID="$click.fields.Your_ID_Field$"</param>
            <module name="ResultsValueSetter">
                <param name="fields">ID,URL</param>
                <module name="Redirector">
                    <param name="url">$URL$</param>
                </module>
            </module>
        </module>
    </module>
</module>

You may want to modify the |inputlookup search to make sure everything still works if the ID field doesn't match anything in the lookup file:

|inputlookup url_loader_config.csv | table ID,URL | where ID="$click.fields.Your_ID_Field$" | stats count | eval URL = if(count == 0, "http_COLON_//www_DOT_splunk_DOT_com",URL) | table ID,URL

I can't post external URLs, so I've substituted periods with "DOT" and colons with "COLON". I hope this works for you.

0 Karma

sideview
SplunkTrust
SplunkTrust

How does the determination work from the field values in a given row, to determine which URL or view you need to go to? I assume there's some field value or combination of field values that dictates the correct link (and $foo$ tokens therein) that needs to be used? With more specifics I can give better advice.

0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...