Splunk Search

Merge 2 queries base on id

shrogers
Loves-to-Learn Everything

Need some assistance from the experts.

I have two queries below which I would like to merge on id.

Query 1

index=aws sourcetype=aws:cloudtrail eventName=RebootInstances | table _time userName sourceIPAddress requestParameters.instancesSet.items{}.instanceId
| rename requestParameters.instancesSet.items{}.instanceId as id

Query 2

index=aws sourcetype=aws:description source="us-east-2:ec2_instances" | table id private_ip_address

 

I would like the final table fields to be:

time  userName  sourceIPAddress    id   private_ip_address

 

Any assistance given will be appreciated.

Labels (1)
Tags (1)
0 Karma

bowesmana
SplunkTrust
SplunkTrust

Try this

(index=aws sourcetype=aws:cloudtrail eventName=RebootInstances) OR
(index=aws sourcetype=aws:description source="us-east-2:ec2_instances")
| eval id=coalesce(id, 'requestParameters.instancesSet.items{}.instanceId')
| eval _time=if(sourcetype="aws:cloudtrail", _time, null())
| fields _time userName sourceIPAddress private_ip_address id
| stats values(*) as * by id

 It searches both data sets.

  • id is then set as either id OR the instanceId in the coalesce statement.
  • _time is set to null if it is the description sourcetype, forcing _time to come from the cloudtrail event
  • fields are then limited to the ones specified
  • stats takes the values of all fields and effectively merges the data on the id field

Hope this helps

 

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@shrogers 

Can you please try this?

index=aws (sourcetype=aws:cloudtrail eventName=RebootInstances) OR (sourcetype=aws:description source="us-east-2:ec2_instances")
| fields _time userName sourceIPAddress requestParameters.instancesSet.items{}.instanceId id private_ip_address 
| rename requestParameters.instancesSet.items{}.instanceId as id
| stats latest(_time) as _time values(userName) as userName values(sourceIPAddress) as sourceIPAddress values(private_ip_address) as private_ip_address by id
| table time  userName  sourceIPAddress    id private_ip_address

 

KV 

0 Karma

shrogers
Loves-to-Learn Everything

Hi Kamlesh,

Thank you for your quick response.

Unfortunately, the time and private_id_address are not being populated.

 

Regards,

Sheldon

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