Dashboards & Visualizations

How to set tokens with single searches in django?

lquinn
Contributor

I am writing my first django app and I am having some trouble with tokens. The following is my dashboard (I used the splunk django template) ...

{% extends "splunkdj:base_with_app_bar.html" %}

{% load splunkmvc %}

{% block title %}{{app_name}} Your page title goes here{% endblock title %}

{% block css %}
    <!-- Style sheets are loaded here -->
    <link rel="stylesheet" type="text/css" href="{{STATIC_URL}}{{app_name}}/custom.css" />
    <link rel="stylesheet" type="text/css" href="{{STATIC_URL}}splunkjs/css/dashboard.css" />
    <style>
    </style>
{% endblock css %}

{% block content %} 

{% dropdown id="drop1" managerid="search1" labelField="label" valueField="label" value="$label$"|token_safe showClearButton=False %}
{% single id="single1" managerid="search2" labelField="ip" valueField="ip" value="$ip$"|token_safe %}
{% single id="single2" managerid="search3" labelField="device" valueField="device" value="$device$"|token_safe %}

{% endblock content%}


{% block managers %}
    {% searchmanager
        id="search1"
        search="|inputlookup lookupTable.csv | fields label | dedup label"
        cache=False
    %}
    {% searchmanager
        id="search2"
        search='| inputlookup lookupTable.csv | search label="$label$" | fields ip'|token_safe
        cache=False
    %}
    {% searchmanager
        id="search3"
        search='| inputlookup lookupTable.csv | search ip="$ip$" | fields device'|token_safe
        cache=False
    %}
{% endblock managers %}

{% block js %}

{% endblock js %}

where lookupTable.csv has headings label, ip and device.

When I make a selection from the drop down list, the token $label$ is successfully assigned and the single view search with id=single1 is populated. However, the second token, $ip$ is not assigned and the second single view search is still waiting for an input. Can anyone see what I'm doing wrong here? Thanks!

Tags (2)
0 Karma

gyslainlatsa
Motivator

HI Iquinn,
we must add another dropdown to select the ip token that will allow you to display a value of the device field
the first panel is displayed when you select dropdown because he depends on the value of the dropdown, which is the token label
we must create a second dropdown that will allow you to select the input of the token ip to display its result

So add the following code in the content block
{% block content %}
{% dropdown id="drop2" managerid="search4" labelField="ip" valueField="ip" value="$ip$"|token_safe showClearButton=False %}
{% endblock content%}

Then add this code in the block managers

{% block managers %}
    {% searchmanager
    id="search4"
    search="|inputlookup lookupTable.csv | fields ip | dedup ip"
    cache=False
    %}
{% endblock managers %} 

and then you will get the expected results

0 Karma

lquinn
Contributor

I have since realised that you cannot assign tokens straight from searches. I found this splunk answer ....

http://answers.splunk.com/answers/118584/web-framework-searchmanager-to-token.html

... however after trying to adapt the javascript in this answer I still cant get it to work. Any input would be much appreciated!

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...