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!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

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