Splunk Search

How to create a search that compares the user by time, using different sourcetypes

raghuchams4527
Explorer

Hi All,

I've two sourcetypes with user information. I want to match the user by time.
Please provide me the Splunk search to match the user by time.

If the users do not match that time I need to set up an alert.

Tags (3)
0 Karma
1 Solution

niyaz006
Path Finder
sourcetype="sourcetype1"
| search NOT 
    [
    search sourcetype="sourcetype2"
    | stats values(username) as username, values(_time) as _time
    ]
| stats values(username) as username

You will get the list of unmatched usernames which you could then use to trigger alert

View solution in original post

niyaz006
Path Finder
sourcetype="sourcetype1"
| search NOT 
    [
    search sourcetype="sourcetype2"
    | stats values(username) as username, values(_time) as _time
    ]
| stats values(username) as username

You will get the list of unmatched usernames which you could then use to trigger alert

kmorris_splunk
Splunk Employee
Splunk Employee

You would probably have to settle for close to the same time, but you could do something with the transaction command:

sourcetype=sourcetype1 OR sourcetype=sourcetype2 
| transaction username maxspan=10s 
| eval st_count=mvcount(sourcetype) 
| where eventcount > 1 AND st_count > 1 
| table username eventcount st_count

Take note of the maxspan=10s bit. This is going to be your tolerance for how far away from each other, the events can be. The next line, where we do the mvcount is so we can make sure we are getting events from both of your sourcetypes. This is counting the number of values in a multivalued field which is generated by the transaction command. The eventcount field is automatically generated when you use transaction. The Transaction command will group all events within the maxspan where username is the same.

Hopefully this will work for your use case.

0 Karma

kmorris_splunk
Splunk Employee
Splunk Employee

Just a little clarification. Are you trying to find events in the two sourcetypes, with the same user and that happened at or close to the same time?

0 Karma

raghuchams4527
Explorer

I want to match the user by time in both sourcetypes..

0 Karma

raghuchams4527
Explorer

yes, same user same time in both sourcetypes

0 Karma
Get Updates on the Splunk Community!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...