Commit f0992162f00aa0240c48632a050178ebe7c24ee6
1 parent
0f3eba15c0
Exists in
master
no trim on log
Showing 1 changed file with 1 additions and 1 deletions Inline Diff
lib/apiserver/routers/smstools.js
1 | const childProcess = require('child_process'); | 1 | const childProcess = require('child_process'); |
2 | const express = require('express'); | 2 | const express = require('express'); |
3 | const escapeQuotes = require('escape-quotes'); | 3 | const escapeQuotes = require('escape-quotes'); |
4 | 4 | ||
5 | const config = require('komodo-sdk/config'); | 5 | const config = require('komodo-sdk/config'); |
6 | const logger = require('komodo-sdk/logger'); | 6 | const logger = require('komodo-sdk/logger'); |
7 | 7 | ||
8 | const smstoolsUtil = require('../../smstools-util'); | 8 | const smstoolsUtil = require('../../smstools-util'); |
9 | const smstoolsStatus = require('../../smstools-status'); | 9 | const smstoolsStatus = require('../../smstools-status'); |
10 | const smstoolsStatusParsed = require('../../smstools-status-parsed'); | 10 | const smstoolsStatusParsed = require('../../smstools-status-parsed'); |
11 | 11 | ||
12 | const router = express.Router(); | 12 | const router = express.Router(); |
13 | module.exports = router; | 13 | module.exports = router; |
14 | 14 | ||
15 | async function pageStatus(req, res) { | 15 | async function pageStatus(req, res) { |
16 | const filename = config.smstools_status_file || '//var/log/smsd/smsd_stats/status'; | 16 | const filename = config.smstools_status_file || '//var/log/smsd/smsd_stats/status'; |
17 | const status = await smstoolsStatusParsed(filename); | 17 | const status = await smstoolsStatusParsed(filename); |
18 | res.json(status); | 18 | res.json(status); |
19 | } | 19 | } |
20 | 20 | ||
21 | async function pageStatusRaw(req, res) { | 21 | async function pageStatusRaw(req, res) { |
22 | const filename = config.smstools_status_file || '//var/log/smsd/smsd_stats/status'; | 22 | const filename = config.smstools_status_file || '//var/log/smsd/smsd_stats/status'; |
23 | const statusContent = await smstoolsStatus(filename); | 23 | const statusContent = await smstoolsStatus(filename); |
24 | res.end(statusContent); | 24 | res.end(statusContent); |
25 | } | 25 | } |
26 | 26 | ||
27 | async function pageRestart(req, res) { | 27 | async function pageRestart(req, res) { |
28 | res.json(await smstoolsUtil.restart()); | 28 | res.json(await smstoolsUtil.restart()); |
29 | } | 29 | } |
30 | 30 | ||
31 | function pageLog(req, res) { | 31 | function pageLog(req, res) { |
32 | const maxLines = (Number(req.query.max) || 200); | 32 | const maxLines = (Number(req.query.max) || 200); |
33 | const keyword = req.query.keyword && req.query.keyword.trim() && escapeQuotes(req.query.keyword.trim(), '\'"&|*<>[];$'); | 33 | const keyword = req.query.keyword && escapeQuotes(req.query.keyword, '\'"&|*<>[];$'); |
34 | const cmd = req.query.keyword ? `tail -n ${maxLines * 50} | grep ${keyword} | tail -n ${maxLines} | tac` | 34 | const cmd = req.query.keyword ? `tail -n ${maxLines * 50} | grep ${keyword} | tail -n ${maxLines} | tac` |
35 | : `tail -n ${maxLines} /var/log/smsd/smsd.log | tac`; | 35 | : `tail -n ${maxLines} /var/log/smsd/smsd.log | tac`; |
36 | 36 | ||
37 | logger.verbose('ROUTER-SMSTOOLS: Getting log', { keyword, maxLines, cmd }); | 37 | logger.verbose('ROUTER-SMSTOOLS: Getting log', { keyword, maxLines, cmd }); |
38 | childProcess.exec(cmd, (err, stdout, stderr) => { | 38 | childProcess.exec(cmd, (err, stdout, stderr) => { |
39 | res.json({ | 39 | res.json({ |
40 | err, | 40 | err, |
41 | stdout, | 41 | stdout, |
42 | stderr, | 42 | stderr, |
43 | }); | 43 | }); |
44 | }); | 44 | }); |
45 | } | 45 | } |
46 | 46 | ||
47 | router.get('/status', pageStatus); | 47 | router.get('/status', pageStatus); |
48 | router.get('/status/raw', pageStatusRaw); | 48 | router.get('/status/raw', pageStatusRaw); |
49 | router.get('/restart', pageRestart); | 49 | router.get('/restart', pageRestart); |
50 | router.get('/log', pageLog); | 50 | router.get('/log', pageLog); |
51 | 51 |