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!

Monitoring MariaDB and MySQL

In a previous post, we explored monitoring PostgreSQL and general best practices around which metrics to ...

Financial Services Industry Use Cases, ITSI Best Practices, and More New Articles ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Splunk Federated Analytics for Amazon Security Lake

Thursday, November 21, 2024  |  11AM PT / 2PM ET Register Now Join our session to see the technical ...