Added TCP syslog support.
Ylian Saint-Hilaire committed
May 18, 2021 at 23:54 UTC
eb160fa583aad32c21c2d0b2f09ee56bbfabf3dd
3 files changed
+16
-1
meshcentral-config-schema.json
+1
@@ -151,6 +151,7 @@
151
"syslog": { "type": "string" },
152
"syslogauth": { "type": "string" },
153
"syslogjson": { "type": "string" },
154
+ "syslogtcp": { "type": "string", "default": null, "description": "Send syslog events over the network (RFC3164) to a target hostname:port. For example: localhost:514" },
155
"webrtcConfig": {
156
"type": "object",
157
"additionalProperties": false,
meshcentral.js
+14
-1
@@ -659,7 +659,7 @@ function CreateMeshCentralServer(config, args) {
659
//var wincmd = require('node-windows');
660
//wincmd.list(function (svc) { console.log(svc); }, true);
661
662
- // Setup syslog support
662
+ // Setup syslog support. Not supported on Windows.
663
if ((require('os').platform() != 'win32') && ((config.settings.syslog != null) || (config.settings.syslogjson != null) || (config.settings.syslogauth != null))) {
664
if (config.settings.syslog === true) { config.settings.syslog = 'meshcentral'; }
665
if (config.settings.syslogjson === true) { config.settings.syslogjson = 'meshcentral-json'; }
@@ -684,6 +684,17 @@ function CreateMeshCentralServer(config, args) {
684
obj.syslogauth.log(obj.syslogauth.LOG_INFO, "MeshCentral v" + getCurrentVersion() + " Server Start");
685
}
686
}
687
+ // Setup TCP syslog support, this works on all OS's.
688
+ if (config.settings.syslogtcp != null) {
689
+ const syslog = require('syslog');
690
+ if (config.settings.syslogtcp === true) {
691
+ obj.syslogtcp = syslog.createClient(514, 'localhost');
692
+ } else {
693
+ const sp = config.settings.syslogtcp.split(':');
694
+ obj.syslogtcp = syslog.createClient(parseInt(sp[1]), sp[0]);
695
+ }
696
+ obj.syslogtcp.log("MeshCentral v" + getCurrentVersion() + " Server Start", obj.syslogtcp.LOG_INFO);
697
+ }
698
699
// Check top level configuration for any unreconized values
700
if (config) { for (var i in config) { if ((typeof i == 'string') && (i.length > 0) && (i[0] != '_') && (['settings', 'domaindefaults', 'domains', 'configfiles', 'smtp', 'letsencrypt', 'peers', 'sms', 'sendgrid', 'firebase', 'firebaserelay', '$schema'].indexOf(i) == -1)) { addServerWarning('Unrecognized configuration option \"' + i + '\".'); } } }
@@ -1945,6 +1956,7 @@ function CreateMeshCentralServer(config, args) {
1956
// Send event to syslog if needed
1957
if (obj.syslog && event.msg) { obj.syslog.log(obj.syslog.LOG_INFO, event.msg); }
1958
if (obj.syslogjson) { obj.syslogjson.log(obj.syslogjson.LOG_INFO, JSON.stringify(event)); }
1959
+ if (obj.syslogtcp && event.msg) { obj.syslogtcp.log(event.msg, obj.syslogtcp.LOG_INFO); }
1960
1961
obj.debug('dispatch', 'DispatchEvent', ids);
1962
if ((typeof event == 'object') && (!event.nolog)) {
@@ -3229,6 +3241,7 @@ function mainStart() {
3241
3242
// Syslog support
3243
if ((require('os').platform() != 'win32') && (config.settings.syslog || config.settings.syslogjson)) { modules.push('modern-syslog'); }
3244
+ if (config.settings.syslogtcp) { modules.push('syslog'); }
3245
3246
// Setup heapdump support if needed, useful for memory leak debugging
3247
// https://www.arbazsiddiqui.me/a-practical-guide-to-memory-leaks-in-nodejs/
sample-config-advanced.json
+1
@@ -77,6 +77,7 @@
77
"_syslog": "meshcentral",
78
"_syslogauth": "meshcentral-auth",
79
"_syslogjson": "meshcentral-json",
80
+ "_syslogtcp": "localhost:514",
81
"_webrtcConfig": {
82
"iceServers": [
83
{ "urls": "stun:stun.services.mozilla.com" },