Skip to content

Commit

Permalink
TSERV-1062 Adding diagnostics report to the testengine cli. (#33)
Browse files Browse the repository at this point in the history
TSERV-1062 Adding diagnostics report to the testengine cli.
  • Loading branch information
lootic authored Jun 9, 2021
1 parent bc32ead commit 73aa2a4
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,18 @@ To uninstall, you use the uninstall command.
`testengine license install type=floating <ip-address|hostname>:1099`

A fixed license will be deactivated and a floating license will be checked back in to the floating license server.

### Create a diagnostics report
A diagnostics report is a zip-archive containing information about a running testengine instance that a testengine dev
needs when troubleshooting testengine. This diagnostics report can be created with the following command.

`testengine diagnostics run [reportFileName=fileName] [output=outputDirectory]`

`reportFileName` is the file name of the zip-archive excluding extension and `output` is the folder where the
zip-archive is going to be created.

Example:
```
$ testengine diagnostics run output=some/folder reportFileName=report -u admin -p password -H http://localhost:8080
Diagnostics report /home/björn/some/folder/report.zip created successfully
```
66 changes: 66 additions & 0 deletions bin/diagnostics_functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const process = require('process');
const util = require('./shared_utils');
const config = require('./config').config;
const request = require('superagent');
const fs = require('fs');
const resolve = require('path').resolve;

module.exports.dispatcher = function (args) {
if (args.length === 0) {
printModuleHelp();
process.exit(1);
}
switch (args[0].toLowerCase()) {
case 'run': {
const options = util.optionsFromArgs(args.splice(1), ['output', 'reportFileName']);
runDiagnostics(options['output'], options['reportFileName']);
break;
}
case 'help':
printModuleHelp();
break;
default:
util.printErrorAndExit("Unknown operation");
}
}

function runDiagnostics(outputFolder, fileName) {
const endPoint = config.server + '/api/v1/diagnostics';
let reportFileName = "diagnostics.zip";

if (outputFolder) {
if (!fs.existsSync(outputFolder)) {
fs.mkdirSync(outputFolder, {recursive: true});
}
}

reportFileName = (outputFolder ? outputFolder + '/' : '') + (fileName ? fileName : reportFileName);
if(!reportFileName.endsWith(".zip")) {
reportFileName += ".zip";
}
const stream = fs.createWriteStream(reportFileName);

const req = request.get(endPoint)
.auth(config.username, config.password)
.accept("application/zip")
.on('response', function (response) {
if (response.status !== 200) {
util.printErrorAndExit(`Status code: ${response.status}`);
} else {
util.output('Diagnostics report ' + resolve(reportFileName) + ' created successfully');
}
})
.on('error', function (err) {
util.error("Error: " + err.message);
process.exit(1);
}).send();

req.pipe(stream);
}

function printModuleHelp() {
util.error("Usage: testengine diagnostics <command>");
util.error("Commands: ");
util.error(" run [output=<directory>] [reportFileName=<filename>]");
util.error(" help");
}
6 changes: 5 additions & 1 deletion bin/testengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const auditlog = require('./auditlog_functions');
const run = require('./run_functions');
const license = require('./license_functions');
const jobs = require('./jobs_functions');
const diagnostics = require('./diagnostics_functions');
const config = require('./config');
const util = require('./shared_utils');
const pjson = require('../package.json');
Expand All @@ -17,7 +18,7 @@ const pjson = require('../package.json');
program
.version(pjson.version)
.name("testengine")
.usage('[options] <user|auditlog|run|jobs|license> command parameters')
.usage('[options] <user|auditlog|run|jobs|license|diagnostics> command parameters')
.option('-c, --config <filename>', 'Config file for admin tool')
.option('-q, --quiet', 'Run in quiet mode. Do not write to console')
.option('-u, --username <username>', 'TestEngine username')
Expand Down Expand Up @@ -59,6 +60,9 @@ if (program.args.length > 0) {
case 'license':
license.dispatcher(program.args.slice(1));
break;
case 'diagnostics':
diagnostics.dispatcher(program.args.slice(1));
break;
default:
program.outputHelp();
process.exit(1);
Expand Down

0 comments on commit 73aa2a4

Please sign in to comment.