Splunk Search

Anything wrong is with join query?

kyoung2580
Explorer

I have inserted the same data in splunk and mysql.

Splunk query:

 

index=sysmon EventCode=3
| stats count as sysmon_count by img_name
| sort sysmon_count desc
| join type=inner img_name
    [ search index=winevent EventCode=5156
    | stats count as winevt_count by img_name ]
| table img_name, sysmon_count, winevt_count

 

Result:

img_namesysmon_countwinevt_count
splunkd.exe36973701
python3.exe6143071
streamfwd.exe6141228
chrome.exe211910
svchost.exe3697
System2234
taskhostw.exe12
whale_update.exe11

 

Mysql query:

 

select a.img_name, a.sysmon_count, b.winevt_count
from (
	select img_name, count(*) as sysmon_count
	from sysmon
	where eventcode = 3
	group by img_name
	order by sysmon_count desc) a
join (
	select img_name, count(*) as winevt_count
	from winevent
	where eventcode=5156
	group by img_name
	order by winevt_count desc) b
on a.img_name = b.img_name

 

Result:

img_namesysmon_countwinevt_count
splunkd.exe36973701
python3.exe6143071
streamfwd.exe6141228
chrome.exe211910
svchost.exe3697
System2234
RuntimeBroker.exe22
taskhostw.exe12
backgroundTaskHost.exe11
OfficeClickToRun.exe11
POWERPNT.EXT11
MsMpEng.exe11
CEIP.exe11
whale_update.exe11

 

Add:

I have found the cause of join problem. Mysql is case-insensitive but splunk is case-sensitive. It can get the same result as mysql when change the join field(img_name) to lowercase. 

index=sysmon EventCode=3
| eval img_name = lower(img_name)
| stats count as sysmon_count by img_name
| sort sysmon_count desc 
| join type=inner img_name
    [ search index=winevent EventCode=5156
    | eval img_name = lower(img_name)
    | stats count as winevt_count by img_name ]

 

Labels (1)
0 Karma
1 Solution

manjunathmeti
Champion

hi @kyoung2580,
You don't need a join command, you can try this,

index=sysmon EventCode=3 OR EventCode=5156
| stats count(eval(EventCode=3)) as sysmon_count, count(eval(EventCode=5156)) as winevt_count by img_name
| sort sysmon_count desc
| table img_name, sysmon_count, winevt_count

 

If you still find some img_name values missing then they might not be there in your index OR you might need to increase the search time range depending on when the data is collected in Splunk and event timestamps.

index=sysmon EventCode=3 OR EventCode=5156 earliest=1
| stats count(eval(EventCode=3)) as sysmon_count, count(eval(EventCode=5156)) as winevt_count by img_name
| sort sysmon_count desc
| table img_name, sysmon_count, winevt_count

 

If this reply helps you, an upvote/like would be appreciated.

View solution in original post

kyoung2580
Explorer

@manjunathmeti It works! This is very helpful. Thank you very much.:)

0 Karma

manjunathmeti
Champion

hi @kyoung2580,
You don't need a join command, you can try this,

index=sysmon EventCode=3 OR EventCode=5156
| stats count(eval(EventCode=3)) as sysmon_count, count(eval(EventCode=5156)) as winevt_count by img_name
| sort sysmon_count desc
| table img_name, sysmon_count, winevt_count

 

If you still find some img_name values missing then they might not be there in your index OR you might need to increase the search time range depending on when the data is collected in Splunk and event timestamps.

index=sysmon EventCode=3 OR EventCode=5156 earliest=1
| stats count(eval(EventCode=3)) as sysmon_count, count(eval(EventCode=5156)) as winevt_count by img_name
| sort sysmon_count desc
| table img_name, sysmon_count, winevt_count

 

If this reply helps you, an upvote/like would be appreciated.

Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...