Commit c2cfd84fe454c914520641b013129a8751715ff9

Authored by Adhidarma Hadiwinoto
1 parent 9b5f21d3ee
Exists in master

pageLog

Showing 1 changed file with 2 additions and 2 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 6
7 const smstoolsUtil = require('../../smstools-util'); 7 const smstoolsUtil = require('../../smstools-util');
8 const smstoolsStatus = require('../../smstools-status'); 8 const smstoolsStatus = require('../../smstools-status');
9 const smstoolsStatusParsed = require('../../smstools-status-parsed'); 9 const smstoolsStatusParsed = require('../../smstools-status-parsed');
10 10
11 const router = express.Router(); 11 const router = express.Router();
12 module.exports = router; 12 module.exports = router;
13 13
14 async function pageStatus(req, res) { 14 async function pageStatus(req, res) {
15 const filename = config.smstools_status_file || '//var/log/smsd/smsd_stats/status'; 15 const filename = config.smstools_status_file || '//var/log/smsd/smsd_stats/status';
16 const status = await smstoolsStatusParsed(filename); 16 const status = await smstoolsStatusParsed(filename);
17 res.json(status); 17 res.json(status);
18 } 18 }
19 19
20 async function pageStatusRaw(req, res) { 20 async function pageStatusRaw(req, res) {
21 const filename = config.smstools_status_file || '//var/log/smsd/smsd_stats/status'; 21 const filename = config.smstools_status_file || '//var/log/smsd/smsd_stats/status';
22 const statusContent = await smstoolsStatus(filename); 22 const statusContent = await smstoolsStatus(filename);
23 res.end(statusContent); 23 res.end(statusContent);
24 } 24 }
25 25
26 async function pageRestart(req, res) { 26 async function pageRestart(req, res) {
27 res.json(await smstoolsUtil.restart()); 27 res.json(await smstoolsUtil.restart());
28 } 28 }
29 29
30 function pageSmsdLog(req, res) { 30 function pageLog(req, res) {
31 const maxLines = (Number(req.query.max) || 200); 31 const maxLines = (Number(req.query.max) || 200);
32 const keyword = req.query.keyword && req.query.keyword.trim() && escapeQuotes(req.query.keyword.trim(), '\'"&|*<>[];$'); 32 const keyword = req.query.keyword && req.query.keyword.trim() && escapeQuotes(req.query.keyword.trim(), '\'"&|*<>[];$');
33 const cmd = req.query.keyword ? `tail -n ${maxLines * 50} | grep ${keyword} | tail -n ${maxLines} | tac` 33 const cmd = req.query.keyword ? `tail -n ${maxLines * 50} | grep ${keyword} | tail -n ${maxLines} | tac`
34 : `tail -n ${maxLines} /var/log/smsd/smsd.log | tac`; 34 : `tail -n ${maxLines} /var/log/smsd/smsd.log | tac`;
35 35
36 childProcess.exec(cmd, (err, stdout, stderr) => { 36 childProcess.exec(cmd, (err, stdout, stderr) => {
37 res.json({ 37 res.json({
38 err, 38 err,
39 stdout, 39 stdout,
40 stderr, 40 stderr,
41 }); 41 });
42 }); 42 });
43 } 43 }
44 44
45 router.get('/status', pageStatus); 45 router.get('/status', pageStatus);
46 router.get('/status/raw', pageStatusRaw); 46 router.get('/status/raw', pageStatusRaw);
47 router.get('/restart', pageRestart); 47 router.get('/restart', pageRestart);
48 router.get('/smsd-log', pageSmsdLog); 48 router.get('/log', pageLog);
49 49