added log tails function
This commit is contained in:
@@ -0,0 +1,12 @@
|
|||||||
|
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
|
||||||
|
import { defaultMenuSettings } from '../../globals';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'aws',
|
||||||
|
alias: ['a'],
|
||||||
|
description: 'Aws (a)',
|
||||||
|
hidden: false,
|
||||||
|
run: async (toolbox: GluegunMenuToolbox) => {
|
||||||
|
await toolbox.menu.showMenu('aws', defaultMenuSettings);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu'
|
||||||
|
import chalk = require('chalk');
|
||||||
|
import { confirmMessage, defaultMenuSettings } from '../../../globals';
|
||||||
|
const { AutoComplete } = require('enquirer');
|
||||||
|
const { spawn } = require('child_process');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'logs',
|
||||||
|
alias: ['l'],
|
||||||
|
description: 'Tail a log in cloudwatch (l)',
|
||||||
|
hidden: false,
|
||||||
|
run: async (toolbox: GluegunMenuToolbox) => {
|
||||||
|
|
||||||
|
const { system, strings } = toolbox
|
||||||
|
|
||||||
|
const groups = JSON.parse(strings.trim(await system.run(`aws logs describe-log-groups`)));
|
||||||
|
|
||||||
|
const options = groups.logGroups.map(item => {
|
||||||
|
return item.logGroupName;
|
||||||
|
});
|
||||||
|
|
||||||
|
const prompt = new AutoComplete({
|
||||||
|
name: 'logGroups',
|
||||||
|
message: 'Choose a logGroup',
|
||||||
|
limit: 30,
|
||||||
|
initial: options.length - 1,
|
||||||
|
choices: options
|
||||||
|
});
|
||||||
|
|
||||||
|
const logGroup = await prompt.run();
|
||||||
|
if (await confirmMessage(`Tail logs from ${chalk.yellow(logGroup)}?`)) {
|
||||||
|
const child = spawn('aws', ['logs', 'tail', `${logGroup}`, '--follow', '--format', 'short']);
|
||||||
|
child.stdout.setEncoding('utf8');
|
||||||
|
child.stdout.on('data', function(data) {
|
||||||
|
//Here is where the output goes
|
||||||
|
console.log(data);
|
||||||
|
});
|
||||||
|
child.stderr.on('data', (data) => {
|
||||||
|
console.error(`stderr: ${data}`);
|
||||||
|
});
|
||||||
|
child.on('close', (code) => {
|
||||||
|
console.log(`child process exited with code ${code}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toolbox.fromMenu()) {
|
||||||
|
await toolbox.menu.showMenu('aws', defaultMenuSettings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu'
|
|
||||||
import chalk = require('chalk');
|
|
||||||
import { confirmMessage, defaultMenuSettings } from '../../../../globals';
|
|
||||||
const { AutoComplete } = require('enquirer');
|
|
||||||
const { spawn } = require('child_process');
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
name: 'logs',
|
|
||||||
alias: ['l'],
|
|
||||||
description: 'Tail a log in cloudwatch (l)',
|
|
||||||
hidden: false,
|
|
||||||
run: async (toolbox: GluegunMenuToolbox) => {
|
|
||||||
|
|
||||||
const { system, strings } = toolbox
|
|
||||||
|
|
||||||
// aws logs tail /aws/codebuild/photowall-test-arwid-1 --follow
|
|
||||||
// aws logs describe-log-groups --log-group-name-prefix codepipeline
|
|
||||||
|
|
||||||
// const groups = JSON.parse(strings.trim(await system.run(`aws logs describe-log-groups`)));
|
|
||||||
|
|
||||||
// const options = groups.logGroups.map(item => {
|
|
||||||
// return item.logGroupName;
|
|
||||||
// });
|
|
||||||
|
|
||||||
// const prompt = new AutoComplete({
|
|
||||||
// name: 'logGroups',
|
|
||||||
// message: 'Choose a logGroup',
|
|
||||||
// limit: 30,
|
|
||||||
// initial: options.length - 1,
|
|
||||||
// choices: options
|
|
||||||
// });
|
|
||||||
|
|
||||||
// const logGroup = await prompt.run();
|
|
||||||
const logGroup = 'top';
|
|
||||||
|
|
||||||
if (await confirmMessage(`Tail logs from ${chalk.yellow(logGroup)}?`)) {
|
|
||||||
// system.run(`aws logs tail ${logGroup} --follow`);
|
|
||||||
// const child = spawn(`aws logs tail ${logGroup} --follow`);
|
|
||||||
const child = spawn(`top`);
|
|
||||||
child.stdout.setEncoding('utf8');
|
|
||||||
child.stdout.on('data', function(data) {
|
|
||||||
//Here is where the output goes
|
|
||||||
console.clear();
|
|
||||||
console.log(data);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (toolbox.fromMenu()) {
|
|
||||||
await toolbox.menu.showMenu('deployment testservers', defaultMenuSettings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user