Splunk Search

Is there a way to APPEND events based on a field value from main search?

jedatt01
Builder

I have a use case where a user will input a username and Splunk should return results for that username. But, there are seperate events related that username which do not contain the username field, but instead have the same mac address field. The following command is what I wish would work, but I know the append command doesn't allow you to pass data from the main search.

index=my_index UserName=myuser | table _time UserName MacAddress Message | append MacAddress [search index=my_index | table _time UserName MacAddress Message]

Does anybody know how I can acomplish this?

0 Karma
1 Solution

somesoni2
Revered Legend

So if you want to append result of 2nd search to result of 1st search based on a field (common) from the result of 1st search, you need to use syntax like this. The append function doesn't offer any functionality to append conditionally. You have to use a subsearch in the 2nd search:
Updated

index=my_index UserName=myuser | table _time UserName MacAddress Message 
| append [search index=my_index [search index=my_index UserName=myuser | stats count by MacAddress | table MacAddress ]| table _time UserName MacAddress Message]

View solution in original post

chimell
Motivator

Hi jedatt01
Try this search code

| set union [search index=my_index UserName=myuser| fields _time MacAddress Message] [search index=my_index NOT UserName| fields  _time MacAddress Message]|table _time MacAddress Message
0 Karma

somesoni2
Revered Legend

So if you want to append result of 2nd search to result of 1st search based on a field (common) from the result of 1st search, you need to use syntax like this. The append function doesn't offer any functionality to append conditionally. You have to use a subsearch in the 2nd search:
Updated

index=my_index UserName=myuser | table _time UserName MacAddress Message 
| append [search index=my_index [search index=my_index UserName=myuser | stats count by MacAddress | table MacAddress ]| table _time UserName MacAddress Message]

jedatt01
Builder

This worked with one change in the syntax, Remove the MacAddress from after | append

 index=my_index UserName=myuser | table _time UserName MacAddress Message 
 | append [search index=my_index [search index=my_index UserName=myuser | stats count by MacAddress | table MacAddress ]| table _time UserName MacAddress Message]
0 Karma

somesoni2
Revered Legend

Ohh.. cut copy paste error. Updated the answer.

0 Karma

somesoni2
Revered Legend

You sample query says both the searches have a field called UserName, Is that a typo?

0 Karma

s2_splunk
Splunk Employee
Splunk Employee

Have you taken a look at the join command?
Here's a good blog post on event correlation

Hope this helps!

0 Karma

jedatt01
Builder

From what I understand the join command will join the fields of two events together. What I need to to be able to append the events but the append needs to be based on a common field

0 Karma

kbecker
Communicator

Does the MacAddress field exist in both events? If so "join" would work.

0 Karma
Get Updates on the Splunk Community!

Splunk Mobile: Your Brand-New Home Screen

Meet Your New Mobile Hub  Hello Splunk Community!  Staying connected to your data—no matter where you are—is ...

Introducing Value Insights (Beta): Understand the Business Impact your organization ...

Real progress on your strategic priorities starts with knowing the business outcomes your teams are delivering ...

Enterprise Security (ES) Essentials 8.3 is Now GA — Smarter Detections, Faster ...

As of today, Enterprise Security (ES) Essentials 8.3 is now generally available, helping SOC teams simplify ...