Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FluentD: record_transformer conditional statements

How to put conditional if else statements in fluentd record_transformer and add output to column.

eg:

<filter nifi.*>
  @type record_transformer
  enable_ruby true
  auto_typecast true
  <record>
    NormalizedFileInByte ${a=1024;if record[DataMetricIn]=="GB";record["FilesInByte"].to_f*a.to_f;else;record["FilesInByte"].to_f;end;} 
  </record>
</filter>

I have put an if else statement and added a new column NormalizedFileInByte to existing log in the above example. But it errors.

like image 362
Vinayak Mishra Avatar asked Jul 20 '26 19:07

Vinayak Mishra


1 Answers

this worked for me:

NormalizedFileInByte ${if record["message"].split(" ")[2].split(",")[0] == "PM"; record["message"].split(" ")[2].split(",")[0] ;end;
like image 163
Hamza Mourad Avatar answered Jul 25 '26 22:07

Hamza Mourad