Commit 1696c7056b75b7d107ca485d6016652db62724a5

Authored by Adhidarma Hadiwinoto
1 parent 48d5ab8110
Exists in master

Nothing

Showing 1 changed file with 1 additions and 1 deletions Inline Diff

lib/register-modem.js
1 'use strict'; 1 'use strict';
2 2
3 const path = require('path'); 3 const path = require('path');
4 const request = require('request'); 4 const request = require('request');
5 5
6 const locks = require('locks'); 6 const locks = require('locks');
7 7
8 const config = require('komodo-sdk/config'); 8 const config = require('komodo-sdk/config');
9 const logger = require('komodo-sdk/logger'); 9 const logger = require('komodo-sdk/logger');
10 10
11 // const counters = require('./counters'); 11 // const counters = require('./counters');
12 12
13 const mutex = locks.createMutex(); 13 const mutex = locks.createMutex();
14 14
15 function reportUrl() { 15 function reportUrl() {
16 if (config.report_url.register_modem) { 16 if (config.report_url.register_modem) {
17 return config.report_url.register_modem; 17 return config.report_url.register_modem;
18 } 18 }
19 19
20 const baseUrl = path.dirname(config.report_url.incoming_sms); 20 const baseUrl = path.dirname(config.report_url.incoming_sms);
21 return `${baseUrl}/modems/set`; 21 return `${baseUrl}/modems/set`;
22 } 22 }
23 23
24 async function sender(modemInfo) { 24 async function sender(modemInfo) {
25 if (mutex.tryLock()) { 25 if (mutex.tryLock()) {
26 logger.info('Getting message counters before registering modem'); 26 // logger.info('Getting message counters before registering modem');
27 27
28 // eslint-disable-next-line no-param-reassign 28 // eslint-disable-next-line no-param-reassign
29 // modemInfo.messageSentCounter = await counters.get('MESSAGE_SENT', modemInfo); 29 // modemInfo.messageSentCounter = await counters.get('MESSAGE_SENT', modemInfo);
30 // eslint-disable-next-line no-param-reassign 30 // eslint-disable-next-line no-param-reassign
31 // modemInfo.messageReceivedCounter = await counters.get('MESSAGE_RECEIVED', modemInfo); 31 // modemInfo.messageReceivedCounter = await counters.get('MESSAGE_RECEIVED', modemInfo);
32 32
33 const requestOptions = { 33 const requestOptions = {
34 url: reportUrl(), 34 url: reportUrl(),
35 qs: { 35 qs: {
36 modem: config.name, 36 modem: config.name,
37 modem_device: config.modem.device, 37 modem_device: config.modem.device,
38 modem_imsi: modemInfo.imsi, 38 modem_imsi: modemInfo.imsi,
39 modem_msisdn: modemInfo.msisdn, 39 modem_msisdn: modemInfo.msisdn,
40 modem_network_id: modemInfo.networkId, 40 modem_network_id: modemInfo.networkId,
41 modem_network_name: modemInfo.networkName, 41 modem_network_name: modemInfo.networkName,
42 modem_signal_strength: modemInfo.signalStrength, 42 modem_signal_strength: modemInfo.signalStrength,
43 uptime: Math.floor(process.uptime()), 43 uptime: Math.floor(process.uptime()),
44 report_port: config.http_command_server.listen_port, 44 report_port: config.http_command_server.listen_port,
45 report_apikey: config.http_command_server.apikey, 45 report_apikey: config.http_command_server.apikey,
46 report_path_sms: '/sms', 46 report_path_sms: '/sms',
47 // counter_sent: modemInfo.messageSentCounter, 47 // counter_sent: modemInfo.messageSentCounter,
48 // counter_received: modemInfo.messageReceivedCounter, 48 // counter_received: modemInfo.messageReceivedCounter,
49 }, 49 },
50 }; 50 };
51 51
52 logger.info('Sending modem registration to center'); 52 logger.info('Sending modem registration to center');
53 request(requestOptions, (err, res) => { 53 request(requestOptions, (err, res) => {
54 mutex.unlock(); 54 mutex.unlock();
55 55
56 if (err) { 56 if (err) {
57 logger.warn(`Error registering modem. ${err.toString()}`); 57 logger.warn(`Error registering modem. ${err.toString()}`);
58 } else if (res.statusCode !== 200) { 58 } else if (res.statusCode !== 200) {
59 logger.warn(`SMS center respond with HTTP status code ${res.statusCode}.`); 59 logger.warn(`SMS center respond with HTTP status code ${res.statusCode}.`);
60 } 60 }
61 }); 61 });
62 } 62 }
63 } 63 }
64 64
65 module.exports = sender; 65 module.exports = sender;
66 66