Splunk Search

How to sort a statistics based on 2 columns

prerana_jain
Explorer

I have written a command to get the timings of particular log from different servers. I want to sort it based on host and source. I have used multisearch, stats values(xx) by date,time,host,source command.

Example:
Date Time host source
2/20 2:13 110 /opt/source.log
2/20 2:15 117 /opt/dest.log
2/20 2:20 116 /opt/so.log

Expected result:
Sort the statistics with column host and source..

I tried to use case command but not working

0 Karma

to4kawa
Ultra Champion
<form>
  <label>select sort</label>
  <fieldset submitButton="false" autoRun="true">
    <input type="dropdown" token="sort1" searchWhenChanged="true">
      <label>first sort</label>
      <choice value="host">host</choice>
      <choice value="source">source</choice>
      <choice value="Time">Time</choice>
      <choice value="Date">Date</choice>
      <default>host</default>
      <initialValue>host</initialValue>
    </input>
    <input type="dropdown" token="sort2" searchWhenChanged="true">
      <label>second sort</label>
      <choice value="host">host</choice>
      <choice value="source">source</choice>
      <choice value="Time">Time</choice>
      <choice value="Date">Date</choice>
      <default>source</default>
      <initialValue>source</initialValue>
    </input>
  </fieldset>
  <row>
    <panel>
      <table>
        <search>
          <query>|makeresults
|eval _raw="Date Time host source
2/20 2:13 110 /opt/source.log
2/20 2:15 117 /opt/dest.log
2/20 2:20 116 /opt/so.log
2/20 2:13 110 /opt/dest.log
2/20 2:15 117 /opt/source.log"
|multikv forceheader=1
|table Date Time host source
| sort $sort1$ $sort2$</query>
          <earliest>0</earliest>
          <latest></latest>
          <sampleRatio>1</sampleRatio>
        </search>
        <option name="count">20</option>
        <option name="dataOverlayMode">none</option>
        <option name="drilldown">none</option>
        <option name="percentagesRow">false</option>
        <option name="refresh.display">progressbar</option>
        <option name="rowNumbers">false</option>
        <option name="totalsRow">false</option>
        <option name="wrap">true</option>
      </table>
    </panel>
  </row>
</form>

I'm not sure I want to write case telling which host, source has to be first . Which needs to be second

Do you want to create dashboard like above.

your_search
| sort 0 host source

sort is wrong?

0 Karma

prerana_jain
Explorer

The above command is sorting in the ascending order. But I want sort with my requirements.

Ex:
Date Time host source
2/20 2:13 110 /opt/source.log
2/20 2:15 117 /opt/dest.log
2/20 2:20 116 /opt/so.log
2/20 2:13 110 /opt/dest.log
2/20 2:15 117 /opt/source.log

Expected:
Date Time host source
2/20 2:13 110 /opt/dest.log
2/20 2:15 117 /opt/source.log
2/20 2:13 110 /opt/source.log
2/20 2:15 117 /opt/dest.log
2/20 2:20 116 /opt/so.log

I want to write case telling which host, source has to be first . Which needs to be second

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

All Work and No Play? Not at .conf26! Unwind at These Evening Events

Between hands-on technical sessions, keynote reveals, and diving into live architectures, .conf26 is packed ...

Join the Hackathon at .conf26 and build a No-Code AI agent

Join us for the AI Agent Buildathon, an in-person, three-hour hands-on Hackathon where you’ll use Splunk Agent ...

Level Up Your Workflow: Mastering Splunk Cloud Management via Terraform

Tech Talk Recap   From Chaos to Control: Scaling Splunk Cloud with Infrastructure as Code Managing apps in ...