Logstash exec 输入插件 - 从@message 中删除命令 运行

Logstash exec input plugin - Remove command run from @message

我在 windows 机器上使用 logstash 1.5.1。我必须打个休息电话,它会给我 JSON 输出。

因此我正在使用 exec。结果不再是 json :-(.

The @message of this event will be the entire stdout of the command as one event. https://www.elastic.co/guide/en/logstash/current/plugins-inputs-exec.html

我的 logstash 配置

input {
    exec {
        command => "C:\bin\curl\curl.exe http://localhost:8080/jolokia/read/metrics:name=trx.process.approved" 
        interval => 10
        codec => json { charset => "CP1252" }
    }
}
output {
  elasticsearch {
    node_name => test
    host => myhost  
  }
}

cmd下的输出

{"request":{"mbean":"metrics:name=trx.process.approved","type":"read"},"value":{"Count":14},"timestamp":1434643572,"status":200}

elasticsearch 上无法解析的输出(3 行!)


C:\Daten\tools\logstash-1.5.1\bin>C:\bin\curl\curl.exe http://localhost:8080/jolokia/read/metrics:name=trx.process.approved
{"request":"mbean":"metrics:name=trx.process.approved","type":"read"},"value":{"Count":14},"timestamp":1434641808,"status":200}

通常我会尝试只削减 JSON 输出,但不知何故我在 Windows 方面的知识有限。

我试过过滤器插件 split 来分隔这三行,但不知道如何删除第 1 行和第 2 行。

filter {
    split {     
    }
}

感谢任何指点。

最后我只想将这一行发送到elasticsearch:

{"request":{"mbean":"metrics:name=trx.process.approved","type":"read"},"value":{"Count":14},"timestamp":1434641808,"status":200}

自己找到解决方案

filter {
    split { 
    }
    if  [message] !~ "^{" {
        drop {}
    }
}

如果字符串不是以“{”开头,则使用带正则表达式的条件将删除该行。