From 43fad48a4f9a506e077057d67c20f46fabdf5a94 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Tue, 7 Apr 2020 12:02:29 -0700 Subject: [PATCH] Added syslog support. --- meshcentral.js | 25 +++++++++++++++++++++++++ sample-config.json | 2 ++ views/default.handlebars | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/meshcentral.js b/meshcentral.js index e946d1af..4977ee21 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -574,6 +574,24 @@ function CreateMeshCentralServer(config, args) { //var wincmd = require('node-windows'); //wincmd.list(function (svc) { console.log(svc); }, true); + // Setup syslog support + if ((require('os').platform() != 'win32') && ((config.settings.syslog != null) || (config.settings.syslogjson != null))) { + if (config.settings.syslog === true) { config.settings.syslog = 'meshcentral'; } + if (config.settings.syslogjson === true) { config.settings.syslogjson = 'meshcentral-json'; } + if (typeof config.settings.syslog == 'string') { + obj.syslog = require('modern-syslog'); + console.log('Starting ' + config.settings.syslog + ' syslog.'); + obj.syslog.init(config.settings.syslog, obj.syslog.LOG_PID | obj.syslog.LOG_ODELAY, obj.syslog.LOG_LOCAL0); + obj.syslog.log(obj.syslog.LOG_INFO, "MeshCentral v" + getCurrentVerion() + " Server Start"); + } + if (typeof config.settings.syslogjson == 'string') { + obj.syslogjson = require('modern-syslog'); + console.log('Starting ' + config.settings.syslogjson + ' JSON syslog.'); + obj.syslogjson.init(config.settings.syslogjson, obj.syslogjson.LOG_PID | obj.syslogjson.LOG_ODELAY, obj.syslogjson.LOG_LOCAL0); + obj.syslogjson.log(obj.syslogjson.LOG_INFO, "MeshCentral v" + getCurrentVerion() + " Server Start"); + } + } + // Check top level configuration for any unreconized values if (config) { for (var i in config) { if ((typeof i == 'string') && (i.length > 0) && (i[0] != '_') && (['settings', 'domains', 'configfiles', 'smtp', 'letsencrypt', 'peers'].indexOf(i) == -1)) { addServerWarning('Unrecognized configuration option \"' + i + '\".'); } } } @@ -1475,6 +1493,10 @@ function CreateMeshCentralServer(config, args) { // If the database is not setup, exit now. if (!obj.db) return; + // Send event to syslog is needed + if (obj.syslog && event.msg) { obj.syslog.log(obj.syslog.LOG_INFO, event.msg); } + if (obj.syslogjson) { obj.syslog.log(obj.syslogjson.LOG_INFO, JSON.stringify(event)); } + obj.debug('dispatch', 'DispatchEvent', ids); if ((typeof event == 'object') && (!event.nolog)) { event.time = new Date(); @@ -2465,6 +2487,9 @@ function mainStart() { if (allsspi == false) { modules.push('otplib@10.2.3'); } // Google Authenticator support (v10 supports older NodeJS versions). } + // Syslog support + if ((require('os').platform() != 'win32') && (config.settings.syslog || config.settings.syslogjson)) { modules.push('modern-syslog'); } + // Setup heapdump support if needed, useful for memory leak debugging // https://www.arbazsiddiqui.me/a-practical-guide-to-memory-leaks-in-nodejs/ if (config.settings.heapdump === true) { modules.push('heapdump'); } diff --git a/sample-config.json b/sample-config.json index d332be09..e58648d7 100644 --- a/sample-config.json +++ b/sample-config.json @@ -56,6 +56,8 @@ "_MpsTlsOffload": true, "_No2FactorAuth": true, "_Log": "main,web,webrequest,cert", + "_syslog": true, + "_syslogjson": true, "_WebRtConfig": { "iceServers": [ { "urls": "stun:stun.services.mozilla.com" }, diff --git a/views/default.handlebars b/views/default.handlebars index d9b9389a..37d055d2 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -9115,7 +9115,7 @@ h = '
 ' + right + '
' + shortname + '
'; } else { var link = shortname, publiclink = ''; - if (publicfolder) { publiclink = ' '; } + if (publicfolder) { publiclink = ' '; } if (f.s > 0) { link = publiclink + ' ' + shortname + ''; } h = '
 ' + fdatestr + '' + fsize + '
' + link + '
'; }