From b5772740ae3685fceceeda513fca4ff86a183d14 Mon Sep 17 00:00:00 2001 From: Ivan Date: Sat, 22 Feb 2020 16:27:28 -0700 Subject: [PATCH] Add a containerId request parameter for journal-logs api endpoint, and pass it along to journalctl process options. Change-Type: minor Signed-off-by: Ivan --- src/device-api/v2.ts | 10 +++++++++- src/lib/journald.ts | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/device-api/v2.ts b/src/device-api/v2.ts index 2e500dba..e69b1f50 100644 --- a/src/device-api/v2.ts +++ b/src/device-api/v2.ts @@ -471,8 +471,16 @@ export function createV2Api(router: Router, applications: ApplicationManager) { const count = checkInt(req.body.count, { positive: true }) || undefined; const unit = req.body.unit; const format = req.body.format || 'short'; + const containerId = req.body.containerId; - const journald = spawnJournalctl({ all, follow, count, unit, format }); + const journald = spawnJournalctl({ + all, + follow, + count, + unit, + format, + containerId, + }); res.status(200); journald.stdout.pipe(res); res.on('close', () => { diff --git a/src/lib/journald.ts b/src/lib/journald.ts index 22516614..28ab487a 100644 --- a/src/lib/journald.ts +++ b/src/lib/journald.ts @@ -8,6 +8,7 @@ export function spawnJournalctl(opts: { follow: boolean; count?: number; unit?: string; + containerId?: string; format: string; }): ChildProcess { const args = [ @@ -25,6 +26,10 @@ export function spawnJournalctl(opts: { args.push('-u'); args.push(opts.unit); } + if (opts.containerId != null) { + args.push('-t'); + args.push(opts.containerId); + } if (opts.count != null) { args.push('-n'); args.push(opts.count.toString());