Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 如何在Logstash配置文件中包含过滤器?_Json_Logstash_Logstash Configuration - Fatal编程技术网

Json 如何在Logstash配置文件中包含过滤器?

Json 如何在Logstash配置文件中包含过滤器?,json,logstash,logstash-configuration,Json,Logstash,Logstash Configuration,我正在使用LogStash,它接受来自日志文件的数据,日志文件具有不同类型的日志 第一行表示自定义日志,而第二行表示JSON格式的日志 现在,我想编写一个过滤器,它将根据内容解析日志,最后将所有JSON格式的日志定向到一个名为jsonformat.log的文件,并将其他日志定向到一个单独的文件中 您可以利用json过滤器检查它是否失败,以决定将事件发送到何处 input { file { path => "/Users/mysystem/Desktop/abc.log"

我正在使用LogStash,它接受来自日志文件的数据,日志文件具有不同类型的日志

第一行表示自定义日志,而第二行表示JSON格式的日志


现在,我想编写一个过滤器,它将根据内容解析日志,最后将所有JSON格式的日志定向到一个名为jsonformat.log的文件,并将其他日志定向到一个单独的文件中

您可以利用
json
过滤器检查它是否失败,以决定将事件发送到何处

input {
   file {
       path => "/Users/mysystem/Desktop/abc.log"
       start_position => beginning
       ignore_older => 0
   }
}
filter {
   json {
     source => "message"
   }
}
output {
  # this condition will be true if the log line is not valid JSON
  if "_jsonparsefailure" in [tags] {
    file {
       path => "/Users/mysystem/Desktop/nonjson.log"
    }
  }
  # this condition will be true if the log line is valid JSON
  else {
    file {
       path => "/Users/mysystem/Desktop/jsonformat.log"
    }
  }
}

您可以利用
json
过滤器检查它是否失败,以决定将事件发送到何处

input {
   file {
       path => "/Users/mysystem/Desktop/abc.log"
       start_position => beginning
       ignore_older => 0
   }
}
filter {
   json {
     source => "message"
   }
}
output {
  # this condition will be true if the log line is not valid JSON
  if "_jsonparsefailure" in [tags] {
    file {
       path => "/Users/mysystem/Desktop/nonjson.log"
    }
  }
  # this condition will be true if the log line is valid JSON
  else {
    file {
       path => "/Users/mysystem/Desktop/jsonformat.log"
    }
  }
}

我不知道为什么,但尽管您的代码通过了配置测试,但当我在输入文件上运行它时,它只是显示管道已经启动,但它没有创建日志文件。您需要向
abc.log
文件添加新行,或者向文件输入添加
sincedb\u path=>“/dev/null”
。是的,我这样做了。我甚至尝试添加新行,但仍然无法生成新文件。我正在发布我的配置文件供您查看。还有,输入文件。(作为问题中编辑的一部分提到)能否将abc.log文件重命名为其他名称?甚至可能将其移动到另一个文件夹尝试重命名,并将其移动到一个新文件夹(是的,我更改了配置文件中的路径),但仍然不起作用。只是表明管道已经启动。另外,你能看一下问题的编辑吗?我不知道为什么,尽管你的代码通过了配置测试,但当我在输入文件上运行它时,它只是显示管道已经启动,但它没有创建日志文件。你要么需要在
abc.log
文件中添加新行,要么添加
sincedb\u path=>“/dev/null”
添加到您的文件输入。是的,我这样做了。我甚至尝试添加新行,但仍然无法生成新文件。我正在发布我的配置文件供您查看。还有,输入文件。(作为问题中编辑的一部分提到)能否将abc.log文件重命名为其他名称?甚至可能将其移动到另一个文件夹尝试重命名,并将其移动到一个新文件夹(是的,我更改了配置文件中的路径),但仍然不起作用。只是表明管道已经启动。另外,你能看一下问题的编辑吗?