Provide machine name on logs snapshots batch

This commit is contained in:
goga-m 2017-10-31 16:30:46 +02:00 committed by Josh Harvey
parent 62d606cc80
commit 4f9cc88a5e
4 changed files with 819 additions and 273 deletions

View file

@ -58,19 +58,22 @@ function update (deviceId, logLines) {
/**
* Get all logs by machine id
* and timestamp
*
* @name list
* @function
*
* @param {string} deviceId Machine id to fetch the logs for
* @param {date} until Show the logs until the date provided, defaults to now
*
* @returns {array} Array of logs for the requested machinej
*/
function getMachineLogs (deviceId) {
function getMachineLogs (deviceId, until = new Date().toISOString()) {
const sql = `select id, log_level, timestamp, message from logs
where device_id=$1
order by timestamp desc limit $2`
return Promise.all([db.any(sql, [ deviceId, NUM_RESULTS ]), getMachineName(deviceId)])
and timestamp <= $3
order by timestamp asc limit $2`
return Promise.all([db.any(sql, [ deviceId, NUM_RESULTS, until ]), getMachineName(deviceId)])
.then(([logs, machineName]) => ({
logs: _.map(_.mapKeys(_.camelCase), logs),
currentMachine: {deviceId, name: machineName}