Commit 9b503f9a174c5a1167890b71fea7d46ecaa130fa
1 parent
7d16c37376
Exists in
master
/smstools/modems include imsi, imei, and cops
Showing 1 changed file with 13 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 | 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 | const smstoolsConfigData = require('../../smstools-config/config-file'); | 11 | const smstoolsConfigData = require('../../smstools-config/config-file'); |
12 | const modemInfo = require('../../smstools-modem-info'); | ||
12 | 13 | ||
13 | const router = express.Router(); | 14 | const router = express.Router(); |
14 | module.exports = router; | 15 | module.exports = router; |
15 | 16 | ||
16 | async function pageStatus(req, res) { | 17 | async function pageStatus(req, res) { |
17 | const filename = config.smstools_status_file || '//var/log/smsd/smsd_stats/status'; | 18 | const filename = config.smstools_status_file || '//var/log/smsd/smsd_stats/status'; |
18 | const status = await smstoolsStatusParsed(filename); | 19 | const status = await smstoolsStatusParsed(filename); |
19 | res.json(status); | 20 | res.json(status); |
20 | } | 21 | } |
21 | 22 | ||
22 | async function pageStatusRaw(req, res) { | 23 | async function pageStatusRaw(req, res) { |
23 | const filename = config.smstools_status_file || '//var/log/smsd/smsd_stats/status'; | 24 | const filename = config.smstools_status_file || '//var/log/smsd/smsd_stats/status'; |
24 | const statusContent = await smstoolsStatus(filename); | 25 | const statusContent = await smstoolsStatus(filename); |
25 | res.end(statusContent); | 26 | res.end(statusContent); |
26 | } | 27 | } |
27 | 28 | ||
28 | async function pageRestart(req, res) { | 29 | async function pageRestart(req, res) { |
29 | res.json(await smstoolsUtil.restart()); | 30 | res.json(await smstoolsUtil.restart()); |
30 | } | 31 | } |
31 | 32 | ||
32 | async function pageModemList(req, res) { | 33 | async function pageModems(req, res) { |
33 | const modems = []; | 34 | const modems = []; |
34 | // eslint-disable-next-line no-restricted-syntax | 35 | // eslint-disable-next-line no-restricted-syntax |
35 | for (const [key, value] of Object.entries(smstoolsConfigData.modems || {})) { | 36 | for (const [key, value] of Object.entries(smstoolsConfigData.modems || {})) { |
37 | const regularRunResultFile = config.smstools_regular_run_result_file || '/var/spool/sms/regular_run/<MODEMNAME>'; | ||
38 | |||
39 | // eslint-disable-next-line no-await-in-loop | ||
40 | const { imsi, imei, cops } = (await modemInfo.get(key, regularRunResultFile)) || {}; | ||
41 | |||
36 | modems.push({ | 42 | modems.push({ |
37 | label: `${key}: ${value.device}, INCOMING${value.outgoing ? ' and OUTGOING' : ''}`, | 43 | label: `${key}: ${value.device}, INCOMING${value.outgoing ? ' and OUTGOING' : ''}`, |
38 | value: key, | 44 | value: key, |
39 | data: value, | 45 | data: value, |
46 | status: { | ||
47 | imsi, | ||
48 | imei, | ||
49 | cops, | ||
50 | }, | ||
40 | }); | 51 | }); |
41 | } | 52 | } |
42 | 53 | ||
43 | res.json(modems); | 54 | res.json(modems); |
44 | } | 55 | } |
45 | 56 | ||
46 | function pageLog(req, res) { | 57 | function pageLog(req, res) { |
47 | const maxLines = (Number(req.query.max) || 200); | 58 | const maxLines = (Number(req.query.max) || 200); |
48 | const keyword = req.query.keyword && escapeQuotes(req.query.keyword, '\'\n"&|*<>[];$ '); | 59 | const keyword = req.query.keyword && escapeQuotes(req.query.keyword, '\'\n"&|*<>[];$ '); |
49 | const cmd = req.query.keyword ? `tail -n ${maxLines * 50} /var/log/smsd/smsd.log | grep --ignore-case ${keyword} | tail -n ${maxLines} | tac` | 60 | const cmd = req.query.keyword ? `tail -n ${maxLines * 50} /var/log/smsd/smsd.log | grep --ignore-case ${keyword} | tail -n ${maxLines} | tac` |
50 | : `tail -n ${maxLines} /var/log/smsd/smsd.log | tac`; | 61 | : `tail -n ${maxLines} /var/log/smsd/smsd.log | tac`; |
51 | 62 | ||
52 | logger.verbose('ROUTER-SMSTOOLS: Getting log', { keyword, maxLines, cmd }); | 63 | logger.verbose('ROUTER-SMSTOOLS: Getting log', { keyword, maxLines, cmd }); |
53 | childProcess.exec(cmd, (err, stdout, stderr) => { | 64 | childProcess.exec(cmd, (err, stdout, stderr) => { |
54 | res.json({ | 65 | res.json({ |
55 | err, | 66 | err, |
56 | stdout, | 67 | stdout, |
57 | stderr, | 68 | stderr, |
58 | }); | 69 | }); |
59 | }); | 70 | }); |
60 | } | 71 | } |
61 | 72 | ||
62 | async function pageSpoolCount(req, res) { | 73 | async function pageSpoolCount(req, res) { |
63 | const checkedCount = await smstoolsUtil.fileCountOnDir('/var/spool/sms/checked'); | 74 | const checkedCount = await smstoolsUtil.fileCountOnDir('/var/spool/sms/checked'); |
64 | const outgoingCount = await smstoolsUtil.fileCountOnDir('/var/spool/sms/outgoing'); | 75 | const outgoingCount = await smstoolsUtil.fileCountOnDir('/var/spool/sms/outgoing'); |
65 | const indosatCount = await smstoolsUtil.fileCountOnDir('/var/spool/sms/queue/indosat'); | 76 | const indosatCount = await smstoolsUtil.fileCountOnDir('/var/spool/sms/queue/indosat'); |
66 | const otherCount = await smstoolsUtil.fileCountOnDir('/var/spool/sms/queue/other'); | 77 | const otherCount = await smstoolsUtil.fileCountOnDir('/var/spool/sms/queue/other'); |
67 | 78 | ||
68 | res.json({ | 79 | res.json({ |
69 | checkedCount, | 80 | checkedCount, |
70 | outgoingCount, | 81 | outgoingCount, |
71 | indosatCount, | 82 | indosatCount, |
72 | otherCount, | 83 | otherCount, |
73 | totalQueueCount: | 84 | totalQueueCount: |
74 | Number(checkedCount) | 85 | Number(checkedCount) |
75 | + Number(outgoingCount) | 86 | + Number(outgoingCount) |
76 | + Number(indosatCount) | 87 | + Number(indosatCount) |
77 | + Number(otherCount), | 88 | + Number(otherCount), |
78 | }); | 89 | }); |
79 | } | 90 | } |
80 | 91 | ||
81 | router.get('/status', pageStatus); | 92 | router.get('/status', pageStatus); |
82 | router.get('/status/raw', pageStatusRaw); | 93 | router.get('/status/raw', pageStatusRaw); |
83 | router.get('/restart', pageRestart); | 94 | router.get('/restart', pageRestart); |
84 | router.get('/log', pageLog); | 95 | router.get('/log', pageLog); |
85 | router.get('/spool-count', pageSpoolCount); | 96 | router.get('/spool-count', pageSpoolCount); |
86 | router.get('/modems', pageModemList); | 97 | router.get('/modems', pageModems); |
87 | 98 |