Logstash
嘗試發送到 slack webhook 時,Logstash 輸出-http 外掛錯誤 500
我正在執行一個帶有 ELK 堆棧的 docker 容器。一切都很好,很好。我想使用https://www.elastic.co/guide/en/logstash/current/plugins-outputs-http.html外掛。
我安裝外掛它:
root@elk:/# /opt/logstash/bin/plugin install logstash-output-http Validating logstash-output-http Installing logstash-output-http Installation successful
/etc/logstash/conf.d/logstash.conf
主logstash配置文件:input { beats { port => 5044 type => "logs" } } filter { grok { match => { "message" => "\"name\":\"Error\""} add_tag => ["error"] } } output { elasticsearch { hosts => "localhost:9200" sniffing => true manage_template => false index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}" document_type => "%{[@metadata][type]}" } if "error" in [tags] { http { http_method => "post" url => "https://hooks.slack.com/services/<MY_ID>" format => "json" content_type => "application/json" message => "{\"text\": \"dis is workinz\"}" } } }
我還嘗試更改 http 中的格式:
... format => "message" ...
該配置也經過測試並且有效:
root@elk:/# /opt/logstash/bin/logstash --configtest -f /etc/logstash/conf.d/logstash.conf Configuration OK
兩者都導致它不起作用。我仔細檢查以確保 webhook 正在使用測試(來自 logstash docker 容器):
curl -H "Content-Type: application/json" -X POST -d '{"text":"testing"}' https://hooks.slack.com/services/<MY_ID>
我知道標籤被正確應用,在 Kibana 中檢查。此外,if 子句也在工作,因為我
elasticsearch
在其中進行了測試,它確實只將帶有添加error
標籤的日誌發送到 elasticsearch。最後是來自以下的神聖錯誤消息
/var/log/logstash/logstah.log
:{: timestamp => "2016-02-25T15:55:35.926000+0000", : message => "[HTTP Output Failure] Encountered non-200 HTTP code 200", : response_code => 500, : url => "https://hooks.slack.com/services/<YES_THE_ACTUAL_WEBHOOK_ID_WAS_HERE>", : event => # < LogStash::Event: 0x408e202@ metadata = { "beat" => "filebeat", "type" => "log" }, @accessors = # < LogStash::Util::Accessors: 0x5dc514d7@ store = { "message" => "{\"name\":\"myapp\",\"hostname\":\"sensu-node-dev\",\"pid\":749,\"level\":50,\"err\":{\"message\":\"Cannot find module 'lol'\",\"name\":\"Error\",\"stack\":\"Error: Cannot find module 'lol'\\n at Function.Module._resolveFilename (module.js:339:15)\\n at Function.Module._load (module.js:290:25)\\n at Module.require (module.js:367:17)\\n at require (internal/module.js:16:19)\\n at Object.<anonymous> (/srv/www/dev.site/app.js:27:6)\\n at next (native)\\n at Object.<anonymous> (/srv/www/dev.site/node_modules/koa-compose/index.js:29:5)\\n at next (native)\\n at onFulfilled (/srv/www/dev.site/node_modules/co/index.js:65:19)\\n at /srv/www/dev.site/node_modules/co/index.js:54:5\",\"code\":\"MODULE_NOT_FOUND\"},\"msg\":\"Cannot find module 'lol'\",\"time\":\"2016-02-25T15:55:25.509Z\",\"v\":0}", "@version" => "1", "@timestamp" => "2016-02-25T15:55:34.004Z", "beat" => { "hostname" => "sensu-node-dev", "name" => "sensu-node-dev" }, "count" => 1, "fields" => nil, "input_type" => "log", "offset" => 29352, "source" => "/var/log/bunyan/myapp-info.log", "type" => "log", "host" => "sensu-node-dev", "tags" => ["beats_input_codec_plain_applied", "error"] }, @lut = { "@timestamp" => [{ "message" => "{\"name\":\"myapp\",\"hostname\":\"sensu-node-dev\",\"pid\":749,\"level\":50,\"err\":{\"message\":\"Cannot find module 'lol'\",\"name\":\"Error\",\"stack\":\"Error: Cannot find module 'lol'\\n at Function.Module._resolveFilename (module.js:339:15)\\n at Function.Module._load (module.js:290:25)\\n at Module.require (module.js:367:17)\\n at require (internal/module.js:16:19)\\n at Object.<anonymous> (/srv/www/dev.site/app.js:27:6)\\n at next (native)\\n at Object.<anonymous> (/srv/www/dev.site/node_modules/koa-compose/index.js:29:5)\\n at next (native)\\n at onFulfilled (/srv/www/dev.site/node_modules/co/index.js:65:19)\\n at /srv/www/dev.site/node_modules/co/index.js:54:5\",\"code\":\"MODULE_NOT_FOUND\"},\"msg\":\"Cannot find module 'lol'\",\"time\":\"2016-02-25T15:55:25.509Z\",\"v\":0}", "@version" => "1", "@timestamp" => "2016-02-25T15:55:34.004Z", "beat" => { "hostname" => "sensu-node-dev", "name" => "sensu-node-dev" }, "count" => 1, "fields" => nil, "input_type" => "log", "offset" => 29352, "source" => "/var/log/bunyan/myapp-info.log", "type" => "log", "host" => "sensu-node-dev", "tags" => ["beats_input_codec_plain_applied", "error"] }, "@timestamp"], "beat" => [{ "message" => "{\"name\":\"myapp\",\"hostname\":\"sensu-node-dev\",\"pid\":749,\"level\":50,\"err\":{\"message\":\"Cannot find module 'lol'\",\"name\":\"Error\",\"stack\":\"Error: Cannot find module 'lol'\\n at Function.Module._resolveFilename (module.js:339:15)\\n at Function.Module._load (module.js:290:25)\\n at Module.require (module.js:367:17)\\n at require (internal/module.js:16:19)\\n at Object.<anonymous> (/srv/www/dev.site/app.js:27:6)\\n at next (native)\\n at Object.<anonymous> (/srv/www/dev.site/node_modules/koa-compose/index.js:29:5)\\n at next (native)\\n at onFulfilled (/srv/www/dev.site/node_modules/co/index.js:65:19)\\n at /srv/www/dev.site/node_modules/co/index.js:54:5\",\"code\":\"MODULE_NOT_FOUND\"},\"msg\":\"Cannot find module 'lol'\",\"time\":\"2016-02-25T15:55:25.509Z\",\"v\":0}", "@version" => "1", "@timestamp" => "2016-02-25T15:55:34.004Z", "beat" => { "hostname" => "sensu-node-dev", "name" => "sensu-node-dev" }, "count" => 1, "fields" => nil, "input_type" => "log", "offset" => 29352, "source" => "/var/log/bunyan/myapp-info.log", "type" => "log", "host" => "sensu-node-dev", "tags" => ["beats_input_codec_plain_applied", "error"] }, "beat"], "count" => [{ "message" => "{\"name\":\"myapp\",\"hostname\":\"sensu-node-dev\",\"pid\":749,\"level\":50,\"err\":{\"message\":\"Cannot find module 'lol'\",\"name\":\"Error\",\"stack\":\"Error: Cannot find module 'lol'\\n at Function.Module._resolveFilename (module.js:339:15)\\n at Function.Module._load (module.js:290:25)\\n at Module.require (module.js:367:17)\\n at require (internal/module.js:16:19)\\n at Object.<anonymous> (/srv/www/dev.site/app.js:27:6)\\n at next (native)\\n at Object.<anonymous> (/srv/www/dev.site/node_modules/koa-compose/index.js:29:5)\\n at next (native)\\n at onFulfilled (/srv/www/dev.site/node_modules/co/index.js:65:19)\\n at /srv/www/dev.site/node_modules/co/index.js:54:5\",\"code\":\"MODULE_NOT_FOUND\"},\"msg\":\"Cannot find module 'lol'\",\"time\":\"2016-02-25T15:55:25.509Z\",\"v\":0}", "@version" => "1", "@timestamp" => "2016-02-25T15:55:34.004Z", "beat" => { "hostname" => "sensu-node-dev", "name" => "sensu-node-dev" }, "count" => 1, "fields" => nil, "input_type" => "log", "offset" => 29352, "source" => "/var/log/bunyan/myapp-info.log", "type" => "log", "host" => "sensu-node-dev", "tags" => ["beats_input_codec_plain_applied", "error"] }, "count"], "fields" => [{ "message" => "{\"name\":\"myapp\",\"hostname\":\"sensu-node-dev\",\"pid\":749,\"level\":50,\"err\":{\"message\":\"Cannot find module 'lol'\",\"name\":\"Error\",\"stack\":\"Error: Cannot find module 'lol'\\n at Function.Module._resolveFilename (module.js:339:15)\\n at Function.Module._load (module.js:290:25)\\n at Module.require (module.js:367:17)\\n at require (internal/module.js:16:19)\\n at Object.<anonymous> (/srv/www/dev.site/app.js:27:6)\\n at next (native)\\n at Object.<anonymous> (/srv/www/dev.site/node_modules/koa-compose/index.js:29:5)\\n at next (native)\\n at onFulfilled (/srv/www/dev.site/node_modules/co/index.js:65:19)\\n at /srv/www/dev.site/node_modules/co/index.js:54:5\",\"code\":\"MODULE_NOT_FOUND\"},\"msg\":\"Cannot find module 'lol'\",\"time\":\"2016-02-25T15:55:25.509Z\",\"v\":0}", "@version" => "1", "@timestamp" => "2016-02-25T15:55:34.004Z", "beat" => { "hostname" => "sensu-node-dev", "name" => "sensu-node-dev" }, "count" => 1, "fields" => nil, "input_type" => "log", "offset" => 29352, "source" => "/var/log/bunyan/myapp-info.log", "type" => "log", "host" => "sensu-node-dev", "tags" => ["beats_input_codec_plain_applied", "error"] }, "fields"], "input_type" => [{ "message" => "{\"name\":\"myapp\",\"hostname\":\"sensu-node-dev\",\"pid\":749,\"level\":50,\"err\":{\"message\":\"Cannot find module 'lol'\",\"name\":\"Error\",\"stack\":\"Error: Cannot find module 'lol'\\n at Function.Module._resolveFilename (module.js:339:15)\\n at Function.Module._load (module.js:290:25)\\n at Module.require (module.js:367:17)\\n at require (internal/module.js:16:19)\\n at Object.<anonymous> (/srv/www/dev.site/app.js:27:6)\\n at next (native)\\n at Object.<anonymous> (/srv/www/dev.site/node_modules/koa-compose/index.js:29:5)\\n at next (native)\\n at onFulfilled (/srv/www/dev.site/node_modules/co/index.js:65:19)\\n at /srv/www/dev.site/node_modules/co/index.js:54:5\",\"code\":\"MODULE_NOT_FOUND\"},\"msg\":\"Cannot find module 'lol'\",\"time\":\"2016-02-25T15:55:25.509Z\",\"v\":0}", "@version" => "1", "@timestamp" => "2016-02-25T15:55:34.004Z", "beat" => { "hostname" => "sensu-node-dev", "name" => "sensu-node-dev" }, "count" => 1, "fields" => nil, "input_type" => "log", "offset" => 29352, "source" => "/var/log/bunyan/myapp-info.log", "type" => "log", "host" => "sensu-node-dev", "tags" => ["beats_input_codec_plain_applied", "error"] }, "input_type"], "offset" => [{ "message" => "{\"name\":\"myapp\",\"hostname\":\"sensu-node-dev\",\"pid\":749,\"level\":50,\"err\":{\"message\":\"Cannot find module 'lol'\",\"name\":\"Error\",\"stack\":\"Error: Cannot find module 'lol'\\n at Function.Module._resolveFilename (module.js:339:15)\\n at Function.Module._load (module.js:290:25)\\n at Module.require (module.js:367:17)\\n at require (internal/module.js:16:19)\\n at Object.<anonymous> (/srv/www/dev.site/app.js:27:6)\\n at next (native)\\n at Object.<anonymous> (/srv/www/dev.site/node_modules/koa-compose/index.js:29:5)\\n at next (native)\\n at onFulfilled (/srv/www/dev.site/node_modules/co/index.js:65:19)\\n at /srv/www/dev.site/node_modules/co/index.js:54:5\",\"code\":\"MODULE_NOT_FOUND\"},\"msg\":\"Cannot find module 'lol'\",\"time\":\"2016-02-25T15:55:25.509Z\",\"v\":0}", "@version" => "1", "@timestamp" => "2016-02-25T15:55:34.004Z", "beat" => { "hostname" => "sensu-node-dev", "name" => "sensu-node-dev" }, "count" => 1, "fields" => nil, "input_type" => "log", "offset" => 29352, "source" => "/var/log/bunyan/myapp-info.log", "type" => "log", "host" => "sensu-node-dev", "tags" => ["beats_input_codec_plain_applied", "error"] }, "offset"], "source" => [{ "message" => "{\"name\":\"myapp\",\"hostname\":\"sensu-node-dev\",\"pid\":749,\"level\":50,\"err\":{\"message\":\"Cannot find module 'lol'\",\"name\":\"Error\",\"stack\":\"Error: Cannot find module 'lol'\\n at Function.Module._resolveFilename (module.js:339:15)\\n at Function.Module._load (module.js:290:25)\\n at Module.require (module.js:367:17)\\n at require (internal/module.js:16:19)\\n at Object.<anonymous> (/srv/www/dev.site/app.js:27:6)\\n at next (native)\\n at Object.<anonymous> (/srv/www/dev.site/node_modules/koa-compose/index.js:29:5)\\n at next (native)\\n at onFulfilled (/srv/www/dev.site/node_modules/co/index.js:65:19)\\n at /srv/www/dev.site/node_modules/co/index.js:54:5\",\"code\":\"MODULE_NOT_FOUND\"},\"msg\":\"Cannot find module 'lol'\",\"time\":\"2016-02-25T15:55:25.509Z\",\"v\":0}", "@version" => "1", "@timestamp" => "2016-02-25T15:55:34.004Z", "beat" => { "hostname" => "sensu-node-dev", "name" => "sensu-node-dev" }, "count" => 1, "fields" => nil, "input_type" => "log", "offset" => 29352, "source" => "/var/log/bunyan/myapp-info.log", "type" => "log", "host" => "sensu-node-dev", "tags" => ["beats_input_codec_plain_applied", "error"] }, "source"], "type" => [{ "message" => "{\"name\":\"myapp\",\"hostname\":\"sensu-node-dev\",\"pid\":749,\"level\":50,\"err\":{\"message\":\"Cannot find module 'lol'\",\"name\":\"Error\",\"stack\":\"Error: Cannot find module 'lol'\\n at Function.Module._resolveFilename (module.js:339:15)\\n at Function.Module._load (module.js:290:25)\\n at Module.require (module.js:367:17)\\n at require (internal/module.js:16:19)\\n at Object.<anonymous> (/srv/www/dev.site/app.js:27:6)\\n at next (native)\\n at Object.<anonymous> (/srv/www/dev.site/node_modules/koa-compose/index.js:29:5)\\n at next (native)\\n at onFulfilled (/srv/www/dev.site/node_modules/co/index.js:65:19)\\n at /srv/www/dev.site/node_modules/co/index.js:54:5\",\"code\":\"MODULE_NOT_FOUND\"},\"msg\":\"Cannot find module 'lol'\",\"time\":\"2016-02-25T15:55:25.509Z\",\"v\":0}", "@version" => "1", "@timestamp" => "2016-02-25T15:55:34.004Z", "beat" => { "hostname" => "sensu-node-dev", "name" => "sensu-node-dev" }, "count" => 1, "fields" => nil, "input_type" => "log", "offset" => 29352, "source" => "/var/log/bunyan/myapp-info.log", "type" => "log", "host" => "sensu-node-dev", "tags" => ["beats_input_codec_plain_applied", "error"] }, "type"], "[beat][hostname]" => [{ "hostname" => "sensu-node-dev", "name" => "sensu-node-dev" }, "hostname"], "host" => [{ "message" => "{\"name\":\"myapp\",\"hostname\":\"sensu-node-dev\",\"pid\":749,\"level\":50,\"err\":{\"message\":\"Cannot find module 'lol'\",\"name\":\"Error\",\"stack\":\"Error: Cannot find module 'lol'\\n at Function.Module._resolveFilename (module.js:339:15)\\n at Function.Module._load (module.js:290:25)\\n at Module.require (module.js:367:17)\\n at require (internal/module.js:16:19)\\n at Object.<anonymous> (/srv/www/dev.site/app.js:27:6)\\n at next (native)\\n at Object.<anonymous> (/srv/www/dev.site/node_modules/koa-compose/index.js:29:5)\\n at next (native)\\n at onFulfilled (/srv/www/dev.site/node_modules/co/index.js:65:19)\\n at /srv/www/dev.site/node_modules/co/index.js:54:5\",\"code\":\"MODULE_NOT_FOUND\"},\"msg\":\"Cannot find module 'lol'\",\"time\":\"2016-02-25T15:55:25.509Z\",\"v\":0}", "@version" => "1", "@timestamp" => "2016-02-25T15:55:34.004Z", "beat" => { "hostname" => "sensu-node-dev", "name" => "sensu-node-dev" }, "count" => 1, "fields" => nil, "input_type" => "log", "offset" => 29352, "source" => "/var/log/bunyan/myapp-info.log", "type" => "log", "host" => "sensu-node-dev", "tags" => ["beats_input_codec_plain_applied", "error"] }, "host"], "tags" => [{ "message" => "{\"name\":\"myapp\",\"hostname\":\"sensu-node-dev\",\"pid\":749,\"level\":50,\"err\":{\"message\":\"Cannot find module 'lol'\",\"name\":\"Error\",\"stack\":\"Error: Cannot find module 'lol'\\n at Function.Module._resolveFilename (module.js:339:15)\\n at Function.Module._load (module.js:290:25)\\n at Module.require (module.js:367:17)\\n at require (internal/module.js:16:19)\\n at Object.<anonymous> (/srv/www/dev.site/app.js:27:6)\\n at next (native)\\n at Object.<anonymous> (/srv/www/dev.site/node_modules/koa-compose/index.js:29:5)\\n at next (native)\\n at onFulfilled (/srv/www/dev.site/node_modules/co/index.js:65:19)\\n at /srv/www/dev.site/node_modules/co/index.js:54:5\",\"code\":\"MODULE_NOT_FOUND\"},\"msg\":\"Cannot find module 'lol'\",\"time\":\"2016-02-25T15:55:25.509Z\",\"v\":0}", "@version" => "1", "@timestamp" => "2016-02-25T15:55:34.004Z", "beat" => { "hostname" => "sensu-node-dev", "name" => "sensu-node-dev" }, "count" => 1, "fields" => nil, "input_type" => "log", "offset" => 29352, "source" => "/var/log/bunyan/myapp-info.log", "type" => "log", "host" => "sensu-node-dev", "tags" => ["beats_input_codec_plain_applied", "error"] }, "tags"], "message" => [{ "message" => "{\"name\":\"myapp\",\"hostname\":\"sensu-node-dev\",\"pid\":749,\"level\":50,\"err\":{\"message\":\"Cannot find module 'lol'\",\"name\":\"Error\",\"stack\":\"Error: Cannot find module 'lol'\\n at Function.Module._resolveFilename (module.js:339:15)\\n at Function.Module._load (module.js:290:25)\\n at Module.require (module.js:367:17)\\n at require (internal/module.js:16:19)\\n at Object.<anonymous> (/srv/www/dev.site/app.js:27:6)\\n at next (native)\\n at Object.<anonymous> (/srv/www/dev.site/node_modules/koa-compose/index.js:29:5)\\n at next (native)\\n at onFulfilled (/srv/www/dev.site/node_modules/co/index.js:65:19)\\n at /srv/www/dev.site/node_modules/co/index.js:54:5\",\"code\":\"MODULE_NOT_FOUND\"},\"msg\":\"Cannot find module 'lol'\",\"time\":\"2016-02-25T15:55:25.509Z\",\"v\":0}", "@version" => "1", "@timestamp" => "2016-02-25T15:55:34.004Z", "beat" => { "hostname" => "sensu-node-dev", "name" => "sensu-node-dev" }, "count" => 1, "fields" => nil, "input_type" => "log", "offset" => 29352, "source" => "/var/log/bunyan/myapp-info.log", "type" => "log", "host" => "sensu-node-dev", "tags" => ["beats_input_codec_plain_applied", "error"] }, "message"], "[tags]" => [{ "message" => "{\"name\":\"myapp\",\"hostname\":\"sensu-node-dev\",\"pid\":749,\"level\":50,\"err\":{\"message\":\"Cannot find module 'lol'\",\"name\":\"Error\",\"stack\":\"Error: Cannot find module 'lol'\\n at Function.Module._resolveFilename (module.js:339:15)\\n at Function.Module._load (module.js:290:25)\\n at Module.require (module.js:367:17)\\n at require (internal/module.js:16:19)\\n at Object.<anonymous> (/srv/www/dev.site/app.js:27:6)\\n at next (native)\\n at Object.<anonymous> (/srv/www/dev.site/node_modules/koa-compose/index.js:29:5)\\n at next (native)\\n at onFulfilled (/srv/www/dev.site/node_modules/co/index.js:65:19)\\n at /srv/www/dev.site/node_modules/co/index.js:54:5\",\"code\":\"MODULE_NOT_FOUND\"},\"msg\":\"Cannot find module 'lol'\",\"time\":\"2016-02-25T15:55:25.509Z\",\"v\":0}", "@version" => "1", "@timestamp" => "2016-02-25T15:55:34.004Z", "beat" => { "hostname" => "sensu-node-dev", "name" => "sensu-node-dev" }, "count" => 1, "fields" => nil, "input_type" => "log", "offset" => 29352, "source" => "/var/log/bunyan/myapp-info.log", "type" => "log", "host" => "sensu-node-dev", "tags" => ["beats_input_codec_plain_applied", "error"] }, "tags"] } > , @data = { "message" => "{\"name\":\"myapp\",\"hostname\":\"sensu-node-dev\",\"pid\":749,\"level\":50,\"err\":{\"message\":\"Cannot find module 'lol'\",\"name\":\"Error\",\"stack\":\"Error: Cannot find module 'lol'\\n at Function.Module._resolveFilename (module.js:339:15)\\n at Function.Module._load (module.js:290:25)\\n at Module.require (module.js:367:17)\\n at require (internal/module.js:16:19)\\n at Object.<anonymous> (/srv/www/dev.site/app.js:27:6)\\n at next (native)\\n at Object.<anonymous> (/srv/www/dev.site/node_modules/koa-compose/index.js:29:5)\\n at next (native)\\n at onFulfilled (/srv/www/dev.site/node_modules/co/index.js:65:19)\\n at /srv/www/dev.site/node_modules/co/index.js:54:5\",\"code\":\"MODULE_NOT_FOUND\"},\"msg\":\"Cannot find module 'lol'\",\"time\":\"2016-02-25T15:55:25.509Z\",\"v\":0}", "@version" => "1", "@timestamp" => "2016-02-25T15:55:34.004Z", "beat" => { "hostname" => "sensu-node-dev", "name" => "sensu-node-dev" }, "count" => 1, "fields" => nil, "input_type" => "log", "offset" => 29352, "source" => "/var/log/bunyan/myapp-info.log", "type" => "log", "host" => "sensu-node-dev", "tags" => ["beats_input_codec_plain_applied", "error"] }, @metadata_accessors = # < LogStash::Util::Accessors: 0x22cd112d@ store = { "beat" => "filebeat", "type" => "log" }, @lut = { "[type]" => [{ "beat" => "filebeat", "type" => "log" }, "type"], "[beat]" => [{ "beat" => "filebeat", "type" => "log" }, "beat"] } > , @cancelled = false > , : level => : error }
如您所見,它說明了
response_code => 500
內部錯誤。format => "json"
和都出現同樣的錯誤format => "message"
。我猜這與我的配置有關(顯然)。
顯然logstash 有雙引號問題,我很驚訝(也很失望)。這是工作程式碼:
if "error" in [tags] { http { http_method => "post" url => "https://hooks.slack.com/services/<MY_ID>" format => "message" message => '{"text":"hello"}' } }