Logstash ruby code error

ruby {
code => "
byt = event.get('[network][bytes]');
bytes = byt*8;
microsec = ((event.get('[netflow][flow_end_sys_up_time]'))-(event.get('[netflow][flow_start_sys_up_time]')))/1000;
avg = bytes/microsec;
event.set('netavg_bps', avg);
event.set('total_bytes', bytes);



For above am getting error..
like this
Ruby exception occurred: undefined method *' for nil:NilClass {:class=>"NoMethodError", :backtrace=>["(ruby filter code):4:in block in filter_method.
if am giving microsec!=0
Ruby exception occurred: divided by 0 {:class=>"ZeroDivisionError", :backtrace=>["(ruby filter code):7:
for correct code
can anyone help on this

If an event does not have a [network][bytes] field then this will produce that exception. You need to test it before using it

byt = event.get('[network][bytes]');
if byt
    bytes = byt*8;


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