# Ruby exception occurred: undefined method \`unpack1' for nil:NilClass

**URL:** https://discuss.elastic.co/t/ruby-exception-occurred-undefined-method-unpack1-for-nil-nilclass/191134
**Category:** Logstash
**Created:** [July 18, 2019, 7:15am UTC](https://discuss.elastic.co/t/ruby-exception-occurred-undefined-method-unpack1-for-nil-nilclass/191134 "2019-07-18T07:15:34Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Nagesh\_Kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nagesh_kumar/32/47284_2.png) [@Nagesh\_Kumar](https://discuss.elastic.co/u/Nagesh_Kumar)
#### Post date: [July 18, 2019, 7:15am UTC](https://discuss.elastic.co/t/ruby-exception-occurred-undefined-method-unpack1-for-nil-nilclass/191134/1 "2019-07-18T07:15:34Z")

</div>

Hi,  
I am trying with below logstash (7.0 version) conf file to decode base64 logs to send elasticsearch but its throwing below error -  
[2019-07-17T19:01:36,791][ERROR][logstash.filters.ruby] Ruby exception occurred: undefined method `unpack1' for nil:NilClass

Logstash.conf file

input {  
s3 {  
access\_key\_id =\> "xxxxxxx"  
bucket =\> "kinesis-datadog"  
region =\> "us-east-1"  
secret\_access\_key =\> "xxxxxxx8"  
prefix =\> "2019/07/05"  
type =\> "S3"  
}  
}

filter {  
grok {  
match =\> {"message" =\> "%{WORD:prefix} %{WORD:b64} %{WORD:suffix}"}  
}  
ruby {  
init =\> "require 'base64'"  
code =\> "event['b64\_decoded'] = Base64.decode64(event['b64']) if event.include?('b64')"

}  
}

#output plugin, which has the ElasticSearch domain information

output {

elasticsearch {  
hosts =\> ["[http://localhost:9200](http://localhost:9200)"]  
index =\> ".kibana-%{+YYYY.MM.dd}"  
codec =\> rubydebug  
#user =\> "elastic"  
#password =\> "elastic"  
}  
}

---

<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: [July 18, 2019, 9:51am UTC](https://discuss.elastic.co/t/ruby-exception-occurred-undefined-method-unpack1-for-nil-nilclass/191134/2 "2019-07-18T09:51:12Z")

</div>

> [@Nagesh\_Kumar](#):
>
> code =\> "event['b64\_decoded'] = Base64.decode64(event['b64']) if event.include?('b64')"

If you are running logstash v7 I would not expect that to work (although I would expect a different error). You should be using the [event API](https://www.elastic.co/guide/en/logstash/current/event-api.html).

Try

```
code => "
    b64 = event.get('b64')
    if b64
        event.set('b64_decoded', Base64.decode64(b64))
    end
"

```

---

<div class="post-metadata">

### Author: ![Nagesh\_Kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nagesh_kumar/32/47284_2.png) [@Nagesh\_Kumar](https://discuss.elastic.co/u/Nagesh_Kumar)
#### Post date: [July 18, 2019, 1:24pm UTC](https://discuss.elastic.co/t/ruby-exception-occurred-undefined-method-unpack1-for-nil-nilclass/191134/3 "2019-07-18T13:24:54Z")

</div>

Thanks a lot its worked !!

---

<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: [August 15, 2019, 1:24pm UTC](https://discuss.elastic.co/t/ruby-exception-occurred-undefined-method-unpack1-for-nil-nilclass/191134/4 "2019-08-15T13:24:54Z")

</div>

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