logstash的conditional语句(if语句出错)
2016-08-31 12:48
302 查看
语句的基本形式:
条件判断
使用条件来决定filter和output处理特定的事件。logstash条件类似于编程语言。条件支持if、else if、else语句,可以嵌套。
条件语法如下:
比较操作有:
相等: ==, !=, <, >, <=, >=
正则: =~(匹配正则), !~(不匹配正则)
包含: in(包含), not in(不包含)
布尔操作:
and(与), or(或), nand(非与), xor(非或)
一元运算符:
!(取反)
()(复合表达式), !()(对复合表达式结果取反)
语句的具体用法请参照参考url
使用中遇到的问题:
1、
原因是没有找到叫做foo的field,无法把该字段值转化成String类型。所以最好要加field if exist判断。
2、判断字段是否存在,代码如下:
http://www.ttlsa.com/elk/elk-logstash-configuration-syntax/
http://stackoverflow.com/questions/36947535/logstash-conditional-statement-in-input-block
http://stackoverflow.com/questions/30309096/logstash-check-if-field-exists
http://stackoverflow.com/questions/21438697/logstash-conditional-to-check-if-tag-exists
条件判断
使用条件来决定filter和output处理特定的事件。logstash条件类似于编程语言。条件支持if、else if、else语句,可以嵌套。
条件语法如下:
if EXPRESSION { ... } else if EXPRESSION { ... } else { ... }
比较操作有:
相等: ==, !=, <, >, <=, >=
正则: =~(匹配正则), !~(不匹配正则)
包含: in(包含), not in(不包含)
布尔操作:
and(与), or(或), nand(非与), xor(非或)
一元运算符:
!(取反)
()(复合表达式), !()(对复合表达式结果取反)
语句的具体用法请参照参考url
使用中遇到的问题:
1、
if[foo] in "String"在执行这样的语句是,报错如下:
Exception in pipelineworker, the pipeline stopped processing new events, please check your filter configuration and restart Logstash. {"exception"=>#<TypeError: can't convert nil into String>, "backtrace"=>["org/jruby/RubyString.java:4462:in `include?'", "(eval):97:in `initialize'", "org/jruby/RubyArray.java:1613:in `each'", "(eval):95:in `initialize'", "org/jruby/RubyProc.java:281:in `call'", "(eval):68:in `filter_func'", "/opt/logstash-2.3.4/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.4-java/lib/logstash/pipeline.rb:267:in `filter_batch'", "org/jruby/RubyArray.java:1613:in `each'", "org/jruby/RubyEnumerable.java:852:in `inject'", "/opt/logstash-2.3.4/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.4-java/lib/logstash/pipeline.rb:265:in `filter_batch'", "/opt/logstash-2.3.4/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.4-java/lib/logstash/pipeline.rb:223:in `worker_loop'", "/opt/logstash-2.3.4/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.4-java/lib/logstash/pipeline.rb:201:in `start_workers'"], :level=>:error} TypeError: can't convert nil into String include? at org/jruby/RubyString.java:4462 initialize at (eval):97 each at org/jruby/RubyArray.java:1613 initialize at (eval):95 call at org/jruby/RubyProc.java:281 filter_func at (eval):68 filter_batch at /opt/logstash-2.3.4/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.4-java/lib/logstash/pipeline.rb:267 each at org/jruby/RubyArray.java:1613 inject at org/jruby/RubyEnumerable.java:852 filter_batch at /opt/logstash-2.3.4/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.4-java/lib/logstash/pipeline.rb:265 worker_loop at /opt/logstash-2.3.4/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.4-java/lib/logstash/pipeline.rb:223 start_workers at /opt/logstash-2.3.4/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.4-java/lib/logstash/pipeline.rb:201
原因是没有找到叫做foo的field,无法把该字段值转化成String类型。所以最好要加field if exist判断。
2、判断字段是否存在,代码如下:
if ["foo"] { mutate { add_field => "bar" => "%{foo}" } }
http://www.ttlsa.com/elk/elk-logstash-configuration-syntax/
http://stackoverflow.com/questions/36947535/logstash-conditional-statement-in-input-block
http://stackoverflow.com/questions/30309096/logstash-check-if-field-exists
http://stackoverflow.com/questions/21438697/logstash-conditional-to-check-if-tag-exists
相关文章推荐
- 在Repeater控件中使用if语句判断前4条数据 和后面数据样式 不同 并且对4求余的样式又是一种 老是出错
- 6、if 语句对出错的处理
- Python的if...else...语句出错
- nginx配置if错误语句时出错一例
- 在Repeater控件中使用if语句判断前4条数据 和后面数据样式 不同 并且对4求余的样式又是一种 老是出错
- C#条件语句、循环语句(if、while)
- 学习笔记第五周——嵌套if语句之排位大小
- 【基础】java 条件语句 if
- 007day(if,switch语句的学习)
- if语句练习
- 用if语句切换背景:
- JavaScript js设计思维 if语句
- BOOL,float,指针变量与零值比较的if语句
- if语句 和switch语句
- javascript中if语句条件执行顺序
- python 学习笔记 if语句
- 用 if 和 switch 语句实现多分枝结构
- Effective C# Item 4: Use Conditional Attributes Instead of #if
- 使用for if else语句做导航下拉菜单
- 熊猫学猿--(第七竹--常使用的条件语句if)