Splunk Search

Find three different events within a timeframe for the same user

mlorrette
Path Finder

In this dataset, transactions (#3 + #9 + #10 - Mike), and (#5 + #7 +#11  - Alex) -- Would be displayed.

#TimeUserTransaction
112:01DavidLogin from 1.1.1.1
212:01JoeLogin from 2.2.2.2
312:02MikeLogin from 1.1.1.1
412:03DavidSomething else
512:05AlexLogin from 1.1.1.1
612:06MikeSomething else
712:09AlexDelete table
812:10JoeDelete table
912:06MikeDelete table
1012:09MikeInsert Table
1112:14AlexInsert Table
1212:20DavidDelete table

Looking for one search to find all events where within 10 minutes:

1. User logged in from IP address 1.1.1.1 (Search:  userIP = "1.1.1.1"  transaction="Logged"

2. The same user then deleted a table (Search: databaseAction = "DeleteTable")

3. The same user then inserted a table (Search: databaseAction = "InsertTable")

 

I can use startswith and endswith with transaction, but this only gives me the first and last event, not the second.

Labels (3)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

First, thank you for giving a clear illustration of input, desired output, and the logic linking the two.  Let me confirm: Are you skipping Joe because IP address is not 1.1.1.1?

Assuming this is correct, you are looking for something like

 

<some index search> transaction IN (Logged, DeleteTable)
| stats list(transaction) as transaction min(_time) as logon_time max(_time) as delete_time values(userIP) as userIP by User
| where mvindex(transaction, 0) == "Logged" AND mvindex(transaction, -1) LIKE "DeleteTable"
  AND delete_time < relative_time(logon_time, "+10min") AND userIP == "1.1.1.1"
| fieldformat logon_time = strftime(logon_time, "%F %T")
| fieldformat delete_time = strftime(delete_time, "%F %T")

 

Output from your sample data is

User
transaction
logon_timedelete_timeuserIP
Alex
Logged
DeleteTable
2023-11-05 12:05:002023-11-05 12:10:001.1.1.1
Mike
Logged
DeleteTable
2023-11-05 12:02:002023-11-05 12:06:001.1.1.1

This is an emulation you can play with and compare with real data

 

| makeresults
| eval _raw="#	Time	User	Transaction
1	12:01	David	Login from 1.1.1.1
2	12:01	Joe	Login from 2.2.2.2
3	12:02	Mike	Login from 1.1.1.1
4	12:03	David	Something else
5	12:05	Alex	Login from 1.1.1.1
6	12:06	Mike	Something else
7	12:09	Joe	Delete table
8	12:10	Alex	Delete table
9	12:06	Mike	Delete table
10	12:20	David	Delete table"
| multikv forceheader=1
| eval transaction = case(Transaction LIKE "Login from %", "Logged", Transaction == "Delete table", "DeleteTable", true(), "SomethingElse")
| rex field=Transaction "Login from (?<userIP>.+)"
| fields - _* linecount Transaction
| eval _time = strptime(Time, "%H:%M")
| search transaction IN (Logged, DeleteTable)
``` the above emulates
<some index search> transaction IN (Logged, DeleteTable)
```

 

mlorrette
Path Finder

Elegant solution. I'll take a look with our prod data and respond here. Thanks again the the reply.

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