Splunk Search

find the latest field only from multiple output

surekhasplunk
Communicator

I have a query like below :

bla bla ...| lookup mylookupfile.csv Hostname as Name output Status Creation_Date
| eval Status=MVDEDUP(Status) |eval Creation_Date=mvindex(Creation_Date,-1)| then rest of my query

Here issue happens when while matching for the Hostname i get two Status values 

So above query gives me output where : 

1) i am getting Creation_Date field as the latest date only

2) But Status i am receiving both Active and Destroyed

i want to get in Status field only the corresponding value of Status for latest(Creation_Date)

How can i do that

Labels (1)
Tags (2)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

If I understand the problem correctly then this should help.

bla bla ...| lookup mylookupfile.csv Hostname as Name output Status Creation_Date
| eval created = strptime(Creation_Date, "format string that matches the date format")
| sort 1000 - created
| fields - created
| head 1
| then rest of my query

 The lookup file already associates Status with Creation_Date so all the query needs to do is find the most recent Creation_Date value.  We do that by converting the Creation_Date field to epoch form (assuming it is not already an epoch) then sorting the dates in descending order.  The first event in the results is the latest date.

---
If this reply helps you, Karma would be appreciated.
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...