Splunk Search

unable to extract deeply-nested JSON from AWS CloudTrail

ttovarzoll
Path Finder

I have a large query which works great to search CloudTrail logs for Security Group changes. Different events, however, place the notable fields in different paths, e.g.

  • requestParameters.groupId
  • requestElements.groupId
  • requestParameters.UpdateSecurityGroupRuleDescriptionsIngressRequest.GroupId

In this instance, I do a series of cascading evals where I set my 'GroupID' to each path ... then do another eval that starts with 'if(isnull(GroupID)' to determine if the previous path was empty. It all works (worked) great.

But now I've found another event type where the notable fields are stashed under a much longer path, e.g.

  • requestParameters.UpdateSecurityGroupRuleDescriptionsIngressRequest.GroupId

There are actually 3 paths -- for GroupId, CIDR and Description. The lookup for the GroupId works but the lookups for CIDR and Description do not. I'm doing everything the same, it just doesn't work. Are they too long?

Here's an example of the CIDR query:

 

 

| spath "requestParameters" 
| eval CIDR = 'requestParameters.cidrIp' 

| eval CIDR = if( isnull(CIDR), 'requestParameters.ipPermissions.items{}.cidrIp', CIDR ) 

| spath "requestParameters.UpdateSecurityGroupRuleDescriptionsIngressRequest.IpPermissions{}.IpRanges.CidrIp" 
| eval CIDR = if( isnull(CIDR), 'requestParameters.UpdateSecurityGroupRuleDescriptionsIngressRequest.IpPermissions.items{}.IpRanges.CidrIp', CIDR ) 

 

 

P.S. I don't think that second 'spath' command is needed (is it?) I only threw it in when I started having trouble getting it work ...

 

Labels (1)
Tags (2)
0 Karma

yeahnah
Motivator

Hi @ttovarzoll 

Not sure why it is not working but maybe using rename instead is a workable solution to get set the CIDR field. 

...
| spath "requestParameters" 
| fields *.cidrIp *.CidrIp 
| rename requestParameters.CidrIp AS CIDR  requestParameters.ipPermissions.items{}.cidrIp AS CIDR  requestParameters.UpdateSecurityGroupRuleDescriptionsIngressRequest.IpPermissions.items{}.IpRanges.CidrIp AS CIDR
| eval CIDR=coalesce(CIDR, "not found")
| ....

Just a thought and hope it helps.

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