Skip to content

Commit

Permalink
Merge pull request #809 from mountaindude/803
Browse files Browse the repository at this point in the history
803
  • Loading branch information
mountaindude authored Jun 3, 2024
2 parents e8ff622 + 97e5faa commit 75e1561
Show file tree
Hide file tree
Showing 23 changed files with 2,040 additions and 1,349 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ Adapt to your needs - please also consider sharing enhancements with the wider c
\
**Documentation is available at [https://butler-sos.ptarmiganlabs.com](https://butler-sos.ptarmiganlabs.com).**
\
Commercial getting-started services for Butler SOS are available, more info [here](https://ptarmiganlabs.com/butler-assist/).
Commercial getting-started services for Butler SOS are available, more info [here](https://ptarmiganlabs.com/services/).
340 changes: 180 additions & 160 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 13 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,41 @@
"homepage": "https://github.com/ptarmiganlabs/butler-sos#readme",
"dependencies": {
"@breejs/later": "^4.2.0",
"axios": "^1.6.8",
"commander": "^12.0.0",
"@influxdata/influxdb-client": "^1.33.2",
"@influxdata/influxdb-client-apis": "^1.33.2",
"axios": "^1.7.2",
"commander": "^12.1.0",
"config": "^3.3.11",
"esbuild": "^0.20.2",
"esbuild": "^0.21.4",
"eslint": "^8.56.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"fastify": "^4.26.2",
"fastify": "^4.27.0",
"fastify-healthcheck": "^4.4.0",
"fastify-metrics": "^11.0.0",
"fs-extra": "^11.2.0",
"influx": "^5.9.3",
"js-yaml": "^4.1.0",
"lodash.clonedeep": "^4.5.0",
"luxon": "^3.4.4",
"mqtt": "^5.5.0",
"mqtt": "^5.7.0",
"pg": "^8.11.5",
"posthog-node": "^4.0.0",
"prom-client": "^15.1.1",
"posthog-node": "^4.0.1",
"prom-client": "^15.1.2",
"qrs-interact": "^6.3.1",
"systeminformation": "^5.22.7",
"ua-parser-js": "^1.0.37",
"systeminformation": "^5.22.10",
"ua-parser-js": "^1.0.38",
"uuid": "^9.0.1",
"winston": "^3.13.0",
"winston-daily-rotate-file": "^5.0.0",
"yaml-validator": "^5.0.1"
},
"devDependencies": {
"eslint-formatter-table": "^7.32.1",
"prettier": "^3.2.5",
"snyk": "^1.1287.0"
"prettier": "^3.3.0",
"snyk": "^1.1291.1"
},
"pkg": {
"assets": [
Expand Down
126 changes: 53 additions & 73 deletions src/butler-sos.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,31 @@ process.emit = function (name, data, ...args) {
return originalEmit.apply(process, arguments);
};

globals.initInfluxDB();

if (
(globals.config.has('Butler-SOS.uptimeMonitor.enabled') &&
globals.config.get('Butler-SOS.uptimeMonitor.enabled') === true) ||
(globals.config.has('Butler-SOS.uptimeMonitor.enable') &&
globals.config.get('Butler-SOS.uptimeMonitor.enable') === true)
) {
serviceUptime.serviceUptimeStart();
async function sleep(ms) {
// eslint-disable-next-line no-promise-executor-return
return new Promise((resolve) => setTimeout(resolve, ms));
}

async function mainScript() {
// Sleep 5 seconds to allow inits to complete
globals.logger.info('MAIN: Waiting 5 seconds for initializations to complete...');
globals.logger.info('5...');
await sleep(1000);
globals.logger.info('4...');
await sleep(1000);
globals.logger.info('3...');
await sleep(1000);
globals.logger.info('2...');
await sleep(1000);
globals.logger.info('1...');
await sleep(1000);

await globals.initInfluxDB();

if (globals.config.get('Butler-SOS.uptimeMonitor.enable') === true) {
serviceUptime.serviceUptimeStart();
}

// Verify that the config file has the correct format
// Only do this if the command line option no-config-file-verify is NOT set
if (globals.options.skipConfigVerification) {
Expand All @@ -79,12 +92,7 @@ async function mainScript() {
const caFile = path.resolve(process.cwd(), globals.config.get('Butler-SOS.cert.clientCertCA'));

// Set up heartbeats, if enabled in the config file
if (
(globals.config.has('Butler-SOS.heartbeat.enabled') &&
globals.config.get('Butler-SOS.heartbeat.enabled') === true) ||
(globals.config.has('Butler-SOS.heartbeat.enable') &&
globals.config.get('Butler-SOS.heartbeat.enable') === true)
) {
if (globals.config.get('Butler-SOS.heartbeat.enable') === true) {
heartbeat.setupHeartbeatTimer(globals.config, globals.logger);
}

Expand All @@ -98,36 +106,32 @@ async function mainScript() {
// Default is to use log level defined in config file
globals.logger.info('--------------------------------------');
globals.logger.info('Starting Butler SOS');
globals.logger.info(`Log level: ${globals.getLoggingLevel()}`);
globals.logger.info(`App version: ${globals.appVersion}`);
globals.logger.info(`Instance ID : ${globals.hostInfo.id}`);
globals.logger.info(`Log level : ${globals.getLoggingLevel()}`);
globals.logger.info(`App version : ${globals.appVersion}`);
globals.logger.info(`Instance ID : ${globals.hostInfo.id}`);
globals.logger.info('');
globals.logger.info(`Node version : ${globals.hostInfo.node.nodeVersion}`);
globals.logger.info(`Architecture : ${globals.hostInfo.si.os.arch}`);
globals.logger.info(`Platform : ${globals.hostInfo.si.os.platform}`);
globals.logger.info(`Release : ${globals.hostInfo.si.os.release}`);
globals.logger.info(`Distro : ${globals.hostInfo.si.os.distro}`);
globals.logger.info(`Codename : ${globals.hostInfo.si.os.codename}`);
globals.logger.info(`Virtual : ${globals.hostInfo.si.system.virtual}`);
globals.logger.info(`Processors : ${globals.hostInfo.si.cpu.processors}`);
globals.logger.info(`Physical cores : ${globals.hostInfo.si.cpu.physicalCores}`);
globals.logger.info(`Cores : ${globals.hostInfo.si.cpu.cores}`);
globals.logger.info(`Docker arch. : ${globals.hostInfo.si.cpu.hypervizor}`);
globals.logger.info(`Total memory : ${globals.hostInfo.si.memory.total}`);
globals.logger.info(`Standalone app : ${globals.isPkg}`);
globals.logger.info('--------------------------------------');
globals.logger.info(`Node version : ${globals.hostInfo.node.nodeVersion}`);
globals.logger.info(`Architecture : ${globals.hostInfo.si.os.arch}`);
globals.logger.info(`Platform : ${globals.hostInfo.si.os.platform}`);
globals.logger.info(`Release : ${globals.hostInfo.si.os.release}`);
globals.logger.info(`Distro : ${globals.hostInfo.si.os.distro}`);
globals.logger.info(`Codename : ${globals.hostInfo.si.os.codename}`);
globals.logger.info(`Virtual : ${globals.hostInfo.si.system.virtual}`);
globals.logger.info(`Processors : ${globals.hostInfo.si.cpu.processors}`);
globals.logger.info(`Physical cores : ${globals.hostInfo.si.cpu.physicalCores}`);
globals.logger.info(`Cores : ${globals.hostInfo.si.cpu.cores}`);
globals.logger.info(`Docker arch. : ${globals.hostInfo.si.cpu.hypervizor}`);
globals.logger.info(`Total memory : ${globals.hostInfo.si.memory.total}`);
globals.logger.info(`Standalone app : ${globals.isPkg}`);

// Log info about what Qlik Sense certificates are being used
globals.logger.info(`Client cert: ${certFile}`);
globals.logger.info(`Client cert key: ${keyFile}`);
globals.logger.info(`CA cert: ${caFile}`);
globals.logger.info(`Client cert : ${certFile}`);
globals.logger.info(`Client cert key : ${keyFile}`);
globals.logger.info(`CA cert : ${caFile}`);
globals.logger.info('--------------------------------------');

// Set up anon usage reports, if enabled
if (
globals.config.has('Butler-SOS.anonTelemetry') === false ||
(globals.config.has('Butler-SOS.anonTelemetry') === true &&
globals.config.get('Butler-SOS.anonTelemetry') === true)
) {
if (globals.config.get('Butler-SOS.anonTelemetry') === true) {
telemetry.setupAnonUsageReportTimer();
globals.logger.verbose('MAIN: Anonymous telemetry reporting has been set up.');
globals.logger.verbose(
Expand All @@ -139,10 +143,7 @@ async function mainScript() {
}

// Set up UDP handler for user activity/events
if (
globals.config.has('Butler-SOS.userEvents.enable') &&
globals.config.get('Butler-SOS.userEvents.enable')
) {
if (globals.config.get('Butler-SOS.userEvents.enable')) {
udpUserActivity.udpInitUserActivityServer();

globals.logger.debug(
Expand All @@ -158,12 +159,9 @@ async function mainScript() {

// Set up UDP handler for log events
if (
(globals.config.has('Butler-SOS.logEvents.source.repository.enable') &&
globals.config.get('Butler-SOS.logEvents.source.repository.enable')) ||
(globals.config.has('Butler-SOS.logEvents.source.scheduler.enable') &&
globals.config.get('Butler-SOS.logEvents.source.scheduler.enable')) ||
(globals.config.has('Butler-SOS.logEvents.source.proxy.enable') &&
globals.config.get('Butler-SOS.logEvents.source.proxy.enable'))
globals.config.get('Butler-SOS.logEvents.source.repository.enable') ||
globals.config.get('Butler-SOS.logEvents.source.scheduler.enable') ||
globals.config.get('Butler-SOS.logEvents.source.proxy.enable')
) {
udpLogEvents.udpInitLogEventServer();

Expand All @@ -179,12 +177,7 @@ async function mainScript() {
}

// Start Docker healthcheck REST server on port set in config file
if (
(globals.config.has('Butler-SOS.dockerHealthCheck.enabled') &&
globals.config.get('Butler-SOS.dockerHealthCheck.enabled') === true) ||
(globals.config.has('Butler-SOS.dockerHealthCheck.enable') &&
globals.config.get('Butler-SOS.dockerHealthCheck.enable') === true)
) {
if (globals.config.get('Butler-SOS.dockerHealthCheck.enable') === true) {
try {
globals.logger.verbose('MAIN: Starting Docker healthcheck server...');

Expand All @@ -211,17 +204,9 @@ async function mainScript() {
}

// Start Prometheus metrics REST server on port set in config file
if (
globals.config.has('Butler-SOS.prometheus.enable') &&
globals.config.get('Butler-SOS.prometheus.enable') === true
) {
const promHost = globals.config.has('Butler-SOS.prometheus.host')
? globals.config.get('Butler-SOS.prometheus.host')
: '0.0.0.0';

const promPort = globals.config.has('Butler-SOS.prometheus.port')
? globals.config.get('Butler-SOS.prometheus.port')
: 9842;
if (globals.config.get('Butler-SOS.prometheus.enable') === true) {
const promHost = globals.config.get('Butler-SOS.prometheus.host');
const promPort = globals.config.get('Butler-SOS.prometheus.port');

const promNodeHost = '0.0.0.0';
const promNodePort = 9001;
Expand Down Expand Up @@ -256,12 +241,7 @@ async function mainScript() {
}

// Set up extraction of data from log db
if (
(globals.config.has('Butler-SOS.logdb.enableLogDb') &&
globals.config.get('Butler-SOS.logdb.enableLogDb') === true) ||
(globals.config.has('Butler-SOS.logdb.enable') &&
globals.config.get('Butler-SOS.logdb.enable') === true)
) {
if (globals.config.get('Butler-SOS.logdb.enable') === true) {
logDb.setupLogDbTimer();
}

Expand Down
6 changes: 3 additions & 3 deletions src/config/log_appender_xml/engine/LocalLogConfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@


<!-- Send UDP message to Butler SOS on warnings and errors -->
<logger name="Performance">
<logger name="Performance.Engine">
<appender-ref ref="LogEvent" />
</logger>
<logger name="System">
<logger name="System.Engine">
<appender-ref ref="LogEvent" />
</logger>
<logger name="Session">
<logger name="Session.Engine">
<appender-ref ref="LogEvent" />
</logger>
</configuration>
6 changes: 3 additions & 3 deletions src/config/log_appender_xml/proxy/LocalLogConfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@
</logger>

<!-- Send UDP message to Butler SOS on warnings and errors -->
<logger name="Audit">
<logger name="Audit.Proxy">
<appender-ref ref="LogEvent" />
</logger>
<logger name="AuditSecurity">
<appender-ref ref="LogEvent" />
</logger>
<logger name="Security">
<logger name="Security.Proxy">
<appender-ref ref="LogEvent" />
</logger>
<logger name="System">
<logger name="System.Proxy">
<appender-ref ref="LogEvent" />
</logger>
</configuration>
4 changes: 2 additions & 2 deletions src/config/log_appender_xml/repository/LocalLogConfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
<logger name="Service">
<appender-ref ref="LogEvent" />
</logger>
<logger name="System">
<logger name="System.Repository">
<appender-ref ref="LogEvent" />
</logger>
<logger name="UserManagement">
<logger name="UserManagement.Repository">
<appender-ref ref="LogEvent" />
</logger>
</configuration>
2 changes: 1 addition & 1 deletion src/config/log_appender_xml/scheduler/LocalLogConfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<logger name="Service">
<appender-ref ref="LogEvent" />
</logger>
<logger name="System">
<logger name="System.Scheduler">
<appender-ref ref="LogEvent" />
</logger>
</configuration>
Loading

0 comments on commit 75e1561

Please sign in to comment.