# How to get subfield of cloudtrail logs

**URL:** <https://discuss.elastic.co/t/how-to-get-subfield-of-cloudtrail-logs/182825>\
**Category:** Logstash\
**Created:** [May 27, 2019, 2:51am UTC](https://discuss.elastic.co/t/how-to-get-subfield-of-cloudtrail-logs/182825 "2019-05-27T02:51:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajaysheoran2323](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@ajaysheoran2323](https://discuss.elastic.co/u/ajaysheoran2323)\
**Post date:** [May 27, 2019, 2:51am UTC](https://discuss.elastic.co/t/how-to-get-subfield-of-cloudtrail-logs/182825/1 "2019-05-27T02:51:40Z")

</div>

Hi People, I am using logstash to move logs from cloudtrail to elasticsearch via logstash. Below is the conf file:

```
input {
 s3 {
  bucket => "test-cloudtrail"
  prefix => "AWSLogs/"
  region => "us-west-2"
  access_key_id => "AKIATRONQEXAMPLEEXA"
  secret_access_key => "B809PgsyHkqFu4KXjYrFKexAmpleExample"
  interval => 5

  }
}
output {
 stdout { codec => rubydebug }
 elasticsearch {
 hosts => ["https://blahblah.us-east-1.aws.found.io:9243"]
 user => "elastic"
 password => "blahblah" 
 index => "aws-cloudtrail"
 }
}

```

This format is able to send logs to ES with below format:

```
{
  "_index": "aws-cloudtrail",
  "_type": "_doc",
  "_id": "ZjER92oBx8r9_uotvMwh",
  "_version": 1,
  "_score": null,
  "_source": {
    "message": "{\"Records\":[{\"eventVersion\":\"1.04\",\"userIdentity\":{\"type\":\"AssumedRole\",\"principalId\":\"AROAEXAMPLESRY:ecs-service-scheduler\",\"arn\":\"arn:aws:sts::123123123123:assumed-role/ecsServiceRole/ecs-service-scheduler\",\"accountId\":\"123123123123\",\"accessKeyId\":\
.
.
}",
    "@version": "1",
    "@timestamp": "2019-05-27T02:14:55.631Z"
  },
  "fields": {
    "@timestamp": [
      "2019-05-27T02:14:55.631Z"
    ]
  },
  "sort": [
    123123123123
  ]
}

```

My question is very simple, what should I add in logstash.conf file so that I get an additional field which is grabbed from "message" subfield. If you see the output to ES, it has a field "message", I want to add one more field in ES output with "records[SourceIpAddress]"

I tried with "mutate" but didnt work

filter {  
mutate{  
add\_field =\> { "sourceIPAddress" =\> "%{message[Records][sourceIPAddress]}" }  
}  
}

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [May 27, 2019, 11:59am UTC](https://discuss.elastic.co/t/how-to-get-subfield-of-cloudtrail-logs/182825/2 "2019-05-27T11:59:01Z")

</div>

If [message] is json then you could parse it using a json filter. Then if it is an array in which each element has a SourceIpAddress field you could refer to [Records][0][SourceIpAddress]

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 24, 2019, 11:59am UTC](https://discuss.elastic.co/t/how-to-get-subfield-of-cloudtrail-logs/182825/3 "2019-06-24T11:59:03Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
