/* 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; };