Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- The below segment is in your view. It includes the TimeRangePicker, a blanket search (the purpose of this search is to terminate quickly,
- and allow us to get absolute time when the actual search might include relative times), the CustomBehavior module, and finally an HTML module to
- brag about your success. -->
- <module name="TimeRangePicker">
- <param name="default">Last 30 days</param>
- <param name="searchWhenChanged">True</param>
- <module name="Search" autoRun="True">
- <param name="search">* | head 1</param>
- <module name="CustomBehavior">
- <param name="customBehavior">GatherBins</param>
- <param name="requiresDispatch">True</param>
- <module name="HTML" layoutPanel="panel_row1_col1"><param name="html"><![CDATA[<br /><p>Looking at $Bins$ bins of $Binsize$ each.</p>]]></param></module>
- // The below belongs in your application.js (commenting inline)
- //Assign CustomBehavior triggers
- if(typeof(Sideview)!="undefined"){
- $(document).bind("allModulesInHierarchy",function(){
- Sideview.utils.forEachModuleWithCustomBehavior("GatherBins",function(b,a){
- //isReadyForContextPush -- don't push to the next modules, since the bins aren't assigned yet.
- a.isReadyForContextPush = function(){
- if(!this.RetrievedBinCount) return Splunk.Module.DEFER;
- if (this.getLoadState() < Splunk.util.moduleLoadStates.HAS_CONTEXT) return false;
- return true
- }
- //onJobProgress -- Actually figure out the number of bins.
- a.onJobProgress = function() {
- var c=this.getContext();
- //This will be the upstream * | head 1 search job, which will give us absolute values for the TimeRangePicker
- var d=c.get("search").job;
- var Bins = 0;
- var Binsize = "";
- var latest = new Date(d._latestTime);
- var earliest = new Date(d._earliestTime);
- //Handle latestTime = 0 (Not sure how often this should happen -- came up when I was testing)
- if(latest.valueOf() == 0){
- latest = new Date();
- }
- //Calculate difference in seconds
- var Difference = (latest.valueOf() - earliest.valueOf()) / 1000;
- //Figure out how many bins to assign, based on the range. The below is for 10 minute data increments.
- //If you had only hourly data, and were searching over 10 years, you might need to add an additional layer of summary.
- if(Difference > (730*24*60*60)){
- //alert("More than 730 days -- summarize four days");
- Bins = parseInt(Difference / (96*60*60))+2;
- Binsize = "Four Day";
- }else if(Difference > (450*24*60*60)){
- //alert("More than 450 days -- summarize two days");
- Bins = parseInt(Difference / (48*60*60))+2;
- Binsize = "Two Day";
- }else if(Difference > (150*24*60*60)){
- //alert("More than 150 days -- summarize daily");
- Bins = parseInt(Difference / (24*60*60))+2;
- Binsize = "One Day";
- }else if(Difference > (100*24*60*60)){
- //alert("More than 100 days -- summarize 12 hourly");
- Bins = parseInt(Difference / (12*60*60))+2;
- Binsize = "12 Hour";
- }else if(Difference > (50*24*60*60)){
- //alert("More than 50 days -- summarize 8 hourly");
- Bins = parseInt(Difference / (8*60*60))+2;
- Binsize = "8 Hour";
- }else if(Difference > (14*24*60*60)){
- //alert("More than 14 days -- summarize 4 hourly");
- Bins = parseInt(Difference / (4*60*60))+2;
- Binsize = "4 Hour";
- }else if(Difference > (6*24*60*60)){
- //alert("More than 6 days -- summarize hourly");
- Bins = parseInt(Difference / (60*60))+2;
- Binsize = "One Hour";
- }else if(Difference > (2*24*60*60)){
- //alert("More than 2 days -- summarize half-hourly");
- Bins = parseInt(Difference / (30*60))+2;
- Binsize = "30 Minute";
- }else{
- //alert("Less than 2 days -- summarize to 10 minutes");
- Bins = parseInt(Difference / (10*60))+2;
- Binsize = "10 Minute";
- }
- // Assign to context
- this.Bins = Bins;
- this.Binsize = Binsize;
- this.RetrievedBinCount = true;
- //Now that we have everything we need, we're ready to roll on to the next modules.
- this.pushContextToChildren();
- }
- //getModifiedContent -- put the Bins into $Bins$
- a.getModifiedContext=function(){
- var context=this.getContext();
- context.set("Bins", this.Bins);
- context.set("Binsize", this.Binsize);
- return context
- }
- })
- })
- }
- <!--- You can then do charts such as: -->
- <module name="Search" layoutPanel="panel_row1_col1">
- <param name="search"> * | timechart bins=$Bins$ count</param>
- <module name="HTML"><param name="html"><![CDATA[<h2>Count</h2>]]></param></module>
- <module name="ViewstateAdapter">
- <module name="HiddenFieldPicker">
- <param name="strictMode">True</param>
- <module name="JobProgressIndicator">
- <module name="EnablePreview">
- <param name="enable">True</param>
- <param name="display">False</param>
- <module name="HiddenChartFormatter">
- <param name="charting.chart">area</param>
- <param name="charting.secondaryAxisTitle.text">Count</param>
- <param name="charting.legend.placement">none</param>
- <param name="charting.primaryAxisTitle.text">Time (in $Binsize$ increments)</param>
- <module name="FlashChart">
- <param name="width">100%</param>
- <param name="height">275px</param>
- </module>
- <module name="ViewRedirectorLink">
- <param name="viewTarget">flashtimeline</param>
- </module>
- </module>
- </module>
- </module>
- </module>
- </module>
- </module>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement