smstools-status-parsed.js
1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* eslint-disable guard-for-in */
const moment = require('moment');
const config = require('komodo-sdk/config');
const logger = require('komodo-sdk/logger');
const smstoolsStatus = require('./smstools-status');
const modemInfo = require('./smstools-modem-info');
module.exports = async (statsFilename) => {
const smstoolsLogfile = config.smstools_logfile || config.smstools_log_file || '/var/log/smsd/smsd.log';
logger.verbose('ROUTER-SMSTOOLS-STATUS-PARSED: Executing', { smstoolsLogfile });
const contents = await smstoolsStatus(statsFilename);
const contentsSplitted = (contents || '').trim().split('\n');
const lines = [];
// eslint-disable-next-line no-restricted-syntax
for (const i in contentsSplitted) {
const line = contentsSplitted[i];
const cols = line.split(/[:,]\t+/);
const [keyword, tsRaw, status, succedeed, failed, received, signal] = cols;
const ts = (tsRaw && moment(tsRaw, 'YY-MM-DD HH:mm:ss')) || null;
if (keyword === 'Status') {
lines.push({
keyword,
line,
});
} else {
const regularRunResultFile = config.smstools_regular_run_result_file || '/var/spool/sms/regular_run/<MODEMNAME>';
// eslint-disable-next-line no-await-in-loop
const { imsi, imei, cops } = (await modemInfo.get(keyword, regularRunResultFile)) || {};
lines.push({
keyword,
line,
ts,
tsHuman: moment(ts).format('YYYY-MM-DD HH:mm:ss'),
tsRaw,
status,
succedeed,
failed,
received,
signal,
imsi,
imei,
cops,
});
}
}
return lines;
};