give lamassu support 2 full days of logs; log sharing last for 1 week
This commit is contained in:
parent
dc2f4e497f
commit
783b85ed72
3 changed files with 22 additions and 18 deletions
|
|
@ -41,7 +41,7 @@ app.get('/api/support_logs/logs', (req, res, next) => {
|
||||||
.then(log => (!_.isNil(log) && !_.isEmpty(log)) ? log : supportLogs.batch().then(_.first))
|
.then(log => (!_.isNil(log) && !_.isEmpty(log)) ? log : supportLogs.batch().then(_.first))
|
||||||
.then(result => {
|
.then(result => {
|
||||||
const log = result || {}
|
const log = result || {}
|
||||||
return logs.getMachineLogs(log.deviceId, log.timestamp)
|
return logs.getUnlimitedMachineLogs(log.deviceId, log.timestamp)
|
||||||
})
|
})
|
||||||
.then(r => res.send(r))
|
.then(r => res.send(r))
|
||||||
.catch(next)
|
.catch(next)
|
||||||
|
|
|
||||||
32
lib/logs.js
32
lib/logs.js
|
|
@ -56,23 +56,27 @@ function update (deviceId, logLines) {
|
||||||
return db.none(sql)
|
return db.none(sql)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
function getUnlimitedMachineLogs (deviceId, until = new Date().toISOString()) {
|
||||||
* Get all logs by machine id
|
const sql = `select id, log_level, timestamp, message from logs
|
||||||
* and timestamp
|
where device_id=$1
|
||||||
*
|
and timestamp <= $2
|
||||||
* @name list
|
and timestamp > ($2 - interval '2 days')
|
||||||
* @function
|
order by timestamp asc`
|
||||||
*
|
|
||||||
* @param {string} deviceId Machine id to fetch the logs for
|
return Promise.all([db.any(sql, [ deviceId, until ]), getMachineName(deviceId)])
|
||||||
* @param {date} until Show the logs until the date provided, defaults to now
|
.then(([logs, machineName]) => ({
|
||||||
*
|
logs: _.map(_.mapKeys(_.camelCase), logs),
|
||||||
* @returns {array} Array of logs for the requested machinej
|
currentMachine: {deviceId, name: machineName}
|
||||||
*/
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
function getMachineLogs (deviceId, until = new Date().toISOString()) {
|
function getMachineLogs (deviceId, until = new Date().toISOString()) {
|
||||||
const sql = `select id, log_level, timestamp, message from logs
|
const sql = `select id, log_level, timestamp, message from logs
|
||||||
where device_id=$1
|
where device_id=$1
|
||||||
and timestamp <= $3
|
and timestamp <= $3
|
||||||
order by timestamp asc limit $2`
|
order by timestamp asc
|
||||||
|
limit $2`
|
||||||
|
|
||||||
return Promise.all([db.any(sql, [ deviceId, NUM_RESULTS, until ]), getMachineName(deviceId)])
|
return Promise.all([db.any(sql, [ deviceId, NUM_RESULTS, until ]), getMachineName(deviceId)])
|
||||||
.then(([logs, machineName]) => ({
|
.then(([logs, machineName]) => ({
|
||||||
logs: _.map(_.mapKeys(_.camelCase), logs),
|
logs: _.map(_.mapKeys(_.camelCase), logs),
|
||||||
|
|
@ -80,4 +84,4 @@ function getMachineLogs (deviceId, until = new Date().toISOString()) {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { getMachineLogs, update, getLastSeen }
|
module.exports = { getUnlimitedMachineLogs, getMachineLogs, update, getLastSeen }
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ function insert (deviceId) {
|
||||||
function batch () {
|
function batch () {
|
||||||
const sql = `select s.id, s.device_id, s.timestamp, devices.name from support_logs as s
|
const sql = `select s.id, s.device_id, s.timestamp, devices.name from support_logs as s
|
||||||
inner join devices on s.device_id = devices.device_id
|
inner join devices on s.device_id = devices.device_id
|
||||||
where timestamp > (now() - interval '2 days')
|
where timestamp > (now() - interval '1 week')
|
||||||
order by s.timestamp desc`
|
order by s.timestamp desc`
|
||||||
return db.any(sql)
|
return db.any(sql)
|
||||||
.then(_.map(_.mapKeys(_.camelCase)))
|
.then(_.map(_.mapKeys(_.camelCase)))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue