Dashboards & Visualizations

Stats Not Passing All Fields to Underscore Data Template in Web Framework

chrisdopuch
Path Finder

Hello,

What I am trying to do is create a customized HTML dashboard that renders a box with some statistics in it for each result returned from a search. I am using the Data Template as documented here: http://docs.splunk.com/DocumentationStatic/WebFramework/1.0/compref_data.html (it is better documented in the web framework app, but I don't know where to find an online version of that to link https://apps.splunk.com/app/1613/).

So far it works decently well, I can get the template to print out the categoryID and count, but the other fields generated by stats (like avg(price)) are not being passed. I am working with the demo data that the Splunk tutorials give you. Whenever I do a JSON.stringify on the line var, it only has the fields categoryId and count.

UPDATE: I have tried a few more stats functions like distinct_count and also a rangemap. It passes the rangemap value perfectly as line.range, and it also passes a line.distinct_count(price) but it is always a zero, even though the actual search has actual results. Something very strange is going on here.

Here is my code:

tag openings removed to make them display properly
...

{% block content %}
script type="text/x-underscore-tmpl" id="top-artist-search-template" style="display:none">
div id="box-wrapper">
<% for(var i=0, l=results.length; i < l; i++) { var line=results[i];%>
div class="box" >
h2 class="profile" > <%= line.categoryId %>
div><%= line.count %>
div><%= line.avg_price %>
div><%= line.perc95_price %>
/div>
<% } %>
/div>
/script>

{% dataview 
    id="table-top-artist-searches"
    managerid="search-top-artist-searches"
    templateName="top-artist-search-template"
%}

{% endblock content %}

{% block managers %}

{% searchmanager id="search-top-artist-searches"
search='sourcetype=access_* status=200 action=purchase | stats count, avg(price) as avg_price, perc95(price) AS perc95_price by categoryId | sort avg(time) desc'
cache=True
%}

{% endblock managers %}

0 Karma
1 Solution

chrisdopuch
Path Finder

Ok, I figured out what was going wrong. I migrated this code from the server side (Django) over to the client side (just JS) and examined the GET and POST messages. Something was going wrong with either the transmission of the search, or the transmission of the search results. Instead I used a saved search (instead of one embedded in the page's source) and then it worked!

View solution in original post

0 Karma

chrisdopuch
Path Finder

Ok, I figured out what was going wrong. I migrated this code from the server side (Django) over to the client side (just JS) and examined the GET and POST messages. Something was going wrong with either the transmission of the search, or the transmission of the search results. Instead I used a saved search (instead of one embedded in the page's source) and then it worked!

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 ...