Splunk Search

Multi search / correlate conundrum

jeremywebb
Explorer

Sorry for not spelling the problem out in the title, I'm a bit stuck even for the correct language to describe my puzzle. It's best I explain...

I have one index full of log data like the following:

MessageID User
1 Bill
2 Carol
3 Jane
4 Phil
5 Bill

and also

MessageID Attribute A Attribute B Attribute C
1 Y Y N
2 Y N N
5 Y N N

The Message ID ties together the user and the attributes that I'm interested in as I'd like a table that for each user, counts the number of times they've got a message that has an attribute we are interested in. For example for the above data the table would be:

User Attribute A Attribute B Attribute C
Bill 2 1 0
Carol 0 1 0
Jane 0 0 0
Phil 0 0 0

Or to explain another way...Bill had two messages sent to him, and both had attribute A and one had tribute B. Of Carol's messages, only one had Attribute B.

This is as far as I've got, but it only returns the result for one user, and I'm not sure if JOIN is the right approach for this task!

index=thelog recipient bill | join MessageID [search index=thelog "Attribute A" ] | stats count as Recipient by recipient

Your genius is much appreciated!

1 Solution

woodcock
Esteemed Legend

Like this:

| makeresults 
| eval _raw="MessageID,User
1,Bill
2,Carol
3,Jane
4,Phil
5,Bill"
| eval sourcetype="A"
| append [| makeresults 
| eval _raw="MessageID,AttributeA,AttributeB,AttributeC
1,Y,Y,N
2,Y,N,N
5,Y,N,N"
| eval sourcetype="B"]
| multikv forceheader=1
| fields - _* sourcetype linecount

| rename COMMENT AS "Everything above generates sample event data; everything below is your solution"

| stats list(*) AS * values(User) AS User BY MessageID
| stats count(eval(AttributeA="Y")) AS AttributeA count(eval(AttributeB="Y")) AS AttributeB count(eval(AttributeC="Y")) AS AttributeC BY User

View solution in original post

0 Karma

woodcock
Esteemed Legend

Like this:

| makeresults 
| eval _raw="MessageID,User
1,Bill
2,Carol
3,Jane
4,Phil
5,Bill"
| eval sourcetype="A"
| append [| makeresults 
| eval _raw="MessageID,AttributeA,AttributeB,AttributeC
1,Y,Y,N
2,Y,N,N
5,Y,N,N"
| eval sourcetype="B"]
| multikv forceheader=1
| fields - _* sourcetype linecount

| rename COMMENT AS "Everything above generates sample event data; everything below is your solution"

| stats list(*) AS * values(User) AS User BY MessageID
| stats count(eval(AttributeA="Y")) AS AttributeA count(eval(AttributeB="Y")) AS AttributeB count(eval(AttributeC="Y")) AS AttributeC BY User
0 Karma

jeremywebb
Explorer

Worked like a charm, and I learnt something from the approach. Thank you.

renjith_nair
Legend

@jeremywebb,

Try this and test against your data. By looking at your explanation & data, the second row of your result should be Carol 1 0 0.

index=thelog |fields recipient,MessageID,AttributeA,AttributeB,AttributeC
| eventstats values(Attribute*) as Attribute* by MessageID
| stats count(eval(AttributeA="Y")) as AttributeA,count(eval(AttributeB="Y")) as AttributeB,count(eval(AttributeC="Y")) as AttributeC by recipient
---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma

jeremywebb
Explorer

Thanks for this!

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...