Skip to content

Commit

Permalink
fix: logging and snapshot file fixes (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
sumitsuthar committed Apr 8, 2024
1 parent 38f14b9 commit 0b231b8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
1 change: 0 additions & 1 deletion lib/nr-security-agent/lib/core/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ function setPolicyData(data) {
policy.data = data;
appInfoVersionUpdate(policy, data);
initLogger.info("[STEP-7] => Received and applied policy/configuration", JSON.stringify(policy.data));
logger.info('Applied policy is:', JSON.stringify(policy.data));
if (NRAgent && NRAgent.config.security.detection) {
logger.info('Security detection flags:', JSON.stringify(NRAgent.config.security.detection));
}
Expand Down
19 changes: 17 additions & 2 deletions lib/nr-security-agent/lib/core/commonUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const OS = require('os');
const path = require('path');
const checkDiskSpace = require('check-disk-space').default;
const AgentStatus = require('../core/agent-status');
const { CSEC_HOME, SLASH } = require('./sec-agent-constants');
const { CSEC_HOME, SLASH, EMPTY_STR } = require('./sec-agent-constants');

const njsAgentConstants = require('./sec-agent-constants');
const API = require('../../../nr-security-api');
Expand Down Expand Up @@ -445,6 +445,20 @@ function addLogEventtoBuffer(logMessage) {
logger.debug(error);
}
}
/**
* Utility to get framework from APM
* @returns
*/
function getFramework(){
let framework = EMPTY_STR;
try {
framework = NRAgent.environment.get('Framework')[0];
} catch (error) {
logger.debug("Unable to get framework");
}
return framework;
}


module.exports = {
getUUID,
Expand All @@ -469,5 +483,6 @@ module.exports = {
getWSHealthStatus,
setWSHealthStatus,
addLogEventtoBuffer,
getLogEvents
getLogEvents,
getFramework
};
2 changes: 1 addition & 1 deletion lib/nr-security-agent/lib/core/sec-agent-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ module.exports = {
ERROR_WHILE_SEND_EVENT: 'ERROR While Sending Event: {}',
WS_CONNECTED: '[STEP-4][COMPLETE][WS] Connected To Prevent-web Service',
SENDING_APPINFO: '[APP_INFO] Sending Application Info To Prevent-web Service: ',
SENDING_APPINFO_COMPLETE: '[COMPLETE][APP_INFO] Application info sent to Prevent-Web service :',
SENDING_APPINFO_COMPLETE: '[STEP-3][COMPLETE][APP_INFO] Application info sent to Prevent-Web service :',
APPLY_INSTRUMENTATION: '[STEP-6][BEGIN][instrumentation] Applying Instrumentation',
AVAIL_DISK: 'Available Disk Space Is: ',
AVAIL_DISK_ERROR: 'Insufficient Disk Space Available To The Location %s Is : %s',
Expand Down
11 changes: 6 additions & 5 deletions lib/nr-security-agent/lib/core/statusUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ const logs = require('./logging');
const commonUtils = require('./commonUtils');
const logger = logs.getLogger();
const statusFile = njsAgentConstants.STATUS_LOG_FILE;
const sep = require('path').sep;

const statusTemplate = 'Snapshot timestamp: : %s\n' +
`CSEC Agent start timestamp: ${njsAgentConstants.AGENT_START_TIME} with application uuid:${commonUtils.getUUID()}\n` +
`SEC_HOME: ${njsAgentConstants.CSEC_HOME}\n` +
`CSEC_HOME: ${njsAgentConstants.CSEC_HOME}${sep}nr-security-home${sep}\n` +
`Agent location: ${AGENT_DIR}\n` +
`Using CSEC Agent for Node.js, Node version:${process.version}, PID:${process.pid}\n` +
`Process title: ${process.title}\n` +
Expand All @@ -35,10 +36,10 @@ const statusTemplate = 'Snapshot timestamp: : %s\n' +
`Current working directory: ${process.cwd()}\n` +
`Agent mode: ${commonUtils.getCSECmode()}\n` +
'Application server: %s\n' +
'Application Framework: %s\n' +
`Application Framework: %s\n` +
`Websocket connection to Prevent Web: ${commonUtils.getValidatorServiceEndpointURL()}, Status: %s\n` +
'Instrumentation successful:\n' +
'Tracking loaded modules in the application:\n' +
'Instrumentation successful\n' +
'Tracking loaded modules in the application\n' +
'Policy applied successfully. Policy version is: %s\n' +
'Started Health Check for Agent\n' +
'Started Inbound and Outbound monitoring \n' +
Expand Down Expand Up @@ -83,7 +84,7 @@ function getFormattedData() {
const appInfo = Agent.applicationInfo;
const deployedApplications = appInfo && appInfo.serverInfo && appInfo.serverInfo.deployedApplications;
const appLoc = deployedApplications[0].deployedPath;
const formattedSnapshot = util.format(statusTemplate, new Date().toString(), appLoc, appInfo.serverInfo.name, njsAgentConstants.FRAMEWORK, commonUtils.getWSHealthStatus(), appInfo.policyVersion, getKeyValPairs(lastHC.stats), getKeyValPairs(lastHC.serviceStatus), JSON.stringify(getBufferedErrors()), JSON.stringify(getBufferedHC()));
const formattedSnapshot = util.format(statusTemplate, new Date().toString(), appLoc, appInfo.serverInfo.name, commonUtils.getFramework(), commonUtils.getWSHealthStatus(), appInfo.policyVersion, getKeyValPairs(lastHC.stats), getKeyValPairs(lastHC.serviceStatus), JSON.stringify(getBufferedErrors()), JSON.stringify(getBufferedHC()));
return formattedSnapshot;
}

Expand Down

0 comments on commit 0b231b8

Please sign in to comment.