我正在使用 rsyslog 监视我的系统日志并将它们发送到 Logstash+Kibana。
我的系统日志消息以 JSON 格式记录。它们看起来像这样:
{"foo":"bar", "timegenerated": 43843274834}
rsyslog 配置如下:
module(load="omelasticsearch")
#define a template to print all fields of the message
template(name="messageToES" type="list" option.json="on") {
property(name="msg")
}
*.* action(type="omelasticsearch"
server="localserverhere"
serverport="80"
template="messageToES")
Kibana 很好,因为如果我对它运行 CURL 命令,它就会收到记录。代码如下:
curl -XPOST myserver/test/bar -d '{"test": "baz", "timegenerated":1447145221519}'
当我运行 rsyslogs 并将其指向虚拟服务器时,我可以看到带有有效 json 的传入请求。但是,当我将它指向我的 logstash 服务器时,它并没有出现在 logstash 或 kibana 中。
有谁知道如何将系统日志作为 json 发送到 Kibana/logstash 中?
最佳答案
我从未使用过它,但看起来您的配置文件中缺少某些内容。文档有一个非常详尽的示例:
module(load="omelasticsearch")
template(name="testTemplate"
type="list"
option.json="on") {
constant(value="{")
constant(value="\"timestamp\":\"") property(name="timereported" dateFormat="rfc3339")
constant(value="\",\"message\":\"") property(name="msg")
constant(value="\",\"host\":\"") property(name="hostname")
constant(value="\",\"severity\":\"") property(name="syslogseverity-text")
constant(value="\",\"facility\":\"") property(name="syslogfacility-text")
constant(value="\",\"syslogtag\":\"") property(name="syslogtag")
constant(value="\"}")
}
action(type="omelasticsearch"
server="myserver.local"
serverport="9200"
template="testTemplate"
searchIndex="test-index"
searchType="test-type"
bulkmode="on"
queue.type="linkedlist"
queue.size="5000"
queue.dequeuebatchsize="300"
action.resumeretrycount="-1")
根据您尝试执行的操作,您似乎需要在显示 myserver.local
的地方插入 localserverhere
。看起来你的 ES 也在端口 80 上接受东西,所以你应该输入 80
而不是 9200
。
关于json - 将 JSON 从 rsyslog 发送到 Kibana,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33639591/