Skip to content

Commit

Permalink
Added TCP syslog support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ylianst committed May 19, 2021
1 parent c63344e commit eb160fa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions meshcentral-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
"syslog": { "type": "string" },
"syslogauth": { "type": "string" },
"syslogjson": { "type": "string" },
"syslogtcp": { "type": "string", "default": null, "description": "Send syslog events over the network (RFC3164) to a target hostname:port. For example: localhost:514" },
"webrtcConfig": {
"type": "object",
"additionalProperties": false,
Expand Down
15 changes: 14 additions & 1 deletion meshcentral.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ function CreateMeshCentralServer(config, args) {
//var wincmd = require('node-windows');
//wincmd.list(function (svc) { console.log(svc); }, true);

// Setup syslog support
// Setup syslog support. Not supported on Windows.
if ((require('os').platform() != 'win32') && ((config.settings.syslog != null) || (config.settings.syslogjson != null) || (config.settings.syslogauth != null))) {
if (config.settings.syslog === true) { config.settings.syslog = 'meshcentral'; }
if (config.settings.syslogjson === true) { config.settings.syslogjson = 'meshcentral-json'; }
Expand All @@ -684,6 +684,17 @@ function CreateMeshCentralServer(config, args) {
obj.syslogauth.log(obj.syslogauth.LOG_INFO, "MeshCentral v" + getCurrentVersion() + " Server Start");
}
}
// Setup TCP syslog support, this works on all OS's.
if (config.settings.syslogtcp != null) {
const syslog = require('syslog');
if (config.settings.syslogtcp === true) {
obj.syslogtcp = syslog.createClient(514, 'localhost');
} else {
const sp = config.settings.syslogtcp.split(':');
obj.syslogtcp = syslog.createClient(parseInt(sp[1]), sp[0]);
}
obj.syslogtcp.log("MeshCentral v" + getCurrentVersion() + " Server Start", obj.syslogtcp.LOG_INFO);
}

// 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', 'domaindefaults', 'domains', 'configfiles', 'smtp', 'letsencrypt', 'peers', 'sms', 'sendgrid', 'firebase', 'firebaserelay', '$schema'].indexOf(i) == -1)) { addServerWarning('Unrecognized configuration option \"' + i + '\".'); } } }
Expand Down Expand Up @@ -1945,6 +1956,7 @@ function CreateMeshCentralServer(config, args) {
// Send event to syslog if needed
if (obj.syslog && event.msg) { obj.syslog.log(obj.syslog.LOG_INFO, event.msg); }
if (obj.syslogjson) { obj.syslogjson.log(obj.syslogjson.LOG_INFO, JSON.stringify(event)); }
if (obj.syslogtcp && event.msg) { obj.syslogtcp.log(event.msg, obj.syslogtcp.LOG_INFO); }

obj.debug('dispatch', 'DispatchEvent', ids);
if ((typeof event == 'object') && (!event.nolog)) {
Expand Down Expand Up @@ -3229,6 +3241,7 @@ function mainStart() {

// Syslog support
if ((require('os').platform() != 'win32') && (config.settings.syslog || config.settings.syslogjson)) { modules.push('modern-syslog'); }
if (config.settings.syslogtcp) { modules.push('syslog'); }

// Setup heapdump support if needed, useful for memory leak debugging
// https://www.arbazsiddiqui.me/a-practical-guide-to-memory-leaks-in-nodejs/
Expand Down
1 change: 1 addition & 0 deletions sample-config-advanced.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"_syslog": "meshcentral",
"_syslogauth": "meshcentral-auth",
"_syslogjson": "meshcentral-json",
"_syslogtcp": "localhost:514",
"_webrtcConfig": {
"iceServers": [
{ "urls": "stun:stun.services.mozilla.com" },
Expand Down

0 comments on commit eb160fa

Please sign in to comment.