splunk / splunk-javascript-logging

Splunk HTTP Event Collector logging interface for JavaScript
http://dev.splunk.com/view/splunk-logging-javascript/SP-CAAAE63
Apache License 2.0
85 stars 47 forks source link

Getting ECONNRESET Error: socket hang up error #75

Open alok2k5ingh opened 2 years ago

alok2k5ingh commented 2 years ago

Trying to implement the same example as mentioned in the README file but getting the error: ECONNRESET Error: socket hang up error

Have checkup the token and splunk HEC endpoint, it's working. Can someone please help

Tried on: Node version: v14.17.6

"dependencies": { "splunk-logging": "^0.11.1" }

dkoloditch commented 2 years ago

+1

dkoloditch commented 2 years ago

@alok2k5ingh Here's an alternate solution using the axios library:

const axios = require('axios');

const splunkCollectorUrl = 'https://<yoursubdomain>.splunkcloud.com/services/collector/event'
const context = {
  event: {
    message: 'hello world'
  },
  sourcetype: 'manual'
};
const axiosOptions = {
  url: splunkCollectorUrl,
  method: 'POST',
  data: context,
  headers: {
    'Authorization': `Splunk ${splunkToken}`
  }
}

axios(axiosOptions);
bmccleave commented 2 years ago

I've hit this issue when attempting publish to splunkcloud as well. I found the removing the port from the url here https://github.com/splunk/splunk-javascript-logging/blob/c3795abc5a9fe7f81a9e10c4df46d72f360bb8ca/splunklogger.js#L440 fixes it.

Here is the current line:

requestOptions.url = this.config.protocol + "://" + this.config.host + ":" + this.config.port + this.config.path;

Changing it to this resolved the issue for me:

requestOptions.url = this.config.protocol + "://" + this.config.host + this.config.path;

This is just a hack. Ideally there would be a configuration option to allow the URL to be explicitly passed without a port

serdalis commented 2 years ago

This issue is because the library is pulling the URL apart and looking for the pieces it needs to reconstruct it when making a request.

The problem is, if it doesn't find a piece it will replace it with the default value. In this case, the default port is 8088. Changing the url to (note the 443 port):

const splunkCollectorUrl = 'https://<yoursubdomain>.splunkcloud.com:443/services/collector/event'

will fix the issue you're having.

The problem is from these lines:

https://github.com/splunk/splunk-javascript-logging/blob/c3795abc5a9fe7f81a9e10c4df46d72f360bb8ca/splunklogger.js#L235 https://github.com/splunk/splunk-javascript-logging/blob/c3795abc5a9fe7f81a9e10c4df46d72f360bb8ca/splunklogger.js#L257