fluent-bit icon indicating copy to clipboard operation
fluent-bit copied to clipboard

Add Logstash output plugin

Open kfox1111 opened this issue 9 years ago • 28 comments

Some sites already have a logstash daemon running and don't have direct access to elasticsearch. It would be nice if you could still use fluent-bit in this environment and push logs to logstash.

kfox1111 avatar Jun 20 '17 21:06 kfox1111

It probably can be wired together by using Fluent Bit HTTP Output Plugin and Logstash HTTP Input Plugin. There is even support for MessagePack in Logstash.

wkruse avatar Oct 04 '17 08:10 wkruse

Related to #352.

wkruse avatar Oct 04 '17 08:10 wkruse

@kfox1111 @wkruse would you please point me to the logstash HTTP input spec ?, meaning "how the HTTP payload" needs to be formatted ? (I could not find the info)

edsiper avatar Oct 04 '17 17:10 edsiper

I haven't used the HTTP input plugin, but based on other plugins, and whats in the docs, I think the http input plugin is just a transport .I can be paired up with a codec plugin, (defaults to their json one), which I think is documented here: https://www.elastic.co/guide/en/logstash/current/plugins-codecs-json.html Though for continuous streams, the multiline one might be better.

Based on this page though: http://brewhouse.io/blog/2014/11/04/big-data-with-elk-stack.html

It really looks like it just takes json data and passes it along. one document per log entry and the content can be literally anything. It doens't appear to do any processing of the data out of the box, so the schema's probably not important.

kfox1111 avatar Oct 04 '17 17:10 kfox1111

So for logs to be forwarded to logstash server from fluentBit need to use this?

viveksamaga avatar Feb 01 '18 07:02 viveksamaga

@wkruse @edsiper @kfox1111 @viveksamaga Now I'm searching solutions for sending logs with fluent bit and save it with logstash How about using Fluent Bit Forward Output Plugin and Logstash TCP Input Plugin rathar than HTTP Input and Output Plugins?

sicriops avatar Feb 07 '18 09:02 sicriops

@sicriops did you managed to configure that?

iusergii avatar May 02 '18 15:05 iusergii

I tried fluent-bit with the fluent plugin for Logstash, that doesn't work. I was hoping to just use logstash as my aggregator now I'll have to deploy fluentd for that.

trevorndodds avatar Jul 26 '18 15:07 trevorndodds

I just tested @wkruse 's proposal about forward output and TCP input with Fluent codec and didn't work.

This worked for me:

  • fluentbit output configuration:
[OUTPUT]
    Name          http
    Match         *
    Host          logstash
    Port          12345
    Format        json
  • logstash input configuration:
input {
  http {
    port => 12345
  }
}

As fluentbit sends a correct content_type header, Logstash interprets it and treats information correctly.

Tested also with msgpack, but didn't work. It raised me the following error:

logstash_1   | [2018-08-22T10:06:40,031][ERROR][logstash.inputs.http     ] unable to process event. {:request=>{"request_method"=>"POST", "request_path"=>"/", "request_uri"=>"/", "http_version"=>"HTTP/1.1", "http_host"=>"logstash:12345", "content_length"=>"168", "content_type"=>"application/msgpack"}, :message=>"undefined method `set' for nil:NilClass\nDid you mean?  send", :class=>"NoMethodError", :backtrace=>["/usr/share/logstash/vendor/bundle/jruby/2.3.0/gems/logstash-codec-msgpack-3.0.7-java/lib/logstash/codecs/msgpack.rb:36:in `decode'", "/usr/share/logstash/vendor/bundle/jruby/2.3.0/gems/logstash-input-http-3.0.10/lib/logstash/inputs/http.rb:157:in `block in run'", "/usr/share/logstash/vendor/bundle/jruby/2.3.0/gems/logstash-input-http-3.0.10/lib/logstash/util/http_compressed_requests.rb:27:in `call'", "/usr/share/logstash/vendor/bundle/jruby/2.3.0/gems/rack-1.6.6/lib/rack/builder.rb:153:in `call'", "/usr/share/logstash/vendor/bundle/jruby/2.3.0/gems/puma-2.16.0-java/lib/puma/server.rb:557:in `handle_request'", "/usr/share/logstash/vendor/bundle/jruby/2.3.0/gems/puma-2.16.0-java/lib/puma/server.rb:404:in `process_client'", "/usr/share/logstash/vendor/bundle/jruby/2.3.0/gems/puma-2.16.0-java/lib/puma/server.rb:270:in `block in run'", "/usr/share/logstash/vendor/bundle/jruby/2.3.0/gems/puma-2.16.0-java/lib/puma/thread_pool.rb:106:in `block in spawn_thread'"]}

Versions used:

  • Fluentbit: 0.13.8
  • Logstash: 6.3.2

mpucholblasco avatar Aug 22 '18 12:08 mpucholblasco

Backing to the original requirement, maybe @kfox1111 was thinking on sending information from fluentbit to a logstash using beats input.

mpucholblasco avatar Aug 22 '18 12:08 mpucholblasco

I am not familiar with Logstash but per my understanding HTTP Output in JSON should be enough

edsiper avatar Aug 22 '18 13:08 edsiper

Yes, it could be. You can even add more security by enabling HTTP auth & SSL via:

  • logstash pipeline example:
input {
  http {
    port => 12345
    ssl => true
    user => "log"
    password => "js5CsB3MP43gnS9J"
    keystore => "/usr/share/logstash/config/keystore.jks"
    keystore_password => "123pass"
    add_field    => { "[@metadata][http-input]" => "" }
  }
}

filter {
  if [@metadata][http-input] {
    mutate {
      remove_field => ["headers"]
    }
  }
}

output {
  stdout {
    codec => rubydebug
  }
}
  • keystore file generated via: keytool -genkey -keyalg RSA -alias mycert -keystore keystore.jks -storepass 123pass -validity 360 -keysize 2048
  • fluentbit configuration:
[OUTPUT]
    Name          http
    Match         *
    Host          logstash
    Port          12345
    Format        json
    HTTP_User     log
    HTTP_Passwd   js5CsB3MP43gnS9J
    tls           On
    tls.verify    Off

Maybe this is enough for @kfox1111 .

mpucholblasco avatar Aug 22 '18 13:08 mpucholblasco

Interesting. I'll have to give that a try. Thanks. :)

kfox1111 avatar Aug 22 '18 16:08 kfox1111

btw, anyone interested into write a simple HowTo/article in Markdown ?

edsiper avatar Aug 22 '18 16:08 edsiper

I can do it. Not sure about where because this is not an output as it, but I will do a PR on https://github.com/fluent/fluent-bit-docs about this information and we can discuss it there.

mpucholblasco avatar Aug 22 '18 16:08 mpucholblasco

@mpucholblasco thanks, for now please point me to a gist because I will publish a new tutorials section (different git repo)

edsiper avatar Aug 22 '18 16:08 edsiper

Thanks, using http works. I just need to look at flattening the MESSAGE json into further fields.

trevorndodds avatar Aug 23 '18 20:08 trevorndodds

Hello @edsiper , I left a gist page here: https://gist.github.com/mpucholblasco/b115a81af8832236b1be04d71146f2fe

Tell me if you need anything else.

mpucholblasco avatar Aug 26 '18 09:08 mpucholblasco

@trevorndodds , records sent to the Logstash input are json events. This MESSAGE field is sent by fluent-bit, so you have to flatten it on fluent-bit (via parsers, suppose)

mpucholblasco avatar Aug 26 '18 09:08 mpucholblasco

@mpucholblasco thanks for the contribution! I will push the articles repo shortly.

edsiper avatar Sep 12 '18 18:09 edsiper