internetitem / logback-elasticsearch-appender

Logback Elasticsearch Appender
Other
233 stars 137 forks source link

Connecting to protected https server with user name and password #6

Open maksimu opened 8 years ago

maksimu commented 8 years ago

Is it possible to connect to the protected ElastciSearch server that is on https and has user name and password?

The reason why I asked this questions is because I got the following error:

2016-02-08 09:10:51.220 ERROR 7 --- [   es-writer-28] es-error-logger                          : Failed to send events to Elasticsearch: Got response code [401] from server with data <html>
<head><title>401 Authorization Required</title></head>
<body bgcolor="white">
<center><h1>401 Authorization Required</h1></center>
<hr><center>nginx/1.8.0</center>
</body>
</html>

java.io.IOException: Got response code [401] from server with data <html>
<head><title>401 Authorization Required</title></head>
<body bgcolor="white">
<center><h1>401 Authorization Required</h1></center>
<hr><center>nginx/1.8.0</center>
</body>
</html>

     at com.internetitem.logback.elasticsearch.writer.ElasticsearchWriter.sendData(ElasticsearchWriter.java:60) ~[logback-elasticsearch-appender-1.2.jar!/:na]
     at com.internetitem.logback.elasticsearch.ElasticsearchOutputAggregator.sendData(ElasticsearchOutputAggregator.java:53) ~[logback-elasticsearch-appender-1.2.jar!/:na]
     at com.internetitem.logback.elasticsearch.AbstractElasticsearchPublisher.run(AbstractElasticsearchPublisher.java:140) [logback-elasticsearch-appender-1.2.jar!/:na]
     at java.lang.Thread.run(Thread.java:745) [na:1.8.0_45]

There is what I had in logback.xml file

    <appender name="ELASTIC_PROD_LOGS_APPENDER" class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
        <url>https://user:password@db-elastsear.com:25370/_bulk</url>
        <index>prod-logs-%date{yyyy-MM-dd}</index>
        <type>tester</type>
        ...
maksimu commented 8 years ago

I have added ability for this library to push to elastcisearch under ssl and with basic authentication The SSL party is kind of hacky as it ignores any SSL validation. That's sufficient for me. Here are my changes:

https://github.com/maksimu/logback-elasticsearch-appender/commit/073b977a572dc339d58d106ee62a86c59085e862

abatkin commented 8 years ago

I'd be happy to take a look at a patch enabling HTTP Basic Authentication

ghost commented 8 years ago

Hi Adam,

Will this fix be deployed as a new version on the maven repository ? I guess in the 1.3

Best regards, david

ghost commented 8 years ago

Hi maksimu,

Could you add a submission of your fix to allow it to be quickly integrated into the next release ?

Best regards, david

maksimu commented 8 years ago

hi @infodavidgit

Just sent pull request https://github.com/internetitem/logback-elasticsearch-appender/pull/10

ghost commented 8 years ago

Priviet Maksim,

Thanks

ghost commented 8 years ago

Hi All,

Perhaps it could be nice to have user / password authentication working with HTTP too.

Best regards, david

maksimu commented 8 years ago

good point! Let me move around few lines :)

ghost commented 8 years ago

Thanks.

Adam suggested to submit 2 requests, one for authentication and the other for SSL with the two behaviors: Trust all (as implemented in your code) and with validation.