I'm running a docker container with an ELK stack. Everythings working dandy and fine. I'd like to utilize the https://www.elastic.co/guide/en/logstash/current/plugins-outputs-http.html plugin.
I install the plugin it:
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
main logstash config file:
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\"}"
}
}
}
I've also tried changing the format in the http:
...
format => "message"
...
The configuration is also tested and is valid:
root@elk:/# /opt/logstash/bin/logstash --configtest -f /etc/logstash/conf.d/logstash.conf
Configuration OK
Both result in it not working. I double checked to make sure the webhook is working with a test (from the logstash docker container):
curl -H "Content-Type: application/json" -X POST -d '{"text":"testing"}' https://hooks.slack.com/services/<MY_ID>
I know tags are being applied properly, checked in Kibana. Also the if clause is also working as I tested putting elasticsearch
inside it and it indeed only sent logs with the added error
tags to elasticsearch.
Lastly the holy error message from /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
}
As you can see it states response_code => 500
internal error. I get the same error with both format => "json"
and format => "message"
.
I'm guessing it has something to do with my configuration (obviously).
Apparently logstash has issues with double quotes, I am surprised (and disappointed). Here is working code: