Commit 60ccd8c27c3a6ba8a72300a36209b751f185fcab
1 parent
475852689b
Exists in
master
include outgoing on spool count
Showing 1 changed file with 7 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 && escapeQuotes(req.query.keyword, '\'\n"&|*<>[];$ '); | 33 | const keyword = req.query.keyword && escapeQuotes(req.query.keyword, '\'\n"&|*<>[];$ '); |
34 | const cmd = req.query.keyword ? `tail -n ${maxLines * 50} /var/log/smsd/smsd.log | grep --ignore-case ${keyword} | tail -n ${maxLines} | tac` | 34 | const cmd = req.query.keyword ? `tail -n ${maxLines * 50} /var/log/smsd/smsd.log | grep --ignore-case ${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 | async function pageSpoolCount(req, res) { | 47 | async function pageSpoolCount(req, res) { |
48 | const checkedCount = await smstoolsUtil.fileCountOnDir('/var/spool/sms/checked'); | 48 | const checkedCount = await smstoolsUtil.fileCountOnDir('/var/spool/sms/checked'); |
49 | const outgoingCount = await smstoolsUtil.fileCountOnDir('/var/spool/sms/outgoing'); | ||
49 | const indosatCount = await smstoolsUtil.fileCountOnDir('/var/spool/sms/queue/indosat'); | 50 | const indosatCount = await smstoolsUtil.fileCountOnDir('/var/spool/sms/queue/indosat'); |
50 | const otherCount = await smstoolsUtil.fileCountOnDir('/var/spool/sms/queue/other'); | 51 | const otherCount = await smstoolsUtil.fileCountOnDir('/var/spool/sms/queue/other'); |
51 | 52 | ||
52 | res.json({ | 53 | res.json({ |
53 | checkedCount, | 54 | checkedCount, |
55 | outgoingCount, | ||
54 | indosatCount, | 56 | indosatCount, |
55 | otherCount, | 57 | otherCount, |
56 | totalQueueCount: Number(checkedCount) + Number(indosatCount) + Number(otherCount), | 58 | totalQueueCount: |
59 | Number(checkedCount) | ||
60 | + Number(outgoingCount) | ||
61 | + Number(indosatCount) | ||
62 | + Number(otherCount), | ||
57 | }); | 63 | }); |
58 | } | 64 | } |
59 | 65 | ||
60 | router.get('/status', pageStatus); | 66 | router.get('/status', pageStatus); |
61 | router.get('/status/raw', pageStatusRaw); | 67 | router.get('/status/raw', pageStatusRaw); |
62 | router.get('/restart', pageRestart); | 68 | router.get('/restart', pageRestart); |
63 | router.get('/log', pageLog); | 69 | router.get('/log', pageLog); |
64 | router.get('/spool-count', pageSpoolCount); | 70 | router.get('/spool-count', pageSpoolCount); |
65 | 71 |