Skip to content

Commit

Permalink
feat(new-relic): Allow per-reload-task control of to which New Relic …
Browse files Browse the repository at this point in the history
…account failed/aborted reload alerts are sent

Implements #475
  • Loading branch information
Göran Sander committed Sep 29, 2022
1 parent eb1de8c commit aa81ceb
Show file tree
Hide file tree
Showing 3 changed files with 624 additions and 55 deletions.
6 changes: 5 additions & 1 deletion src/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ const si = require('systeminformation');
const os = require('os');
const crypto = require('crypto');
const isUncPath = require('is-unc-path');
const winston = require('winston');

// Add dependencies
const { Command, Option } = require('commander');
const { configFileNewRelicAssert } = require('./lib/assert/assert_config_file');

const winston = require('winston');
require('winston-daily-rotate-file');

// Variable holding info about all defined schedules
Expand Down Expand Up @@ -216,6 +217,9 @@ if (config.has('Butler.restServerApiDocGenerate') === false || config.get('Butle
logger.debug('CONFIG: API doc mode=on');
}

// Verify select parts/values in config file
configFileNewRelicAssert(config, configQRS, logger);

// MS Teams notification objects
let teamsTaskFailureObj;
let teamsTaskAbortedObj;
Expand Down
282 changes: 282 additions & 0 deletions src/lib/assert/assert_config_file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
const QrsInteract = require('qrs-interact');

/**
* Verify settings in the config file
*/
const configFileNewRelicAssert = async (config, configQRS, logger) => {
// Set up shared Sense repository service configuration
const cfg = {
hostname: config.get('Butler.configQRS.host'),
portNumber: 4242,
certificates: {
certFile: configQRS.certPaths.certPath,
keyFile: configQRS.certPaths.keyPath,
},
};

cfg.headers = {
'X-Qlik-User': 'UserDirectory=Internal; UserId=sa_repository',
};

const qrsInstance = new QrsInteract(cfg);

// ------------------------------------------
// The custom property specified by
// Butler.incidentToo.newRelic.reloadTaskFailure.destination.event.sendToAccount.byCustomProperty.customPropertyName
// should only include values present in the Butler.thirdPartyToolsCredentials.newRelic array

// Only test if the feature in question is enabled in the config file
if (
config.has('Butler.incidentTool.newRelic.reloadTaskFailure.destination.event.sendToAccount.byCustomProperty.enable') &&
config.get('Butler.incidentTool.newRelic.reloadTaskFailure.destination.event.sendToAccount.byCustomProperty.enable') &&
config.has('Butler.incidentTool.newRelic.reloadTaskFailure.destination.event.sendToAccount.byCustomProperty.customPropertyName')
) {
// Get custom property values
try {
logger.debug(
`ASSERT CONFIG NEW RELIC 1: Custom property name: ${config.get(
'Butler.incidentTool.newRelic.reloadTaskFailure.destination.event.sendToAccount.byCustomProperty.customPropertyName'
)}`
);
logger.debug(
`ASSERT CONFIG NEW RELIC 1: custompropertydefinition/full?filter=name eq '${config.get(
'Butler.incidentTool.newRelic.reloadTaskFailure.destination.event.sendToAccount.byCustomProperty.customPropertyName'
)}`
);
qrsInstance
.Get(
`custompropertydefinition/full?filter=name eq '${config.get(
'Butler.incidentTool.newRelic.reloadTaskFailure.destination.event.sendToAccount.byCustomProperty.customPropertyName'
)}'`
)
.then((result1) => {
// The choice values of the custom property should match the values in Butler.thirdPartyToolsCredentials.newRelic

// Test each custom property choice value for existence in Butler config file
const availableNewRelicAccounts = config.get('Butler.thirdPartyToolsCredentials.newRelic');

// eslint-disable-next-line no-restricted-syntax
for (const value of result1.body[0].choiceValues) {
if (availableNewRelicAccounts.findIndex((account) => value === account.accountName) === -1) {
logger.warn(
`ASSERT CONFIG NEW RELIC: New Relic account name '${value}' of custom property '${config.get(
'Butler.incidentTool.newRelic.reloadTaskFailure.destination.event.sendToAccount.byCustomProperty.customPropertyName'
)}' not found in Butler's config file`
);
}
}
});
} catch (err) {
logger.error(`SCRIPTLOG: ${err}`);
}
} else {
// eslint-disable-next-line no-lonely-if
if (
config.has('Butler.incidentTool.newRelic.reloadTaskFailure.destination.event.sendToAccount.byCustomProperty.enable') &&
config.get('Butler.incidentTool.newRelic.reloadTaskFailure.destination.event.sendToAccount.byCustomProperty.enable') &&
!config.has(
'Butler.incidentTool.newRelic.reloadTaskFailure.destination.event.sendToAccount.byCustomProperty.customPropertyName'
)
) {
logger.error(
`ASSERT CONFIG NEW RELIC: Missing config file entry "Butler.incidentTool.newRelic.reloadTaskFailure.destination.event.sendToAccount.byCustomProperty.customPropertyName"`
);
process.exit(1);
}
}

// ------------------------------------------
// The custom property specified by
// Butler.incidentToo.newRelic.reloadTaskFailure.destination.log.sendToAccount.byCustomProperty.customPropertyName
// should only include values present in the Butler.thirdPartyToolsCredentials.newRelic array

// Only test if the feature in question is enabled in the config file
if (
config.has('Butler.incidentTool.newRelic.reloadTaskFailure.destination.log.sendToAccount.byCustomProperty.enable') &&
config.get('Butler.incidentTool.newRelic.reloadTaskFailure.destination.log.sendToAccount.byCustomProperty.enable') &&
config.has('Butler.incidentTool.newRelic.reloadTaskFailure.destination.log.sendToAccount.byCustomProperty.customPropertyName')
) {
// Get custom property values
try {
logger.debug(
`ASSERT CONFIG NEW RELIC 1: Custom property name: ${config.get(
'Butler.incidentTool.newRelic.reloadTaskFailure.destination.log.sendToAccount.byCustomProperty.customPropertyName'
)}`
);
logger.debug(
`ASSERT CONFIG NEW RELIC 1: custompropertydefinition/full?filter=name eq '${config.get(
'Butler.incidentTool.newRelic.reloadTaskFailure.destination.log.sendToAccount.byCustomProperty.customPropertyName'
)}`
);
qrsInstance
.Get(
`custompropertydefinition/full?filter=name eq '${config.get(
'Butler.incidentTool.newRelic.reloadTaskFailure.destination.log.sendToAccount.byCustomProperty.customPropertyName'
)}'`
)
.then((result1) => {
// The choice values of the custom property should match the values in Butler.thirdPartyToolsCredentials.newRelic

// Test each custom property choice value for existence in Butler config file
const availableNewRelicAccounts = config.get('Butler.thirdPartyToolsCredentials.newRelic');

// eslint-disable-next-line no-restricted-syntax
for (const value of result1.body[0].choiceValues) {
if (availableNewRelicAccounts.findIndex((account) => value === account.accountName) === -1) {
logger.warn(
`ASSERT CONFIG NEW RELIC: New Relic account name '${value}' of custom property '${config.get(
'Butler.incidentTool.newRelic.reloadTaskFailure.destination.log.sendToAccount.byCustomProperty.customPropertyName'
)}' not found in Butler's config file`
);
}
}
});
} catch (err) {
logger.error(`SCRIPTLOG: ${err}`);
}
} else {
// eslint-disable-next-line no-lonely-if
if (
config.has('Butler.incidentTool.newRelic.reloadTaskFailure.destination.log.sendToAccount.byCustomProperty.enable') &&
config.get('Butler.incidentTool.newRelic.reloadTaskFailure.destination.log.sendToAccount.byCustomProperty.enable') &&
!config.has('Butler.incidentTool.newRelic.reloadTaskFailure.destination.log.sendToAccount.byCustomProperty.customPropertyName')
) {
logger.error(
`ASSERT CONFIG NEW RELIC: Missing config file entry "Butler.incidentTool.newRelic.reloadTaskFailure.destination.log.sendToAccount.byCustomProperty.customPropertyName"`
);
process.exit(1);
}
}

// ------------------------------------------
// The custom property specified by
// Butler.incidentToo.newRelic.reloadTaskAborted.destination.event.sendToAccount.byCustomProperty.customPropertyName
// should only include values present in the Butler.thirdPartyToolsCredentials.newRelic array

// Only test if the feature in question is enabled in the config file
if (
config.has('Butler.incidentTool.newRelic.reloadTaskAborted.destination.event.sendToAccount.byCustomProperty.enable') &&
config.get('Butler.incidentTool.newRelic.reloadTaskAborted.destination.event.sendToAccount.byCustomProperty.enable') &&
config.has('Butler.incidentTool.newRelic.reloadTaskAborted.destination.event.sendToAccount.byCustomProperty.customPropertyName')
) {
// Get custom property values
try {
logger.debug(
`ASSERT CONFIG NEW RELIC 1: Custom property name: ${config.get(
'Butler.incidentTool.newRelic.reloadTaskAborted.destination.event.sendToAccount.byCustomProperty.customPropertyName'
)}`
);
logger.debug(
`ASSERT CONFIG NEW RELIC 1: custompropertydefinition/full?filter=name eq '${config.get(
'Butler.incidentTool.newRelic.reloadTaskAborted.destination.event.sendToAccount.byCustomProperty.customPropertyName'
)}`
);
qrsInstance
.Get(
`custompropertydefinition/full?filter=name eq '${config.get(
'Butler.incidentTool.newRelic.reloadTaskAborted.destination.event.sendToAccount.byCustomProperty.customPropertyName'
)}'`
)
.then((result1) => {
// The choice values of the custom property should match the values in Butler.thirdPartyToolsCredentials.newRelic

// Test each custom property choice value for existence in Butler config file
const availableNewRelicAccounts = config.get('Butler.thirdPartyToolsCredentials.newRelic');

// eslint-disable-next-line no-restricted-syntax
for (const value of result1.body[0].choiceValues) {
if (availableNewRelicAccounts.findIndex((account) => value === account.accountName) === -1) {
logger.warn(
`ASSERT CONFIG NEW RELIC: New Relic account name '${value}' of custom property '${config.get(
'Butler.incidentTool.newRelic.reloadTaskAborted.destination.event.sendToAccount.byCustomProperty.customPropertyName'
)}' not found in Butler's config file`
);
}
}
});
} catch (err) {
logger.error(`SCRIPTLOG: ${err}`);
}
} else {
// eslint-disable-next-line no-lonely-if
if (
config.has('Butler.incidentTool.newRelic.reloadTaskAborted.destination.event.sendToAccount.byCustomProperty.enable') &&
config.get('Butler.incidentTool.newRelic.reloadTaskAborted.destination.event.sendToAccount.byCustomProperty.enable') &&
!config.has(
'Butler.incidentTool.newRelic.reloadTaskAborted.destination.event.sendToAccount.byCustomProperty.customPropertyName'
)
) {
logger.error(
`ASSERT CONFIG NEW RELIC: Missing config file entry "Butler.incidentTool.newRelic.reloadTaskAborted.destination.event.sendToAccount.byCustomProperty.customPropertyName"`
);
process.exit(1);
}
}

// ------------------------------------------
// The custom property specified by
// Butler.incidentToo.newRelic.reloadTaskAborted.destination.log.sendToAccount.byCustomProperty.customPropertyName
// should only include values present in the Butler.thirdPartyToolsCredentials.newRelic array

// Only test if the feature in question is enabled in the config file
if (
config.has('Butler.incidentTool.newRelic.reloadTaskAborted.destination.log.sendToAccount.byCustomProperty.enable') &&
config.get('Butler.incidentTool.newRelic.reloadTaskAborted.destination.log.sendToAccount.byCustomProperty.enable') &&
config.has('Butler.incidentTool.newRelic.reloadTaskAborted.destination.log.sendToAccount.byCustomProperty.customPropertyName')
) {
// Get custom property values
try {
logger.debug(
`ASSERT CONFIG NEW RELIC 1: Custom property name: ${config.get(
'Butler.incidentTool.newRelic.reloadTaskAborted.destination.log.sendToAccount.byCustomProperty.customPropertyName'
)}`
);
logger.debug(
`ASSERT CONFIG NEW RELIC 1: custompropertydefinition/full?filter=name eq '${config.get(
'Butler.incidentTool.newRelic.reloadTaskAborted.destination.log.sendToAccount.byCustomProperty.customPropertyName'
)}`
);
qrsInstance
.Get(
`custompropertydefinition/full?filter=name eq '${config.get(
'Butler.incidentTool.newRelic.reloadTaskAborted.destination.log.sendToAccount.byCustomProperty.customPropertyName'
)}'`
)
.then((result1) => {
// The choice values of the custom property should match the values in Butler.thirdPartyToolsCredentials.newRelic

// Test each custom property choice value for existence in Butler config file
const availableNewRelicAccounts = config.get('Butler.thirdPartyToolsCredentials.newRelic');

// eslint-disable-next-line no-restricted-syntax
for (const value of result1.body[0].choiceValues) {
if (availableNewRelicAccounts.findIndex((account) => value === account.accountName) === -1) {
logger.warn(
`ASSERT CONFIG NEW RELIC: New Relic account name '${value}' of custom property '${config.get(
'Butler.incidentTool.newRelic.reloadTaskAborted.destination.log.sendToAccount.byCustomProperty.customPropertyName'
)}' not found in Butler's config file`
);
}
}
});
} catch (err) {
logger.error(`SCRIPTLOG: ${err}`);
}
} else {
// eslint-disable-next-line no-lonely-if
if (
config.has('Butler.incidentTool.newRelic.reloadTaskAborted.destination.log.sendToAccount.byCustomProperty.enable') &&
config.get('Butler.incidentTool.newRelic.reloadTaskAborted.destination.log.sendToAccount.byCustomProperty.enable') &&
!config.has('Butler.incidentTool.newRelic.reloadTaskAborted.destination.log.sendToAccount.byCustomProperty.customPropertyName')
) {
logger.error(
`ASSERT CONFIG NEW RELIC: Missing config file entry "Butler.incidentTool.newRelic.reloadTaskAborted.destination.log.sendToAccount.byCustomProperty.customPropertyName"`
);
process.exit(1);
}
}
};

module.exports = {
configFileNewRelicAssert,
};
Loading

0 comments on commit aa81ceb

Please sign in to comment.