Splunk Search

How do I display the date in my report with the the data ?

pradeepk50
Observer

I am trying get the max count for the yesterday's but along with this i need to display the date in the report for yesterdays date?
Kindly help me to get the date in the results along with the existing results.

Query: sourcetype="x" name = "any" | bin _time span=1s | stats count by logtime | stats max(count)

Output for the above query is :
max(count)
34

Thanks In Advance

Tags (2)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

The stats command filters out all fields except those explicitly named in the command so _time is not available. Depending on the time window of your search, this may fill your needs.

sourcetype="x" name = "any" | bin _time span=1s | stats count by logtime 
| stats max(count) as MaxCount 
| eval Date = strftime(now(), "%F")
| table Date MaxCount
---
If this reply helps you, Karma would be appreciated.

View solution in original post

manjunathmeti
Champion

Try this,

sourcetype="x" name = "any" | bin _time span=1s | stats count by logtime | eventstats max(count) as count | eval date=strftime(now()-86400, "%d-%m-%Y")
0 Karma

pradeepk50
Observer

by this i am getting count for that interval. Actually i am looking for complete day Max count with the date incorporated in that.

0 Karma

manjunathmeti
Champion

what are logtime values?

0 Karma

pradeepk50
Observer

Its like

logtime
for todays date and time --> the count will get displayed.

Like below
logtime count
2020-03-11 19:38:42 34
2020-03-11 17:30:53 29
2020-03-11 19:17:02 29
2020-03-11 17:17:36 28

0 Karma

manjunathmeti
Champion

ok, you can use stats in place of eventstats. And you wrote need to display the date in the report for yesterdays date. Replace now()-86400 with now() if you don't want yesterdays date.

sourcetype="x" name = "any" | bin _time span=1s | stats count by logtime | stats max(count) as max_count | eval date=strftime(now()-86400, "%d-%m-%Y") | table date, max_count
0 Karma

pradeepk50
Observer

Yeah, this is working as expected.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

The stats command filters out all fields except those explicitly named in the command so _time is not available. Depending on the time window of your search, this may fill your needs.

sourcetype="x" name = "any" | bin _time span=1s | stats count by logtime 
| stats max(count) as MaxCount 
| eval Date = strftime(now(), "%F")
| table Date MaxCount
---
If this reply helps you, Karma would be appreciated.

pradeepk50
Observer

Perfect 🙂

so to get the date field this is the syntax " | eval Date = strftime(now(), "%F")" right ?

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Right. That will get you the current date as a string. Modify the second argument to strftime if you want the date in a different format.

---
If this reply helps you, Karma would be appreciated.
0 Karma

pradeepk50
Observer

By the above query i am getting the date filed in the results but its getting today's date, but the report is running for yesterday's data. So we need to display yesterday's date.

0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

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 ...