Dashboards & Visualizations

Issue with Setting Default to Latest on Selection Change

juvenile
Loves-to-Learn

The default value of the product selection should be 'latest'. The token for the default value is determined by a hidden search for the latest product. This is dependent on the selected device. If the device selection changes, the product selection should revert to the default value, which is the latest product ID for the newly selected device. Currently, setting the latest product ID upon device change is not functioning. How can I resolve this issue?

 

<search id="base_search">
    <query>
        | mpreview index="my_index"
        | search key IN $token_device$
    </query>
    <earliest>$token_time.earliest$</earliest>
    <latest>$token_time.latest$</latest>
    <refresh>300</refresh>
</search>

<input id="select_device" type="dropdown" token="token_device" searchWhenChanged="true">
    <label>Device</label>

    <selectFirstChoice>true</selectFirstChoice>

    <prefix>(</prefix>
    <suffix>)</suffix>
    <valuePrefix>"</valuePrefix>
    <valueSuffix>"</valueSuffix>

    <search>
        <query>
            | mpreview index="my_index" 
            | stats count by key
            | fields key
            | lookup device-mapping.csv ...
            | fields key full_name
        </query>
    </search>
    <fieldForLabel>full_name</fieldForLabel>
    <fieldForValue>key</fieldForValue>

    <delimiter>,</delimiter>

    <change>
        <unset token="token_product"></unset>
        <unset token="form.token_product"></unset>
    </change>
</input>

<search>
    <query>
        | mpreview index="my_index"
        | search key IN $token_device$
        | stats latest(_time) as latest_time by product_id
        | sort -latest_time 
        | head 1 
        | fields product_id
    </query>
    <earliest>-24h@h</earliest>
    <latest>now</latest>

    <done>
        <condition match="$job.resultCount$ != 0">
            <set token="latest_product_id">$result.product_id$</set>
        </condition>
        <condition match="$job.resultCount$ == 0">
            <set token="latest_product_id">*</set>
        </condition>
    </done>
</search>

<input id="select_product" type="multiselect" token="token_product" searchWhenChanged="true">
    <label>Product</label>

    <default>$latest_product_id$</default>

    <prefix>(</prefix>
    <suffix>)</suffix>
    <valuePrefix>"</valuePrefix>
    <valueSuffix>"</valueSuffix>

    <choice value="*">All</choice>
    <search base="base_search">
        <query>
            | stats latest(_time) as latest_time by product_id
            | eventstats max(latest_time) as max_time 
            | eval label=if(latest_time == max_time, "latest", product_id) 
            | sort - latest_time
            | fields label, product_id
        </query>
    </search>
    <fieldForLabel>label</fieldForLabel>
    <fieldForValue>product_id</fieldForValue>

    <delimiter>,</delimiter>

    <change>
        <condition label="All">
            <set token="token_product">("*") AND product_id != "LoremIpsum"</set>
        </condition>
    </change>
</input>

 

Labels (1)
0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

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