diff --git a/CHANGES b/CHANGES index ab0b583ab..282552125 100644 --- a/CHANGES +++ b/CHANGES @@ -1841,4 +1841,5 @@ * linode: dns backend * make branding routes owner only * add branding API +* Add app start/stop/restart events diff --git a/src/apps.js b/src/apps.js index a0cc8f1d1..7709ede6c 100644 --- a/src/apps.js +++ b/src/apps.js @@ -1679,8 +1679,9 @@ function uninstall(appId, auditSource, callback) { }); } -function start(appId, callback) { +function start(appId, auditSource, callback) { assert.strictEqual(typeof appId, 'string'); + assert.strictEqual(typeof auditSource, 'object'); assert.strictEqual(typeof callback, 'function'); debug('Will start app with id:%s', appId); @@ -1698,13 +1699,16 @@ function start(appId, callback) { addTask(appId, exports.ISTATE_PENDING_START, task, function (error, result) { if (error) return callback(error); + eventlog.add(eventlog.ACTION_APP_START, auditSource, { appId, app, taskId: result.taskId }); + callback(null, { taskId: result.taskId }); }); }); } -function stop(appId, callback) { +function stop(appId, auditSource, callback) { assert.strictEqual(typeof appId, 'string'); + assert.strictEqual(typeof auditSource, 'object'); assert.strictEqual(typeof callback, 'function'); debug('Will stop app with id:%s', appId); @@ -1722,13 +1726,16 @@ function stop(appId, callback) { addTask(appId, exports.ISTATE_PENDING_STOP, task, function (error, result) { if (error) return callback(error); + eventlog.add(eventlog.ACTION_APP_STOP, auditSource, { appId, app, taskId: result.taskId }); + callback(null, { taskId: result.taskId }); }); }); } -function restart(appId, callback) { +function restart(appId, auditSource, callback) { assert.strictEqual(typeof appId, 'string'); + assert.strictEqual(typeof auditSource, 'object'); assert.strictEqual(typeof callback, 'function'); debug('Will restart app with id:%s', appId); @@ -1746,6 +1753,8 @@ function restart(appId, callback) { addTask(appId, exports.ISTATE_PENDING_RESTART, task, function (error, result) { if (error) return callback(error); + eventlog.add(eventlog.ACTION_APP_RESTART, auditSource, { appId, app, taskId: result.taskId }); + callback(null, { taskId: result.taskId }); }); }); diff --git a/src/eventlog.js b/src/eventlog.js index db3b38da9..179c18253 100644 --- a/src/eventlog.js +++ b/src/eventlog.js @@ -7,7 +7,7 @@ exports = module.exports = { getByCreationTime: getByCreationTime, cleanup: cleanup, - // keep in sync with webadmin index.js filter and CLI tool + // keep in sync with webadmin index.js filter ACTION_ACTIVATE: 'cloudron.activate', ACTION_APP_CLONE: 'app.clone', ACTION_APP_CONFIGURE: 'app.configure', @@ -21,6 +21,9 @@ exports = module.exports = { ACTION_APP_OOM: 'app.oom', ACTION_APP_UP: 'app.up', ACTION_APP_DOWN: 'app.down', + ACTION_APP_START: 'app.start', + ACTION_APP_STOP: 'app.stop', + ACTION_APP_RESTART: 'app.restart', ACTION_BACKUP_FINISH: 'backup.finish', ACTION_BACKUP_START: 'backup.start', diff --git a/src/routes/apps.js b/src/routes/apps.js index 0b73bde4c..5ede9337a 100644 --- a/src/routes/apps.js +++ b/src/routes/apps.js @@ -480,7 +480,7 @@ function startApp(req, res, next) { debug('Start app id:%s', req.params.id); - apps.start(req.params.id, function (error, result) { + apps.start(req.params.id, auditSource.fromRequest(req), function (error, result) { if (error) return next(BoxError.toHttpError(error)); next(new HttpSuccess(202, { taskId: result.taskId })); @@ -492,7 +492,7 @@ function stopApp(req, res, next) { debug('Stop app id:%s', req.params.id); - apps.stop(req.params.id, function (error, result) { + apps.stop(req.params.id, auditSource.fromRequest(req), function (error, result) { if (error) return next(BoxError.toHttpError(error)); next(new HttpSuccess(202, { taskId: result.taskId })); @@ -504,7 +504,7 @@ function restartApp(req, res, next) { debug('Restart app id:%s', req.params.id); - apps.restart(req.params.id, function (error, result) { + apps.restart(req.params.id, auditSource.fromRequest(req), function (error, result) { if (error) return next(BoxError.toHttpError(error)); next(new HttpSuccess(202, { taskId: result.taskId }));