Skip to content

Instantly share code, notes, and snippets.

@Jaykul
Created November 13, 2014 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jaykul/2b7bb40d9df69414ada0 to your computer and use it in GitHub Desktop.
Save Jaykul/2b7bb40d9df69414ada0 to your computer and use it in GitHub Desktop.
Simple Simple Tricks
require.config({
paths: {
"app": "../app"
}
});
require(['splunkjs/mvc/simplexml/ready!'], function(){
require(['splunkjs/ready!'], function(){
// The splunkjs/ready loader script will automatically instantiate all elements
// declared in the dashboard's HTML.
});
});
require(['jquery','underscore','splunkjs/mvc','util/console','splunkjs/mvc/simplexml/ready!'], function($, _, mvc, console){
// Get a reference to the dashboard panels
var masterView = mvc.Components.get('master');
var detailViewBTS = mvc.Components.get('detailBTS');
var detailViewTRX = mvc.Components.get('detailTRX');
var unsubmittedTokens = mvc.Components.get('default');
var submittedTokens = mvc.Components.get('submitted');
var urlTokens = mvc.Components.get('url');
if(!submittedTokens.has('BTS')) {
// if there's no value for the $picker$ token yet, hide the dashboard panel of the detail view
detailViewBTS.$el.parents('.dashboard-panel').hide();
}
submittedTokens.on('change:BTS', function(){
// When the token changes...
if(!submittedTokens.get('BTS')) {
// ... hide the panel if the token is not defined
detailViewBTS.$el.parents('.dashboard-panel').hide();
} else {
// ... show the panel if the token has a value
detailViewBTS.$el.parents('.dashboard-panel').show();
}
});
if(!submittedTokens.has('TRX')) {
// if there's no value for the $picker$ token yet, hide the dashboard panel of the detail view
detailViewTRX.$el.parents('.dashboard-panel').hide();
}
submittedTokens.on('change:TRX', function(){
// When the token changes...
if(!submittedTokens.get('TRX')) {
// ... hide the panel if the token is not defined
detailViewTRX.$el.parents('.dashboard-panel').hide();
} else {
// ... show the panel if the token has a value
detailViewTRX.$el.parents('.dashboard-panel').show();
}
});
masterView.on('click', function(e) {
// Submit the value for the picker field
unsubmittedTokens.set('form.BTS', e.BTS);
unsubmittedTokens.set('form.TRX', e.TRX);
submittedTokens.set(unsubmittedTokens.toJSON());
urlTokens.saveOnlyWithPrefix('form\\.', unsubmittedTokens.toJSON(), {
replaceState: false
});
});
});
<form stylesheet="drilldown_form.css" script="drilldown_form.js,autodiscover.js">
<label>Parent-Child</label>
<description>visualization of parent-child relationships</description>
<fieldset submitButton="false">
<!-- This just exists to store the current state/drilldown -->
<input type="text" token="BTS" searchWhenChanged="true" />
<input type="text" token="TRX" searchWhenChanged="true" />
</fieldset>
<row>
<table>
<title>data</title>
<searchString>index="tmforum" | table TRX, TRXCount, BTS, BTSCount</searchString>
<earliestTime>0</earliestTime>
</table>
</row>
<row>
<html id="master">
<h2>Error Sources</h2>
<div id="hierarchy"
class="splunk-manager"
data-require="splunkjs/mvc/searchmanager"
data-options='{
"search": "index=tmforum | stats max(TRXCount) as TRXCount by TRX, BTS, BTSCount",
"earliest_time": "-7d",
"status_buckets": 0,
"cancelOnUnload": true,
"auto_cancel": 90,
"preview": true
}'>
</div>
<div id="hierarchyView"
class="splunk-view"
data-require="app/BDViz/components/hierarchy/hierarchy"
data-options='{
"managerid": "hierarchy",
"nameField": "TRX",
"parentField": "BTS",
"valueField": "TRXCount",
"parentValueField": "BTSCount",
"height": 450
}'>
</div>
</html>
</row>
<row>
<table id="detailBTS">
<title>Detail: $BTS$</title>
<searchTemplate>index=tmforum BTS=$BTS$ | timechart count</searchTemplate>
<!-- <earliestTime>-24h</earliestTime> -->
<!-- <latestTime>now</latestTime> -->
</table>
<table id="detailTRX">
<title>Detail: $TRX$</title>
<searchTemplate>index=tmforum TRX=$TRX$ | timechart count</searchTemplate>
<!-- <earliestTime>-24h</earliestTime> -->
<!-- <latestTime>now</latestTime> -->
</table>
</row>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment