<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Splunk Dynamic query in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Splunk-Dynamic-query/m-p/554704#M38552</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am new to splunk.We have recently integrated New relic(monitoring tool) to splunk.we are currently creating splunk dashboard for new relic to monitor the application performance.As a part of this,we have the fields like custom.step1,custom.step1status,custom.step1duration,custom.step2,custom.step2status,custom.step2duration ans so on for n number of steps in a row format.below is the data we see in the events -&lt;/P&gt;&lt;P&gt;events: [ [-]&lt;BR /&gt;{ [+]&lt;BR /&gt;}&lt;BR /&gt;{ [+]&lt;BR /&gt;}&lt;BR /&gt;{ [-]&lt;BR /&gt;custom.JAZZ_INSTANCE: xx-xxx-06-p&lt;BR /&gt;custom.Step1: APP_LandingPage&lt;BR /&gt;custom.Step1Duration: 205&lt;BR /&gt;custom.Step1Status: Pass&lt;BR /&gt;custom.Step2: APP_Login&lt;BR /&gt;custom.Step2Duration: 1430&lt;BR /&gt;custom.Step2Status: Pass&lt;BR /&gt;custom.Step3: APP_Dashboard&lt;BR /&gt;custom.Step3Duration: 6704&lt;BR /&gt;custom.Step3Status: Pass&lt;BR /&gt;custom.Step4: APP_WorkitemQuery&lt;BR /&gt;custom.Step4Duration: 3349&lt;BR /&gt;custom.Step4Status: Pass&lt;BR /&gt;custom.errMsg: null&lt;BR /&gt;custom.errorStep: null&lt;BR /&gt;custom.testCase: null&lt;BR /&gt;custom.testCaseStatus: null&lt;BR /&gt;duration: 15888.00099992752&lt;BR /&gt;error:&lt;BR /&gt;host: null&lt;BR /&gt;locationLabel: china_bcn&lt;BR /&gt;monitorName: APP_CHINA&lt;BR /&gt;result: SUCCESS&lt;BR /&gt;timestamp: 1623073512664&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;So,to calculate the average of duration of all the steps1,2,3,4.we have written the below query.&lt;/P&gt;&lt;P&gt;index="new_relic_test_index"&lt;BR /&gt;| stats avg(results{}.events{}.custom.Step1Duration) as step1duration avg(results{}.events{}.custom.Step2Duration) as step2duration avg(results{}.events{}.custom.Step3Duration) as step3duration avg(results{}.events{}.custom.Step4Duration) as step4duration by results{}.events{}.custom.Step1 results{}.events{}.custom.Step2 results{}.events{}.custom.Step3 results{}.events{}.custom.Step4&lt;BR /&gt;| eval splithere='results{}.events{}.custom.Step1' ."|". step1duration .";" . 'results{}.events{}.custom.Step2' . "|" . step2duration .";" . 'results{}.events{}.custom.Step3' . "|" . step3duration .";" . 'results{}.events{}.custom.Step4' . "|" . step4duration&lt;BR /&gt;| makemv splithere delim=";"&lt;BR /&gt;| mvexpand splithere&lt;BR /&gt;| eval step=mvindex(split(splithere,"|"),0), Average(duration)=mvindex(split(splithere,"|"),1)&lt;BR /&gt;| table step,Average(duration) | dedup step&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Output -&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;step&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; Average(duration)&lt;/STRONG&gt;&lt;BR /&gt;APP_LandingPage&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 205.83333333333334&lt;BR /&gt;APP_Login&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1033.986111111111&lt;BR /&gt;APP_Dashboard&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4040.1388888888887&lt;BR /&gt;APP_WorkitemQuery&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1724.7916666666667&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;But the issue we are facing here is ...we need a dynamic query which will be the same even in case if we have more number of steps and need not edit the query all the time.Also this query is taking long to load.&lt;/P&gt;&lt;P&gt;Please let us know if the dynamic query is possible in this case.&lt;/P&gt;&lt;P&gt;Thanks in Advance!&lt;/P&gt;</description>
    <pubDate>Mon, 07 Jun 2021 14:32:16 GMT</pubDate>
    <dc:creator>vidya321</dc:creator>
    <dc:date>2021-06-07T14:32:16Z</dc:date>
    <item>
      <title>Splunk Dynamic query</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Splunk-Dynamic-query/m-p/554704#M38552</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am new to splunk.We have recently integrated New relic(monitoring tool) to splunk.we are currently creating splunk dashboard for new relic to monitor the application performance.As a part of this,we have the fields like custom.step1,custom.step1status,custom.step1duration,custom.step2,custom.step2status,custom.step2duration ans so on for n number of steps in a row format.below is the data we see in the events -&lt;/P&gt;&lt;P&gt;events: [ [-]&lt;BR /&gt;{ [+]&lt;BR /&gt;}&lt;BR /&gt;{ [+]&lt;BR /&gt;}&lt;BR /&gt;{ [-]&lt;BR /&gt;custom.JAZZ_INSTANCE: xx-xxx-06-p&lt;BR /&gt;custom.Step1: APP_LandingPage&lt;BR /&gt;custom.Step1Duration: 205&lt;BR /&gt;custom.Step1Status: Pass&lt;BR /&gt;custom.Step2: APP_Login&lt;BR /&gt;custom.Step2Duration: 1430&lt;BR /&gt;custom.Step2Status: Pass&lt;BR /&gt;custom.Step3: APP_Dashboard&lt;BR /&gt;custom.Step3Duration: 6704&lt;BR /&gt;custom.Step3Status: Pass&lt;BR /&gt;custom.Step4: APP_WorkitemQuery&lt;BR /&gt;custom.Step4Duration: 3349&lt;BR /&gt;custom.Step4Status: Pass&lt;BR /&gt;custom.errMsg: null&lt;BR /&gt;custom.errorStep: null&lt;BR /&gt;custom.testCase: null&lt;BR /&gt;custom.testCaseStatus: null&lt;BR /&gt;duration: 15888.00099992752&lt;BR /&gt;error:&lt;BR /&gt;host: null&lt;BR /&gt;locationLabel: china_bcn&lt;BR /&gt;monitorName: APP_CHINA&lt;BR /&gt;result: SUCCESS&lt;BR /&gt;timestamp: 1623073512664&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;So,to calculate the average of duration of all the steps1,2,3,4.we have written the below query.&lt;/P&gt;&lt;P&gt;index="new_relic_test_index"&lt;BR /&gt;| stats avg(results{}.events{}.custom.Step1Duration) as step1duration avg(results{}.events{}.custom.Step2Duration) as step2duration avg(results{}.events{}.custom.Step3Duration) as step3duration avg(results{}.events{}.custom.Step4Duration) as step4duration by results{}.events{}.custom.Step1 results{}.events{}.custom.Step2 results{}.events{}.custom.Step3 results{}.events{}.custom.Step4&lt;BR /&gt;| eval splithere='results{}.events{}.custom.Step1' ."|". step1duration .";" . 'results{}.events{}.custom.Step2' . "|" . step2duration .";" . 'results{}.events{}.custom.Step3' . "|" . step3duration .";" . 'results{}.events{}.custom.Step4' . "|" . step4duration&lt;BR /&gt;| makemv splithere delim=";"&lt;BR /&gt;| mvexpand splithere&lt;BR /&gt;| eval step=mvindex(split(splithere,"|"),0), Average(duration)=mvindex(split(splithere,"|"),1)&lt;BR /&gt;| table step,Average(duration) | dedup step&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Output -&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;step&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; Average(duration)&lt;/STRONG&gt;&lt;BR /&gt;APP_LandingPage&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 205.83333333333334&lt;BR /&gt;APP_Login&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1033.986111111111&lt;BR /&gt;APP_Dashboard&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4040.1388888888887&lt;BR /&gt;APP_WorkitemQuery&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1724.7916666666667&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;But the issue we are facing here is ...we need a dynamic query which will be the same even in case if we have more number of steps and need not edit the query all the time.Also this query is taking long to load.&lt;/P&gt;&lt;P&gt;Please let us know if the dynamic query is possible in this case.&lt;/P&gt;&lt;P&gt;Thanks in Advance!&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jun 2021 14:32:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Splunk-Dynamic-query/m-p/554704#M38552</guid>
      <dc:creator>vidya321</dc:creator>
      <dc:date>2021-06-07T14:32:16Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Dynamic query</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Splunk-Dynamic-query/m-p/554725#M38553</link>
      <description>&lt;P&gt;The first part creates some dummy data.&lt;/P&gt;&lt;P&gt;Expand out the events from the JSON,&amp;nbsp; delimit the step number part of the names, and extract the fields, then join the name and duration, put these in a mv field and expand, finally, split the name and duration and perform stats&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="{\"events\": [ 
{
\"custom.JAZZ_INSTANCE\": \"xx-xxx-06-p\",
\"custom.Step1\": \"APP_LandingPage\",
\"custom.Step1Duration\": 205,
\"custom.Step1Status\": \"Pass\",
\"custom.Step2\": \"APP_Login\",
\"custom.Step2Duration\": 1430,
\"custom.Step2Status\": \"Pass\",
\"custom.Step3\": \"APP_Dashboard\",
\"custom.Step3Duration\": 6704,
\"custom.Step3Status\": \"Pass\",
\"custom.Step4\": \"APP_WorkitemQuery\",
\"custom.Step4Duration\": 3349,
\"custom.Step4Status\": \"Pass\",
\"custom.errMsg\": null,
\"custom.errorStep\": null,
\"custom.testCase\": null,
\"custom.testCaseStatus\": null,
\"duration\": 15888.00099992752,
\"error\": \"\",
\"host\": null,
\"locationLabel\": \"china_bcn\",
\"monitorName\": \"APP_CHINA\",
\"result\": \"SUCCESS\",
\"timestamp\": 1623073512664
},{
\"custom.JAZZ_INSTANCE\": \"xx-xxx-06-p\",
\"custom.Step1\": \"APP_LandingPage\",
\"custom.Step1Duration\": 305,
\"custom.Step1Status\": \"Pass\",
\"custom.Step2\": \"APP_Login\",
\"custom.Step2Duration\": 2430,
\"custom.Step2Status\": \"Pass\",
\"custom.Step3\": \"APP_Dashboard\",
\"custom.Step3Duration\": 7704,
\"custom.Step3Status\": \"Pass\",
\"custom.Step4\": \"APP_WorkitemQuery\",
\"custom.Step4Duration\": 4349,
\"custom.Step4Status\": \"Pass\",
\"custom.errMsg\": null,
\"custom.errorStep\": null,
\"custom.testCase\": null,
\"custom.testCaseStatus\": null,
\"duration\": 25888.00099992752,
\"error\": \"\",
\"host\": null,
\"locationLabel\": \"china_bcn\",
\"monitorName\": \"APP_CHINA\",
\"result\": \"SUCCESS\",
\"timestamp\": 1623073512664
}
]}"


| spath path=events{} output=events
| mvexpand events
| rex field=events mode=sed max_match=0 "s/custom\.Step(?&amp;lt;step&amp;gt;\d+)/custom.Step\1./g"
| spath input=events
| foreach custom.Step*.*
    [eval custom.Step&amp;lt;&amp;lt;MATCHSEG1&amp;gt;&amp;gt;.=if("&amp;lt;&amp;lt;MATCHSEG2&amp;gt;&amp;gt;"="Duration",'custom.Step&amp;lt;&amp;lt;MATCHSEG1&amp;gt;&amp;gt;.'.":".'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;','custom.Step&amp;lt;&amp;lt;MATCHSEG1&amp;gt;&amp;gt;.')]
| foreach custom.Step*.
    [eval steps=if(isnull(steps),'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;',mvappend(steps,'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'))]
| table steps
| mvexpand steps
| eval steps=split(steps,":")
| eval step=mvindex(steps,0), duration=mvindex(steps,1)
| stats avg(duration) as avg_duration by step&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 07 Jun 2021 16:28:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Splunk-Dynamic-query/m-p/554725#M38553</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-06-07T16:28:31Z</dc:date>
    </item>
  </channel>
</rss>

