I want to use Jenkins-Logstash plugin to send Jenkins logs to Logstash.
This is how I configured Logstash plugin in Jenkins:
[jenkins-logstash-plugin configuration][1] [1]: https://i.stack.imgur.com/EsIgY.png
I assume in logstash.conf I have to use HTTP plugin in input section:
input {
http {
host => "127.0.0.1"
port => 31311
}
}
But in Jenkins build logs I can see the error:
> [logstash-plugin]: Failed to send log data to
> ELASTICSEARCH:http://host_name:31311. [logstash-plugin]: No Further
> logs will be sent to http://host_name:31311.
> org.apache.http.conn.HttpHostConnectException: Connect to
> host_name:31311 [/host_name] failed: Connection refused (Connection
> refused) at
> org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:151)
> at
> org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
> ...
> Caused by: java.net.ConnectException: Connection refused
> (Connection refused) at java.net.PlainSocketImpl.socketConnect(Native
> Method) at
> java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
And the error is gone when I change port number in Jenkins config to Elasticsearch port 9200 instead of 31311. But in this case data is written directly to Elasticsearch.
How can I set Jenkins to send build logs to Logstash?
Update: I am able to send and get logs in Logstash now, everything works good. But in Jenkins console I can see the error when sending logs to Logstash, is it acceptable?
20:54:11 [logstash-plugin]: Failed to send log data to ELASTICSEARCH:host_name:31311.
20:54:11 [logstash-plugin]: No Further logs will be sent to host_name:31311.
20:54:11 java.io.IOException: HTTP error code: 200
20:54:11 URI: host_name:31311/jenkins-qa/type
20:54:11 RESPONSE: HttpResponseProxy{HTTP/1.1 200 OK [Content-Type: text/plain, Content-Length: 2] ResponseEntityProxy{[Content-Type: text/plain,Content-Length: 2,Chunked: false]}}
20:54:11 ok
20:54:11 at jenkins.plugins.logstash.persistence.ElasticSearchDao.push(ElasticSearchDao.java:113)
20:54:11 at jenkins.plugins.logstash.LogstashWriter.write(LogstashWriter.java:147)
20:54:11 at jenkins.plugins.logstash.LogstashWriter.writeBuildLog(LogstashWriter.java:116)
20:54:11 at jenkins.plugins.logstash.LogstashNotifier.perform(LogstashNotifier.java:63)
20:54:11 at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
20:54:11 at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
20:54:11 at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:720)
20:54:11 at hudson.model.Build$BuildExecution.post2(Build.java:186)
20:54:11 at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:665)
20:54:11 at hudson.model.Run.execute(Run.java:1753)
20:54:11 at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
20:54:11 at hudson.model.ResourceController.execute(ResourceController.java:98)
20:54:11 at hudson.model.Executor.run(Executor.java:405)
20:54:11 Finished: SUCCESS