Skip to content

Commit

Permalink
Merge pull request #1289 from mountaindude/1287
Browse files Browse the repository at this point in the history
1287
  • Loading branch information
mountaindude authored Oct 24, 2024
2 parents 71f5230 + cbdfce3 commit 6f10790
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 93 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,7 @@ src/config/butler-config.yaml
src/udp_client/udp-client.exe
src/config/production_empty_arrays.yaml
src/config/production_template_filledin.yaml
build.cjs
butler
sea-config.json
sea-prep.blob
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"program": "${workspaceFolder}/src/butler.js",
// "runtimeVersion": "20",
"runtimeVersion": "18",
// "runtimeVersion": "23",
"cwd": "${workspaceFolder}/src",
"env": {
"NODE_CONFIG_DIR": "${workspaceFolder}/src/config",
Expand Down
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@
"xstate": "^5.18.2"
},
"devDependencies": {
"@babel/eslint-parser": "^7.25.8",
"@babel/plugin-syntax-import-assertions": "^7.25.7",
"@babel/eslint-parser": "^7.25.9",
"@babel/plugin-syntax-import-assertions": "^7.25.9",
"@eslint/js": "^9.13.0",
"esbuild": "^0.24.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"jest": "^29.7.0",
"prettier": "^3.3.3",
"snyk": "^1.1293.1"
"snyk": "^1.1294.0"
},
"pkg": {
"assets": [
Expand Down
1 change: 0 additions & 1 deletion src/butler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/first */
// Add dependencies
import dgram from 'dgram';

Expand Down
28 changes: 4 additions & 24 deletions src/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class Settings {
program.parse(process.argv);
this.options = program.opts();

// Utility functions
this.checkFileExistsSync = Settings.checkFileExistsSync;
this.sleep = Settings.sleep;

Expand Down Expand Up @@ -274,7 +275,7 @@ class Settings {
this.logger.debug('CONFIG: API doc mode=off');
// Deep copy of headers object
const httpHeadersEngine = JSON.parse(JSON.stringify(this.config.get('Butler.configEngine.headers')));

// Engine config
this.configEngine = {
engineVersion: this.config.get('Butler.configEngine.engineVersion'),
Expand All @@ -289,7 +290,7 @@ class Settings {

// Deep copy of headers object
const httpHeadersQRS = JSON.parse(JSON.stringify(this.config.get('Butler.configQRS.headers')));

// QRS config
this.configQRS = {
authentication: this.config.get('Butler.configQRS.authentication'),
Expand Down Expand Up @@ -363,28 +364,7 @@ class Settings {
database: this.config.get('Butler.influxDb.dbName'),
username: `${this.config.get('Butler.influxDb.auth.enable') ? this.config.get('Butler.influxDb.auth.username') : ''}`,
password: `${this.config.get('Butler.influxDb.auth.enable') ? this.config.get('Butler.influxDb.auth.password') : ''}`,
schema: [
{
measurement: 'butler_memory_usage',
fields: {
heap_used: Influx.FieldType.FLOAT,
heap_total: Influx.FieldType.FLOAT,
external: Influx.FieldType.FLOAT,
process_memory: Influx.FieldType.FLOAT,
},
tags: ['butler_instance', 'version'],
},
{
measurement: 'win_service_state',
fields: {
state_num: Influx.FieldType.INTEGER,
state_text: Influx.FieldType.STRING,
startup_mode_num: Influx.FieldType.INTEGER,
startup_mode_text: Influx.FieldType.STRING,
},
tags: ['butler_instance', 'host', 'service_name', 'display_name', 'friendly_name'],
},
],
schema: [],
});
}

Expand Down
70 changes: 31 additions & 39 deletions src/lib/post_to_influxdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ export function postButlerMemoryUsageToInfluxdb(memory) {

.then(() => {
globals.logger.silly(
`INFLUXDB MEMORY USAGE: Influxdb datapoint for Butler INFLUXDB MEMORY USAGE: ${JSON.stringify(datapoint, null, 2)}`,
`MEMORY USAGE: Influxdb datapoint for Butler INFLUXDB MEMORY USAGE: ${JSON.stringify(datapoint, null, 2)}`,
);

datapoint = null;
globals.logger.verbose('INFLUXDB MEMORY USAGE: Sent Butler memory usage data to InfluxDB');
globals.logger.verbose('MEMORY USAGE: Sent Butler memory usage data to InfluxDB');
})
.catch((err) => {
globals.logger.error(`INFLUXDB MEMORY USAGE: Error saving Butler memory usage to InfluxDB! ${err.stack}`);
globals.logger.error(`MEMORY USAGE: Error saving Butler memory usage to InfluxDB! ${err.stack}`);
});
}

Expand All @@ -65,7 +65,7 @@ export function postButlerMemoryUsageToInfluxdb(memory) {
// copyrightYearRange: "1993-2024",
// }
export async function postQlikSenseVersionToInfluxDB(qlikSenseVersion) {
globals.logger.verbose('[QSEOW] INFLUXDB QLIK SENSE VERSION: Sending Qlik Sense version to InfluxDB');
globals.logger.verbose('[QSEOW] QLIK SENSE VERSION: Sending Qlik Sense version to InfluxDB');

// Get tags from config file
// Stored in array Butler.qlikSenseVersion.versionMonitor.destination.influxDb.tag
Expand Down Expand Up @@ -119,11 +119,11 @@ export async function postQlikSenseVersionToInfluxDB(qlikSenseVersion) {
await globals.influx.writePoints(deepClonedDatapoint);

globals.logger.silly(
`[QSEOW] INFLUXDB QLIK SENSE VERSION: Influxdb datapoint for Qlik Sense version: ${JSON.stringify(datapoint, null, 2)}`,
`[QSEOW] QLIK SENSE VERSION: Influxdb datapoint for Qlik Sense version: ${JSON.stringify(datapoint, null, 2)}`,
);

datapoint = null;
globals.logger.verbose('[QSEOW] INFLUXDB QLIK SENSE VERSION: Sent Qlik Sense version to InfluxDB');
globals.logger.verbose('[QSEOW] QLIK SENSE VERSION: Sent Qlik Sense version to InfluxDB');
}

// Function to store Qlik Sense server license status to InfluxDB
Expand All @@ -135,7 +135,7 @@ export async function postQlikSenseVersionToInfluxDB(qlikSenseVersion) {
// "daysUntilExpiry": <number>,
// }
export async function postQlikSenseServerLicenseStatusToInfluxDB(qlikSenseServerLicenseStatus) {
globals.logger.verbose('[QSEOW] INFLUXDB QLIK SENSE SERVER LICENSE STATUS: Sending Qlik Sense server license status to InfluxDB');
globals.logger.verbose('[QSEOW] QLIK SENSE SERVER LICENSE STATUS: Sending Qlik Sense server license status to InfluxDB');

// Get tags from config file
// Stored in array Butler.qlikSenseLicense.serverLicenseMonitor.destination.influxDb.tag
Expand Down Expand Up @@ -184,15 +184,15 @@ export async function postQlikSenseServerLicenseStatusToInfluxDB(qlikSenseServer
await globals.influx.writePoints(deepClonedDatapoint);

globals.logger.silly(
`[QSEOW] INFLUXDB QLIK SENSE SERVER LICENSE STATUS: Influxdb datapoint for Qlik Sense server license status: ${JSON.stringify(
`[QSEOW] QLIK SENSE SERVER LICENSE STATUS: Influxdb datapoint for Qlik Sense server license status: ${JSON.stringify(
datapoint,
null,
2,
)}`,
);

datapoint = null;
globals.logger.verbose('[QSEOW] INFLUXDB QLIK SENSE SERVER LICENSE STATUS: Sent Qlik Sense server license status to InfluxDB');
globals.logger.verbose('[QSEOW] QLIK SENSE SERVER LICENSE STATUS: Sent Qlik Sense server license status to InfluxDB');
}

// Function to store Qlik Sense access license status to InfluxDB
Expand Down Expand Up @@ -247,7 +247,7 @@ export async function postQlikSenseServerLicenseStatusToInfluxDB(qlikSenseServer
// "schemaPath": "AccessTypeOverview"
// }
export async function postQlikSenseLicenseStatusToInfluxDB(qlikSenseLicenseStatus) {
globals.logger.verbose('[QSEOW] INFLUXDB QLIK SENSE LICENSE STATUS: Sending Qlik Sense license status to InfluxDB');
globals.logger.verbose('[QSEOW] END USER ACCESS LICENSE: Sending Qlik Sense license status to InfluxDB');

// Get tags from config file
// Stored in array Butler.qlikSenseLicense.licenseMonitor.destination.influxDb.tag
Expand Down Expand Up @@ -398,16 +398,16 @@ export async function postQlikSenseLicenseStatusToInfluxDB(qlikSenseLicenseStatu
await globals.influx.writePoints(deepClonedDatapoint);

globals.logger.silly(
`[QSEOW] INFLUXDB QLIK SENSE LICENSE STATUS: Influxdb datapoint for Qlik Sense license status: ${JSON.stringify(datapoint, null, 2)}`,
`[QSEOW] END USER ACCESS LICENSE: Influxdb datapoint for Qlik Sense license status: ${JSON.stringify(datapoint, null, 2)}`,
);

datapoint = null;
globals.logger.info('[QSEOW] INFLUXDB QLIK SENSE LICENSE STATUS: Sent aggregated Qlik Sense license status to InfluxDB');
globals.logger.info('[QSEOW] END USER ACCESS LICENSE: Sent aggregated Qlik Sense license status to InfluxDB');
}

// Function to store info about released Qlik Sense licenses to InfluxDB
export async function postQlikSenseLicenseReleasedToInfluxDB(licenseInfo) {
globals.logger.verbose('[QSEOW] INFLUXDB QLIK SENSE LICENSE RELEASE: Sending info on released Qlik Sense license to InfluxDB');
globals.logger.verbose('[QSEOW] END USER ACCESS LICENSE RELEASE: Sending info on released Qlik Sense license to InfluxDB');

// Get tags from config file
// Stored in array Butler.qlikSenseLicense.licenseMonitor.destination.influxDb.tag
Expand Down Expand Up @@ -455,17 +455,17 @@ export async function postQlikSenseLicenseReleasedToInfluxDB(licenseInfo) {
await globals.influx.writePoints(deepClonedDatapoint);

globals.logger.silly(
`[QSEOW] INFLUXDB QLIK SENSE LICENSE RELEASE: Influxdb datapoint for released Qlik Sense license: ${JSON.stringify(datapoint, null, 2)}`,
`[QSEOW] END USER ACCESS LICENSE RELEASE: Influxdb datapoint for released Qlik Sense license: ${JSON.stringify(datapoint, null, 2)}`,
);

datapoint = null;
globals.logger.debug('[QSEOW] INFLUXDB QLIK SENSE LICENSE RELEASE: Sent info on released Qlik Sense license to InfluxDB');
globals.logger.debug('[QSEOW] END USER ACCESS LICENSE RELEASE: Sent info on released Qlik Sense license to InfluxDB');
}

// Function to store windows service status to InfluxDB
export function postWindowsServiceStatusToInfluxDB(serviceStatus) {
globals.logger.verbose(
`INFLUXDB WINDOWS SERVICE STATUS: Sending service status to InfluxDB: service="${serviceStatus.serviceFriendlyName}", status="${serviceStatus.serviceStatus}"`,
`WINDOWS SERVICE STATUS: Sending service status to InfluxDB: service="${serviceStatus.serviceFriendlyName}", status="${serviceStatus.serviceStatus}"`,
);

// Create lookup table for Windows service state to numeric value, starting with 1 for stopped
Expand Down Expand Up @@ -530,25 +530,21 @@ export function postWindowsServiceStatusToInfluxDB(serviceStatus) {

.then(() => {
globals.logger.silly(
`INFLUXDB WINDOWS SERVICE STATUS: Influxdb datapoint for INFLUXDB WINDOWS SERVICE STATUS: ${JSON.stringify(
datapoint,
null,
2,
)}`,
`WINDOWS SERVICE STATUS: Influxdb datapoint for INFLUXDB WINDOWS SERVICE STATUS: ${JSON.stringify(datapoint, null, 2)}`,
);

datapoint = null;
globals.logger.verbose('INFLUXDB WINDOWS SERVICE STATUS: Sent Windows service status data to InfluxDB');
globals.logger.verbose('WINDOWS SERVICE STATUS: Sent Windows service status data to InfluxDB');
})
.catch((err) => {
globals.logger.error(`INFLUXDB WINDOWS SERVICE STATUS: Error saving Windows service status to InfluxDB! ${err.stack}`);
globals.logger.error(`WINDOWS SERVICE STATUS: Error saving Windows service status to InfluxDB! ${err.stack}`);
});
}

// Store information about successful reload tasks to InfluxDB
export function postReloadTaskSuccessNotificationInfluxDb(reloadParams) {
try {
globals.logger.verbose('[QSEOW] INFLUXDB RELOAD TASK SUCCESS: Sending reload task notification to InfluxDB');
globals.logger.verbose('[QSEOW] RELOAD TASK SUCCESS: Sending reload task notification to InfluxDB');

// Add tags
let tags = {};
Expand Down Expand Up @@ -589,7 +585,7 @@ export function postReloadTaskSuccessNotificationInfluxDb(reloadParams) {
// Get task info
const { taskInfo } = reloadParams;

globals.logger.debug(`[QSEOW] INFLUXDB RELOAD TASK SUCCESS: Task info:\n${JSON.stringify(taskInfo, null, 2)}`);
globals.logger.debug(`[QSEOW] RELOAD TASK SUCCESS: Task info:\n${JSON.stringify(taskInfo, null, 2)}`);

// Use task info to enrich log entry sent to InfluxDB
datapoint[0].tags.task_executingNodeName = taskInfo.executingNodeName;
Expand Down Expand Up @@ -652,26 +648,24 @@ export function postReloadTaskSuccessNotificationInfluxDb(reloadParams) {

.then(() => {
globals.logger.silly(
`[QSEOW] INFLUXDB RELOAD TASK SUCCESS: Influxdb datapoint for reload task notification: ${JSON.stringify(datapoint, null, 2)}`,
`[QSEOW] RELOAD TASK SUCCESS: Influxdb datapoint for reload task notification: ${JSON.stringify(datapoint, null, 2)}`,
);

datapoint = null;
globals.logger.verbose('[QSEOW] INFLUXDB RELOAD TASK SUCCESS: Sent reload task notification to InfluxDB');
globals.logger.verbose('[QSEOW] RELOAD TASK SUCCESS: Sent reload task notification to InfluxDB');
})
.catch((err) => {
globals.logger.error(
`[QSEOW] INFLUXDB RELOAD TASK SUCCESS: Error saving reload task notification to InfluxDB! ${err.stack}`,
);
globals.logger.error(`[QSEOW] RELOAD TASK SUCCESS: Error saving reload task notification to InfluxDB! ${err.stack}`);
});
} catch (err) {
globals.logger.error(`[QSEOW] INFLUXDB RELOAD TASK SUCCESS: ${err}`);
globals.logger.error(`[QSEOW] RELOAD TASK SUCCESS: ${err}`);
}
}

// Store information about failed reload tasks to InfluxDB
export function postReloadTaskFailureNotificationInfluxDb(reloadParams) {
try {
globals.logger.info('[QSEOW] INFLUXDB RELOAD TASK FAILED: Sending reload task notification to InfluxDB');
globals.logger.info('[QSEOW] RELOAD TASK FAILED: Sending reload task notification to InfluxDB');

// Add tags
let tags = {};
Expand Down Expand Up @@ -725,7 +719,7 @@ export function postReloadTaskFailureNotificationInfluxDb(reloadParams) {
scriptLogData.scriptLogTail = '';
}

globals.logger.debug(`[QSEOW] INFLUXDB RELOAD TASK FAILED: Script log data:\n${JSON.stringify(scriptLogData, null, 2)}`);
globals.logger.debug(`[QSEOW] RELOAD TASK FAILED: Script log data:\n${JSON.stringify(scriptLogData, null, 2)}`);

// Use script log data to enrich log entry sent to InfluxDB
datapoint[0].tags.task_executingNodeName = scriptLogData.executingNodeName;
Expand Down Expand Up @@ -797,18 +791,16 @@ export function postReloadTaskFailureNotificationInfluxDb(reloadParams) {

.then(() => {
globals.logger.silly(
`[QSEOW] INFLUXDB RELOAD TASK FAILED: Influxdb datapoint for reload task notification: ${JSON.stringify(datapoint, null, 2)}`,
`[QSEOW] RELOAD TASK FAILED: Influxdb datapoint for reload task notification: ${JSON.stringify(datapoint, null, 2)}`,
);

datapoint = null;
globals.logger.verbose('[QSEOW] INFLUXDB RELOAD TASK FAILED: Sent reload task notification to InfluxDB');
globals.logger.verbose('[QSEOW] RELOAD TASK FAILED: Sent reload task notification to InfluxDB');
})
.catch((err) => {
globals.logger.error(
`[QSEOW] INFLUXDB RELOAD TASK FAILED: Error saving reload task notification to InfluxDB! ${err.stack}`,
);
globals.logger.error(`[QSEOW] RELOAD TASK FAILED: Error saving reload task notification to InfluxDB! ${err.stack}`);
});
} catch (err) {
globals.logger.error(`[QSEOW] INFLUXDB RELOAD TASK FAILED: ${err}`);
globals.logger.error(`[QSEOW] RELOAD TASK FAILED: ${err}`);
}
}
Loading

0 comments on commit 6f10790

Please sign in to comment.