report-sender2.js
1.53 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
const request = require('request');
const config = require('komodo-sdk/config');
const logger = require('komodo-sdk/logger');
const modemInfo = require('./modem-info');
function incomingSMS(ts, from, msg) {
if (!ts || !from || !msg
|| !config || !config.report_url || !config.report_url.incoming_sms) return;
const requestOptions = {
url: config.report_url.incoming_sms,
qs: {
ts,
// status: message.metadata.status,
number: from,
msg,
modem: config.name,
modem_imsi: modemInfo.imsi,
modem_msisdn: modemInfo.msisdn,
modem_device: config.modem.device,
modem_network_id: modemInfo.networkId,
modem_network_name: modemInfo.networkName,
modem_signal_strength: modemInfo.signalStrength,
uptime: Math.floor(process.uptime()),
report_port: config.http_command_server.listen_port,
report_apikey: config.http_command_server.apikey,
report_path_sms: '/sms',
},
};
logger.info('Sending report via HTTP', requestOptions);
request(requestOptions, (err, res, body) => {
if (err) {
logger.warn(`Error sending report via HTTP. ${err.toString()}`);
return;
}
if (res.statusCode !== 200) {
logger.warn(`Error sending report via HTTP. Server respond with HTTP status code ${res.statusCode}`, { http_status_code: res.statusCode, body });
}
});
}
exports.incomingSMS = incomingSMS;