Skip to content

Commit

Permalink
Merge pull request #1115 from mountaindude/master
Browse files Browse the repository at this point in the history
12.3.0
  • Loading branch information
mountaindude authored Apr 24, 2024
2 parents 543eef9 + f0795fc commit 50c2d9c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 30 deletions.
44 changes: 23 additions & 21 deletions src/butler.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,34 @@ const start = async () => {
}

// Verify correct structure of config file
resAssert = await configFileStructureAssert(globals.config, globals.logger);
if (resAssert === false) {
globals.logger.error('MAIN: Config file structure is incorrect. Exiting.');
process.exit(1);
} else {
globals.logger.info('MAIN: Config file structure is correct - all good.');
}

// Verify select parts/values in config file
if (globals.options.qsConnection) {
// Verify that the config file contains the required data related to New Relic
resAssert = await configFileNewRelicAssert(globals.config, globals.configQRS, globals.logger);
if (!settingsObj.options.skipConfigVerification) {
resAssert = await configFileStructureAssert(globals.config, globals.logger);
if (resAssert === false) {
globals.logger.error('MAIN: Config file does not contain required New Relic data. Exiting.');
globals.logger.error('MAIN: Config file structure is incorrect. Exiting.');
process.exit(1);
} else {
globals.logger.info('MAIN: Config file contains required New Relic data - all good.');
globals.logger.info('MAIN: Config file structure is correct - all good.');
}

// Verify that the config file contains the required data related to InfluxDb
resAssert = await configFileInfluxDbAssert(globals.config, globals.configQRS, globals.logger);
if (resAssert === false) {
globals.logger.error('MAIN: Config file does not contain required InfluxDb data. Exiting.');
process.exit(1);
} else {
globals.logger.info('MAIN: Config file contains required InfluxDb data - all good.');
// Verify select parts/values in config file
if (globals.options.qsConnection) {
// Verify that the config file contains the required data related to New Relic
resAssert = await configFileNewRelicAssert(globals.config, globals.configQRS, globals.logger);
if (resAssert === false) {
globals.logger.error('MAIN: Config file does not contain required New Relic data. Exiting.');
process.exit(1);
} else {
globals.logger.info('MAIN: Config file contains required New Relic data - all good.');
}

// Verify that the config file contains the required data related to InfluxDb
resAssert = await configFileInfluxDbAssert(globals.config, globals.configQRS, globals.logger);
if (resAssert === false) {
globals.logger.error('MAIN: Config file does not contain required InfluxDb data. Exiting.');
process.exit(1);
} else {
globals.logger.info('MAIN: Config file contains required InfluxDb data - all good.');
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ class Settings {
'--api-rate-limit',
'set the API rate limit, per minute. Default is 100 calls/minute. Set to 0 to disable rate limiting.',
100
);
)

.option('--skip-config-verification', 'Disable config file verification', false);

// Parse command line params
program.parse(process.argv);
Expand Down
43 changes: 35 additions & 8 deletions src/lib/assert/assert_config_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -2529,7 +2529,10 @@ export const configFileStructureAssert = async (config, logger) => {
}

// Make sure all entries in Butler.incidentTool.newRelic.reloadTaskFailure.destination.log.attribute.static are objects with the following properties:
// - 'string'
// {
// name: 'string',
// value: 'string'
// }
if (config.has('Butler.incidentTool.newRelic.reloadTaskFailure.destination.log.attribute.static')) {
const attributes = config.get('Butler.incidentTool.newRelic.reloadTaskFailure.destination.log.attribute.static');

Expand All @@ -2541,20 +2544,44 @@ export const configFileStructureAssert = async (config, logger) => {
configFileCorrect = false;
} else {
attributes.forEach((attribute, index) => {
if (typeof attribute !== 'string') {
if (typeof attribute !== 'object') {
logger.error(
`ASSERT CONFIG: "Butler.incidentTool.newRelic.reloadTaskFailure.destination.log.attribute.static[${index}]" is not a string`
`ASSERT CONFIG: "Butler.incidentTool.newRelic.reloadTaskFailure.destination.log.attribute.static[${index}]" is not an object`
);
configFileCorrect = false;
} else {
if (!Object.prototype.hasOwnProperty.call(attribute, 'name')) {
logger.error(
`ASSERT CONFIG: Missing "name" property in "Butler.incidentTool.newRelic.reloadTaskFailure.destination.log.attribute.static[${index}]"`
);
configFileCorrect = false;
} else if (typeof attribute.name !== 'string') {
logger.error(
`ASSERT CONFIG: "name" property in "Butler.incidentTool.newRelic.reloadTaskFailure.destination.log.attribute.static[${index}]" is not a string`
);
configFileCorrect = false;
}

if (!Object.prototype.hasOwnProperty.call(attribute, 'value')) {
logger.error(
`ASSERT CONFIG: Missing "value" property in "Butler.incidentTool.newRelic.reloadTaskFailure.destination.log.attribute.static[${index}]"`
);
configFileCorrect = false;
} else if (typeof attribute.value !== 'string') {
logger.error(
`ASSERT CONFIG: "value" property in "Butler.incidentTool.newRelic.reloadTaskFailure.destination.log.attribute.static[${index}]" is not a string`
);
configFileCorrect = false;
}
}
});
}
} else {
logger.error(
'ASSERT CONFIG: Missing config file entry "Butler.incidentTool.newRelic.reloadTaskFailure.destination.log.attribute.static"'
);
configFileCorrect = false;
}
} else {
logger.error(
'ASSERT CONFIG: Missing config file entry "Butler.incidentTool.newRelic.reloadTaskFailure.destination.log.attribute.static"'
);
configFileCorrect = false;
}

if (!config.has('Butler.incidentTool.newRelic.reloadTaskFailure.destination.log.attribute.dynamic.useAppTags')) {
Expand Down

0 comments on commit 50c2d9c

Please sign in to comment.