Let's have a go at making some changes to our dashboard to show that it is straightforward; and all you need to do is just think about the setup of the code a little differently from what you did when it was set up in Simple XML. In this part of the chapter, we are going to change our chart to provide two separate line graphs for each for the companies that we are providing closing values for. This will mean that we will need to make changes to the HTML section, add another search manager for another search query, and then code a second visualization for the second line graph:
cd $SPLUNK_HOME/etc/apps/stock_market/local/data/ui/html/
stock_market_historical_overview_html.html
file.39 <h3>Historical Overview of Splunk Closing Value</h3>
div
container for element1
. We are going to add the following lines to the code so that it will display a second graph:47 <div id="row2" class="dashboard-row dashboard-row2"> 48 <div id="panel1" class="dashboard-cell" style="width:100%;"> 49 <div class="dashboard-panel clearfix">
div
with row2
as the ID for our second row, and we also name our second class dashboard-row2
. We then set up the panel for the chart.panel-element
; name it element2
and provide it with its own heading to reflect the data it is going to display:51 <div class="panel-element-row"> 52 <div id="element2" class="dashboard- element chart" style="width: 100%"> 53 <div class="panel-head"> 54 <h3>Historical Overview of Yahoo Closing Value</h3> 55 </div> 56 <div class="panel-body"></div>
div
containers for this part of the HTML code:57 </div> 58 </div> 59 </div> 60 </div> 61 </div>
214 "search": "source="*splkstock.csv" | chart values(Close) AS Splunk by Date",
search1
. With the additions that we have made so far, this should be at about line 223:223 var search2 = new SearchManager({ 224 "id": "search2", 225 "status_buckets": 0, 226 "earliest_time": "-1y@y", 227 "search": "source="*yhoostock.csv" | chart values(Close) AS Yahoo by Date", 228 "latest_time": "$latest$", 229 "cancelOnUnload": true, 230 "app": utils.getCurrentApp(), 231 "auto_cancel": 90, 232 "preview": true, 233 "runWhenTimeIsUndefined": false 234 }, {tokens: true, tokenNamespace: "submitted"});
search2
, and our search will point to the Yahoo! stock market data. Each of the other options, including earliest and latest times, will be the same as search1
.element1
already in place. If you remember, we have now entered a second element to be referenced within the HTML part of our code. As it will be very similar to element1
, move just below this code and add the following code lines from line 281:281 var element2 = new ChartElement({ 282 "id": "element2", 283 "charting.chart": "bar", 284 "resizable": true, 285 "managerid": "search2", 286 "el": $('#element2') 287 }, {tokens: true, tokenNamespace: " submitted"}).render();
element2
, which simply references the new search manager we have now set up, called search2
. cd $SPLUNK_HOME/etc/apps/stock_market/default/data/ui/nav/
default.xml
file, and we will add an entry that will place the new dashboard on our interface and load it up when it is clicked. The following is the entire code for the default.xml
, so you can see the difference between displaying Simple XML and HTML dashboards in our menu:1 <nav search_view="search" color="#65A637"> 2 <view name="overview" default='true' /> 3 <a href="stock_market_historical_overview_html">Stock Market Historical Overview HTML</a> 4 <view name="search" /> 5 </nav>
view
element, but as you can see, we now use the anchor element with an href
attribute to add our new HTML dashboard. We also need to specify the name that is going to be displayed in between the tag
elements. If we do not specify the name to be displayed, it will display the filename and not the title as it did with our Simple XML dashboards.
We now have our separate line charts displayed on the one dashboard and we have also been able to add a new item to the menu at the top of the screen.
So there seems to be a lot of code in the HTML section of our dashboard, but a lot of this code has been set up to improve the visual appeal of the information we are presenting to our users. The main reason why all of these visual elements are in place in our HTML is basically so that we can change and manipulate every tiny detail of the way our dashboard is displayed to our users. We are going to take this opportunity to quickly create a new dashboard that will remove all of the unnecessary code and only include the basic HTML code that we need to have our chart displayed on the page. Our new dashboard will be a copy of our original HTML dashboard so that we can compare the two:
cd $SPLUNK_HOME/etc/apps/stock_market/local/data/ui/html/
cp stock_market_historical_overview_html.html raw_stock_market_historical_overview_html.html
18 <p id="element1" />
nav
directory for our Splunk App: cd $SPLUNK_HOME/etc/apps/stock_market/default/data/ui/nav/
default.xml
file with your text editor and add the following line after the previous HTML dashboard that we added:4 <a href="raw_stock_market_historical_overview_html">Only A Graph Will be Displayed</a>
It may be rare that you actually want to display a dashboard in the way that we have done in the previous example. In my opinion, the exercise gives a really good example of where Splunk has such a great amount of power, and one of its major benefits lies in the way it is able to display data to your user.
In the following exercise, we are going to make a template from the Splunk App that we have just created. For me personally, I prefer to have all of my Splunk App code and configurations in the default directory of my Splunk App. I recommend that you copy the most recent HTML dashboards that we have created into a new html
directory within the default directory of our Splunk App.
18.227.0.192