Ruby exception occurred: undefined method `size' for nil:NilClass

Hi guys,

I have the next error on a ruby filter. I'd really appreciate any suggest

[2021-04-16T11:28:06,202][ERROR][logstash.filters.ruby ][main-postilion-pipeline][87afa373e1d0191b4f869238d2908162c237ad31fe6074ec0a41fc36d14eb8fa] Ruby exception occurred: undefined method `size' for nil:NilClass

Here's my pipeline filter

>            ruby {
> 
>                 code => "
> 
>                 event.set('msg1Lenght', event.get('msg-1').size)
> 
>                 event.set('msg2Lenght', event.get('msg-2').size)
> 
>                 "
> 
>                 }
> 
> 
>         if [msg1Lenght] < 6 {
> 
>                 mutate {
> 
>                         update => { "msg-1" => "No se encontraron datos en el mensaje." }
> 
>                 }
> 
>         }
> 
>         if [msg2Lenght] < 6 {
> 
>                 mutate {
> 
>                         update => { "msg-2" => "No se encontraron datos de detalle en el mensaje." }
> 
>                 }
> 
> 
>         }

That suggests that one of those fields does not exist. Change

event.set('msg1Lenght', event.get('msg-1').size)

to

msg-1 = event.get('msg-1')
if msg-1
    event.set('msg1Lenght', msg-1.size)
else
    event.set('msg1Lenght', 0)
end

Likewise for msg-2

1 Like

@Badger Thanks a lot, it worked perfectly.

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