From 3ec3914b22646443d006be0e5ec71dcdfe83689d Mon Sep 17 00:00:00 2001 From: Dominik Sigmund <dominik.sigmund@br.de> Date: Fri, 8 May 2020 11:14:28 +0200 Subject: [PATCH] Switch to Graylog HTTPS --- index.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 5ca8d8b..4ca538e 100644 --- a/index.js +++ b/index.js @@ -25,8 +25,7 @@ function Log (options) { this.hostname = os.hostname() } if (this.options.graylog && this.options.graylog.active) { - this.udp = require('dgram') - this.udpclient = this.udp.createSocket('udp4') + this.https = require('https') } if (this.options.file) { this.fs = require('fs') @@ -120,18 +119,26 @@ function Log (options) { }) } if (this.options.graylog && this.options.graylog.active) { - let buffed = Buffer.from(JSON.stringify({ + let data = JSON.stringify({ short_message: msg, timestamp: Date.now() / 1000, hostname: this.hostname, facility: this.name, level: tag - })) - this.udpclient.send(buffed, 0, buffed.length, this.options.graylog.port, this.options.graylog.server, (error) => { - if (error) { - console.error(error) + }) + let options = { + hostname: this.options.graylog.server, + port: this.options.graylog.port, + path: '/gelf', + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Content-Length': data.length + } } - }) + var post = this.https.request(options) + post.write(data) + post.end() } return msg } -- GitLab