Added syslog support.
Ylian Saint-Hilaire committed
Apr 7, 2020 at 12:02 UTC
8a976f577e6b337e0d80edef53b52a85babb1105
3 files changed
+28
-1
meshcentral.js
+25
@@ -574,6 +574,24 @@ function CreateMeshCentralServer(config, args) {
574
//var wincmd = require('node-windows');
575
//wincmd.list(function (svc) { console.log(svc); }, true);
576
577
+ // Setup syslog support
578
+ if ((require('os').platform() != 'win32') && ((config.settings.syslog != null) || (config.settings.syslogjson != null))) {
579
+ if (config.settings.syslog === true) { config.settings.syslog = 'meshcentral'; }
580
+ if (config.settings.syslogjson === true) { config.settings.syslogjson = 'meshcentral-json'; }
581
+ if (typeof config.settings.syslog == 'string') {
582
+ obj.syslog = require('modern-syslog');
583
+ console.log('Starting ' + config.settings.syslog + ' syslog.');
584
+ obj.syslog.init(config.settings.syslog, obj.syslog.LOG_PID | obj.syslog.LOG_ODELAY, obj.syslog.LOG_LOCAL0);
585
+ obj.syslog.log(obj.syslog.LOG_INFO, "MeshCentral v" + getCurrentVerion() + " Server Start");
586
+ }
587
+ if (typeof config.settings.syslogjson == 'string') {
588
+ obj.syslogjson = require('modern-syslog');
589
+ console.log('Starting ' + config.settings.syslogjson + ' JSON syslog.');
590
+ obj.syslogjson.init(config.settings.syslogjson, obj.syslogjson.LOG_PID | obj.syslogjson.LOG_ODELAY, obj.syslogjson.LOG_LOCAL0);
591
+ obj.syslogjson.log(obj.syslogjson.LOG_INFO, "MeshCentral v" + getCurrentVerion() + " Server Start");
592
+ }
593
+ }
594
+
595
// Check top level configuration for any unreconized values
596
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 + '\".'); } } }
597
@@ -1475,6 +1493,10 @@ function CreateMeshCentralServer(config, args) {
1493
// If the database is not setup, exit now.
1494
if (!obj.db) return;
1495
1496
+ // Send event to syslog is needed
1497
+ if (obj.syslog && event.msg) { obj.syslog.log(obj.syslog.LOG_INFO, event.msg); }
1498
+ if (obj.syslogjson) { obj.syslog.log(obj.syslogjson.LOG_INFO, JSON.stringify(event)); }
1499
+
1500
obj.debug('dispatch', 'DispatchEvent', ids);
1501
if ((typeof event == 'object') && (!event.nolog)) {
1502
event.time = new Date();
@@ -2465,6 +2487,9 @@ function mainStart() {
2487
if (allsspi == false) { modules.push('otplib@10.2.3'); } // Google Authenticator support (v10 supports older NodeJS versions).
2488
}
2489
2490
+ // Syslog support
2491
+ if ((require('os').platform() != 'win32') && (config.settings.syslog || config.settings.syslogjson)) { modules.push('modern-syslog'); }
2492
+
2493
// Setup heapdump support if needed, useful for memory leak debugging
2494
// https://www.arbazsiddiqui.me/a-practical-guide-to-memory-leaks-in-nodejs/
2495
if (config.settings.heapdump === true) { modules.push('heapdump'); }
sample-config.json
+2
@@ -56,6 +56,8 @@
56
"_MpsTlsOffload": true,
57
"_No2FactorAuth": true,
58
"_Log": "main,web,webrequest,cert",
59
+ "_syslog": true,
60
+ "_syslogjson": true,
61
"_WebRtConfig": {
62
"iceServers": [
63
{ "urls": "stun:stun.services.mozilla.com" },
views/default.handlebars
+1
-1
@@ -9115,7 +9115,7 @@
9115
h = '<div class=filelist file=999><input file=999 style=float:left name=fc class=fcb type=checkbox onchange=p5setActions() value="' + name + '"> <span style=float:right title=\"' + title + '\">' + right + '</span><span><div class=fileIcon' + f.t + ' onclick=p5folderset(\"' + encodeURIComponent(f.nx) + '\")></div><a href=# style=cursor:pointer onclick=\'return p5folderset(\"' + encodeURIComponent(f.nx) + '\")\'>' + shortname + '</a></span></div>';
9116
} else {
9117
var link = shortname, publiclink = '';
9118
- if (publicfolder) { publiclink = '<img src="images/link2.png" style=cursor:pointer title="' + "Display public link" + '" onclick=\'return p5showPublicLink("' + (publicPath + '/' + encodeURIComponent(f.nx)) + '")\' width=10 height=10 /> <img src="images/link4.png" title="' + "Copy link to clipboard" + '" style="cursor:pointer" onclick=copyTextToClip2(\"' + encodeURIComponent(publicPath + '/' + encodeURIComponent(f.nx)) + '\") width=10 height=10>'; }
9118
+ if (publicfolder) { publiclink = '<img src="images/link2.png" style=cursor:pointer title="' + "Display public link" + '" onclick=\'return p5showPublicLink("' + (publicPath + '/' + encodeURIComponent(f.nx)) + '?download=1' + '")\' width=10 height=10 /> <img src="images/link4.png" title="' + "Copy link to clipboard" + '" style="cursor:pointer" onclick=copyTextToClip2(\"' + encodeURIComponent(publicPath + '/' + encodeURIComponent(f.nx) + '?download=1') + '\") width=10 height=10>'; }
9119
if (f.s > 0) { link = publiclink + ' <a rel="noreferrer noopener" target="_blank" download href="downloadfile.ashx?link=' + encodeURIComponent(filetreelinkpath + '/' + f.nx) + '">' + shortname + '</a>'; }
9120
h = '<div class=filelist file=3><input file=3 style=float:left name=fc class=fcb type=checkbox onchange=p5setActions() value="' + f.nx + '"> <span class=fsize>' + fdatestr + '</span><span style=float:right>' + fsize + '</span><span><div class=fileIcon' + f.t + '></div>' + link + '</span></div>';
9121
}