Splunk Search

How to add the latest time of laptop communication to another column in a CSV file?

Nayakstar
New Member

I have a list of Laptop names in one column of a CSV file and I want to add the latest time of its communication in another column. In my Splunk logs, one field is "laptop" and other one is "_time".

Please suggest any solution.

Tags (4)
0 Karma
1 Solution

somesoni2
Revered Legend

Try something like this

your splunk log search giving field laptop and _time | stats max(_time) as recentTime by laptop
| append [| inputlookup yourlaptoplookup.csv | table laptop recentTime ] 
| stats max(_time) as recentTime by laptop | outputlookup append=f yourlaptoplookup.csv 

View solution in original post

0 Karma

DalJeanis
Legend

It's going to look something like this -

index=laptopindex "put search criteria here for the laptop info events"
| fields _time laptop
| stats max(_time) as Last_Time by laptop
| rename laptop as Laptop
| eval Last_Time= strftime(Last_Time,"%Y-%m-%d %H:%M:%S")
| inputlookup append=T  mylaptoptracking.csv 
| table Laptop last_time
| outputlookup mylaptoptracking.csv 

This accounts for the two fields you asked for, which I've assumed in the csv are called Laptop and Last_Time.

You might want to change the reformatting of the Last_Time field to whatever format you want the csv to store the date/time in.

0 Karma

somesoni2
Revered Legend

Try something like this

your splunk log search giving field laptop and _time | stats max(_time) as recentTime by laptop
| append [| inputlookup yourlaptoplookup.csv | table laptop recentTime ] 
| stats max(_time) as recentTime by laptop | outputlookup append=f yourlaptoplookup.csv 
0 Karma

DalJeanis
Legend

Slightly different from mine, but this should work, depending on the spelling and capitalization of the field names in the csv file.

The OP should be careful that at the point immediately before the append, either when using somesoni2's method or mine, that the fields are spelled and capitalized exactly the way they are in the csv, for the remainder of the search code. Before that point, they should be named and spelled however they are on the events.

0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...