Splunk Search

Help with search for specific dates?

AL3Z
Builder

Hi,

Could you help me in editing the below search 

index=test sourcetype="centino" | stats count, values(change_asset) as changed_asset, values(brief) as description, values(severity) as severity, values(exploitation_method) as exploitation_method, values(first_find) as first_find, values(last_find) as last_find,  , values(systems) as system by id.

1. In the below output of fields we need to display only the date 2023-01-22 

first_find                                                 last_find

AL3Z_0-1675099386157.jpeg

2. Instead of receiving all the notifications we require, if today's date matches the first _find or the last_find, raise an alert
*todays date will change every day do not bound that with actual todays date*

Thanks...

Labels (1)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

There are a few ways to reduce the timestamp to just the date.  The substr() function may be the easiest.

Use the now() function to get the current timestamp and the strftime() function to convert it into the same format as first_find and last_find.  Then the where command can compare them and only show events from today.

index=test sourcetype="issues" 
| eval first_find=substr(first_find, 1, 10), last_find=substr(last_find, 1, 10)
| stats count, values(change_asset) as changed_asset, values(brief) as description, values(severity) as severity, values(exploitation_method) as exploitation_method, values(first_find) as first_find, values(last_find) as last_find,  , values(systems) as system by id
| eval today = strftime(now(), "%Y-%m-%d")
| where (match(first_find, today) OR match(last_find, today))

Note that this query may not work properly if first_find and last_find are multi-value fields.

 

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

AL3Z
Builder

@richgalloway 

@itwishperer
@

Hi,

what if we have a multi valued fields,could you  pls make a search according to that 

 

Thanks..

0 Karma

richgalloway
SplunkTrust
SplunkTrust

The concept of more than one "first" or "last" anything baffles me so here is a query that eliminates mutli-value firsts and lasts.

index=test sourcetype="issues" 
| eval first_find=substr(first_find, 1, 10), last_find=substr(last_find, 1, 10)
| stats count, values(change_asset) as changed_asset, values(brief) as description, values(severity) as severity, values(exploitation_method) as exploitation_method, earliest(first_find) as first_find, latest(last_find) as last_find, values(systems) as system by id
| eval today = strftime(now(), "%Y-%m-%d")
| where (match(first_find, today) OR match(last_find, today))
---
If this reply helps you, Karma would be appreciated.

AL3Z
Builder

@richgalloway 

this search is not raising any alerts, what could be the problem, the first find and last time fields time in events looks like UTC time, do we need to normalise to IST to get it match if so how we can normalise it.
thnks.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Normalize timestamps by using the strptime function to convert them into internal (epoch) form.

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

AL3Z
Builder

@richgalloway 

Hi,

This query is same as first query.

What the difference ?

 

0 Karma

richgalloway
SplunkTrust
SplunkTrust

The difference is the second query uses earliest and latest instead of values for the first_find and last_find fields to avoid multi-value results.

---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

Unlock Database Monitoring with Splunk Observability Cloud

  In today’s fast-paced digital landscape, even minor database slowdowns can disrupt user experiences and ...

Purpose in Action: How Splunk Is Helping Power an Inclusive Future for All

At Cisco, purpose isn’t a tagline—it’s a commitment. Cisco’s FY25 Purpose Report outlines how the company is ...

[Upcoming Webinar] Demo Day: Transforming IT Operations with Splunk

Join us for a live Demo Day at the Cisco Store on January 21st 10:00am - 11:00am PST In the fast-paced world ...