logstash - 使用 if-else 和 Logstash 拆分
问题描述
我有一个名为description
delimited with的字符串字段_
。
我将其拆分如下:
filter {
mutate {
split => ["description", "_"]
add_field => {"location" => "%{[description][3]}"}
}
如何检查拆分值是否为空?
我尝试过:
if !["%{[description][3]}"] {
# do something
}
if ![[description][3]] {
# do something
}
if ![description][3] {
# do something
}
它们都不起作用。
目标是将新字段的值location
作为其实际值或通用值,例如NA
.
解决方案
你犯了一个非常简单的错误mutate split
。
这个
mutate {
split => ["description", "_"]
add_field => {"location" => "%{[description][3]}"}
}
本来应该
mutate {
split => ["description"=> "_"] <=== see I removed the comma and added =>
add_field => {"location" => "%{[description][3]}"}
}
这是我测试过的样本
filter {
mutate {
remove_field => ["headers", "@version"]
add_field => { "description" => "Python_Java_ruby_perl " }
}
mutate {
split => {"description" => "_"}
}
if [description][4] {
mutate {
add_field => {"result" => "The 4 th field exists"}
}
} else {
mutate {
add_field => {"result" => "The 4 th field DOES NOT exists"}
}
}
和控制台上的结果(因为没有第 4 个元素,它去else
阻塞
{
"host" => "0:0:0:0:0:0:0:1",
"result" => "The 4 th field DOES NOT exists", <==== from else block
"@timestamp" => 2020-01-14T19:35:41.013Z,
"message" => "hello",
"description" => [
[0] "Python",
[1] "Java",
[2] "ruby",
[3] "perl "
]
}
推荐阅读
- botframework - 需要控制网络聊天中的音频流
- javascript - 在静态函数类中返回 this
- c++ - 如何在 main.cpp 中正确调用“void print_x(ostream& o) const”
- arduino - 使用 Arduino 读取电位器的值效果不佳
- python - Flask 框架使用 GET 而不是指定 POST 方法
- php - 如何在 PHP 中使用 MONTH("2020-02-25") 从数据库中获取数据
- movilizer - 无法选择当前日期作为未来日期
- android - 由于错误膨胀类 androidx.constraintlayout.widget.ConstraintLayout 无法在 Android Studio 上运行我的应用程序
- sql - 根据另一个表上的字段长度更新
- android - 是否必须在 Android 的 MVVM 模式中使用 ViewModel 和实时数据类?否则我们可以在不使用它们的情况下使用 MVVM 模式吗?