Skip to content

Commit

Permalink
feat(user-event): Add app id/name to user event logging
Browse files Browse the repository at this point in the history
Implements #674
  • Loading branch information
Göran Sander committed Nov 26, 2023
1 parent 6769b9d commit 5298866
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 1 deletion.
13 changes: 13 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"prom-client": "^14.2.0",
"qrs-interact": "^6.3.1",
"systeminformation": "^5.21.18",
"uuid": "^9.0.1",
"winston": "^3.11.0",
"winston-daily-rotate-file": "^4.7.1",
"yaml-validator": "^5.0.1"
Expand Down
6 changes: 5 additions & 1 deletion src/lib/post-to-influxdb.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable prefer-destructuring */
/* eslint-disable no-unused-vars */

const globals = require('../globals');

const sessionAppPrefix = 'SessionApp';
Expand Down Expand Up @@ -427,8 +426,11 @@ function postUserEventToInfluxdb(msg) {
userDirectory: msg.user_directory,
userId: msg.user_id,
origin: msg.origin,
appId: msg.appId,
appName: msg.appName,
};

// Add custom tags from config file to payload
if (
globals.config.has('Butler-SOS.userEvents.tags') &&
globals.config.get('Butler-SOS.userEvents.tags') !== null &&
Expand All @@ -448,6 +450,8 @@ function postUserEventToInfluxdb(msg) {
fields: {
userFull: tags.userFull,
userId: tags.userId,
appId: msg.appId,
appName: msg.appName,
},
},
];
Expand Down
2 changes: 2 additions & 0 deletions src/lib/post-to-mqtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ function postUserEventToMQTT(msg) {
userDir: msg.user_directory,
userId: msg.user_id,
origin: msg.origin,
appId: msg.appId,
appName: msg.appName,
context: msg.context,
message: msg.message,
tags: {},
Expand Down
5 changes: 5 additions & 0 deletions src/lib/post-to-new-relic.js
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,8 @@ async function postUserEventToNewRelic(msg) {
.update(msg.user_id)
.digest('hex'),
qs_origin: msg.origin,
qs_appId: msg.appId,
qs_appName: msg.appName,
};
} else {
attributes = {
Expand All @@ -718,9 +720,12 @@ async function postUserEventToNewRelic(msg) {
qs_userDirectory: msg.user_directory,
qs_userId: msg.user_id,
qs_origin: msg.origin,
qs_appId: msg.appId,
qs_appName: msg.appName,
};
}

// Add custom tags from config file to payload
if (
globals.config.has('Butler-SOS.userEvents.tags') &&
globals.config.get('Butler-SOS.userEvents.tags') !== null &&
Expand Down
25 changes: 25 additions & 0 deletions src/lib/udp_handlers_user_activity.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-unused-vars */
const { validate } = require('uuid');

// Load global variables and functions
const globals = require('../globals');
Expand Down Expand Up @@ -101,6 +102,30 @@ function udpInitUserActivityServer() {
}
}

// Do we have an app id in the msgObj.context field?
// If that field starts with /app/<guid>?... then we have an app id
// Get that app ID and verify its a valid GUID
if (msgObj?.context.startsWith('/app/')) {
const appIdTmp = msgObj.context.split('?')[0];
const appIdTmp2 = appIdTmp.split('/app/')[1];

// Use uuid lib to verify that we have a valid GUID
if (validate(appIdTmp2)) {
msgObj.appId = appIdTmp2;
}
}

// Do we have an app id to app name lookup table?
// If so, get the app name from the app id
if (msgObj.appId.length > 0) {
const app = globals?.appNames.find((element) => element.id === msgObj.appId);
if (app?.name === undefined) {
msgObj.appName = '<unknown app name>';
} else {
msgObj.appName = app?.name;
}
}

// Post to MQTT
if (
((globals.config.has('Butler-SOS.mqttConfig.enableMQTT') &&
Expand Down

0 comments on commit 5298866

Please sign in to comment.