Splunk Search

How to display dates of month in columns

c_krishna_gutur
Explorer

Hi Team,

I have a scenario to display dates of selected month in columns.
For Example , if i select August month in dropdown i need output as 1 2 3 4.......31 [should display all dates as columns] and if i select Feb, dates should be displayed as 1 2 3 ....28

Please help me how can i achieve this.

Tags (1)
0 Karma

knielsen
Contributor

Hi,

You can autogenerate the monthly names as well, they would be ordered in reverse chronological order. Also, you can already calculate the end for the search as well in that search.

This is a working example, it should be rather close to what you are looking for:

    <form>
  <label></label>
  <fieldset submitButton="false" autoRun="false">
    <input type="dropdown" token="begin" searchWhenChanged="true">
      <label>Month</label>
      <fieldForLabel>month</fieldForLabel>
      <fieldForValue>begin</fieldForValue>
      <search>
        <query>| makeresults | timechart span=1mon count | eval month=strftime(_time,"%B %Y")|  eval begin=_time| eval end=relative_time(_time,"+1mon")</query>
        <earliest>-12mon@mon</earliest>
        <latest>@mon</latest>
      </search>
      <change>
        <set token="end">$row.end$</set>
      </change>
    </input>
  </fieldset>
  <row>
    <panel>
      <chart>
        <search>
          <query>index=_internal | timechart span=1d count</query>
          <earliest>$begin$</earliest>
          <latest>$end$</latest>
        </search>
      </chart>
    </panel>
  </row>
</form>

Hth,
-Kai.

0 Karma

niketn
Legend

You would need to set Month values as per default Time field date_month i.e. lower case full month name, similar to following:

<input type="dropdown" token="$tokMonth$" searchWhenChanged="true">
    <label>Select Month</label>
   <choice value="january">January</choice>
     ...
     ...
   <choice value="november">November</choice>
   <choice value="december">December</choice>
   <change>
      <eval token="$tokCurrentYear$">strftime(now(),"%Y")</eval>
   </change>
</input>

Then your search query should have date_month="$tokMonth$" in the base query and statistics should be with span=1d
There could be multiple options the way you are writing your current search following are couple

<YourBaseSearch> date_month="$tokMonth$" date_year="$tokCurrentYear$"
| stats count by date_mday 

Or with span field using timechart command:

<YourBaseSearch> date_month="$tokMonth$" date_year="$tokCurrentYear$"
| timechart span=1d count 

PS: You can also code change event on Select Month dropdown using eval to set year as current year and pass on to the base search if your use case is to filter record only from current year as stated above.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Get Updates on the Splunk Community!

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...

Combine Multiline Logs into a Single Event with SOCK: a Step-by-Step Guide for ...

Combine multiline logs into a single event with SOCK - a step-by-step guide for newbies Olga Malita The ...

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...