How to use logstash plugin - logstash-input-http

拟墨画扇 提交于 2020-07-18 11:44:22

问题


I am exploring Logstash to receive inputs on HTTP. I have installed http plugin using:

plugin install logstash-input-http

The installation was successfull. Then I tried to run logstash using following command:

logstash -e 'input {http {port => 8900}} output {stdout{codec => rubydebug}}'

But logstash terminates without giving any error as such.

Don't know how to verify whether plugin is installed correctly or not. And how to utilize the http plugin to test a sample request.

Thanks in Advance!


回答1:


I was able to solve the problem by using the .conf file instead of command line arguments.

I created a http-pipeline.conf file similar to below:

input {
 http {
    host => "0.0.0.0"
    port => "8080"
  }
}

output {
    stdout {}
}

And then executed Logstash like:

logstash -f http-pipeline.conf

Using a POSTMAN tool, I sent a POST request(http://localhost:8080) to Logstash with a sample string and voila it appeared on the Logstash console.




回答2:


If you are executing from the same domain following will be sufficient.

input {
    http {
    port => 5043
  }
}
output {
    file {
        path => "/log_streaming/my_app/app.log"
    }
}

If you want to executing a request on a different domain of the website then you need to set few response headers

input {
    http {
    port => 5043
    response_headers => {
      "Access-Control-Allow-Origin" => "*"
      "Content-Type" => "text/plain"
      "Access-Control-Allow-Headers" => "Origin, X-Requested-With, Content-Type, 
       Accept"
    }
  }
}
output {
    file {
       path => "/log_streaming/my_app/app.log"
    }
}


来源:https://stackoverflow.com/questions/37434739/how-to-use-logstash-plugin-logstash-input-http

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!