Commit f24458bdb8bd29e8b25768325b8929643ba28b69

Authored by Adhidarma Hadiwinoto
1 parent b708801611
Exists in master

Queues and providers gona test

Showing 2 changed files with 16 additions and 2 deletions Inline Diff

bin/smstools-config-install
1 #!/bin/bash 1 #!/bin/bash
2 set -x 2 set -x
3 3
4 DIRFILE=`dirname "$0"` 4 DIRFILE=`dirname "$0"`
5 cd "$DIRFILE/.." 5 cd "$DIRFILE/.."
6 echo `pwd` 6 echo `pwd`
7 7
8 TARGETFILE=$1 8 TARGETFILE=$1
9 if [ -z "$TARGETFILE" ]; then 9 if [ -z "$TARGETFILE" ]; then
10 exit 0 10 exit 0
11 fi 11 fi
12 12
13 sudo install smsd.conf.tmp "$TARGETFILE" 13 sudo install smsd.conf.tmp "$TARGETFILE"
14 sudo systemctl restart sms3 14 # sudo systemctl restart sms3
15 15
lib/smstools-config/creator.js
1 const moment = require('moment'); 1 const moment = require('moment');
2 const config = require('komodo-sdk/config'); 2 const config = require('komodo-sdk/config');
3 const { orderBy } = require('natural-orderby'); 3 const { orderBy } = require('natural-orderby');
4 const smstoolsConfig = require('./config-file'); 4 const smstoolsConfig = require('./config-file');
5 const queuesAndProviders = require('./queues-and-providers');
5 6
6 function modemNames() { 7 function modemNames() {
7 const modems = []; 8 const modems = [];
8 9
9 // eslint-disable-next-line no-restricted-syntax 10 // eslint-disable-next-line no-restricted-syntax
10 for (const [key, value] of Object.entries(smstoolsConfig.modems || {})) { 11 for (const [key, value] of Object.entries(smstoolsConfig.modems || {})) {
11 if (value && !value.disabled) modems.push(key); 12 if (value && !value.disabled) modems.push(key);
12 } 13 }
13 14
14 return modems; 15 return modems;
15 } 16 }
16 17
17 function modemEntries() { 18 function modemEntries() {
18 const modems = orderBy(modemNames()); 19 const modems = orderBy(modemNames());
19 const retval = []; 20 const retval = [];
20 21
21 modems.forEach((modemName) => { 22 modems.forEach((modemName) => {
22 const modem = smstoolsConfig.modems[modemName]; 23 const modem = smstoolsConfig.modems[modemName];
23 24
25 let queuesLine = '';
26 if (queuesAndProviders.hasQueues()) {
27 const queues = queuesAndProviders.getModemQueueName(modemName);
28 if (queues && queues.length) {
29 queuesLine = `queues = ${queues.join(', ')}`;
30 }
31 }
32
24 const modemEntry = ` 33 const modemEntry = `
25 [${modemName}] 34 [${modemName}]
26 device = ${modem.device} 35 device = ${modem.device}
27 outgoing = ${modem.outgoing ? 'yes' : 'no'} 36 outgoing = ${modem.outgoing ? 'yes' : 'no'}
37 ${queuesLine}
28 `.trim(); 38 `.trim();
29 39
30 retval.push(modemEntry); 40 retval.push(modemEntry);
31 }); 41 });
32 42
33 return retval; 43 return retval;
34 } 44 }
35 45
36 module.exports = () => { 46 module.exports = async () => {
47 const queuesAndProvidersStr = queuesAndProviders.hasQueues() ? (await queuesAndProviders.dump()) : '';
48
37 const newContent = ` 49 const newContent = `
38 # Generated by komodo-center-smstools based on config timestamp ${moment(smstoolsConfig.ts).format('YYYY-MM-DD HH:mm:ss')} 50 # Generated by komodo-center-smstools based on config timestamp ${moment(smstoolsConfig.ts).format('YYYY-MM-DD HH:mm:ss')}
39 # Do not edit this file manually 51 # Do not edit this file manually
40 52
41 devices = ${orderBy(modemNames()).join(',')} 53 devices = ${orderBy(modemNames()).join(',')}
42 logfile = ${config.smstools_logfile || config.smstools_log_file || '/var/log/smsd/smsd.log'} 54 logfile = ${config.smstools_logfile || config.smstools_log_file || '/var/log/smsd/smsd.log'}
43 loglevel = ${smstoolsConfig.loglevel || 5} 55 loglevel = ${smstoolsConfig.loglevel || 5}
44 errorsleeptime = ${config.smstools_errorsleeptime || 10} 56 errorsleeptime = ${config.smstools_errorsleeptime || 10}
45 blockafter = ${config.smstools_blockafter || 3} 57 blockafter = ${config.smstools_blockafter || 3}
46 blocktime = ${config.smstools_blocktime || 3600} 58 blocktime = ${config.smstools_blocktime || 3600}
47 smart_logging = yes 59 smart_logging = yes
48 autosplit = ${(config.smstools_autosplit !== undefined && config.smstools_autosplit !== null) ? config.smstools_autosplit : 1} 60 autosplit = ${(config.smstools_autosplit !== undefined && config.smstools_autosplit !== null) ? config.smstools_autosplit : 1}
49 user = ${smstoolsConfig.user || 'smstools'} 61 user = ${smstoolsConfig.user || 'smstools'}
50 group = ${smstoolsConfig.group || 'smstools'} 62 group = ${smstoolsConfig.group || 'smstools'}
51 eventhandler = ${config.smstools_eventhandler || '/var/lib/smstools/centers/smstools/bin/smstools-eventhandler.js'} 63 eventhandler = ${config.smstools_eventhandler || '/var/lib/smstools/centers/smstools/bin/smstools-eventhandler.js'}
52 stats_interval = ${config.smstools_stats_interval || 60} 64 stats_interval = ${config.smstools_stats_interval || 60}
53 stats = ${config.smstools_stats || '/var/log/smsd/smsd_stats'} 65 stats = ${config.smstools_stats || '/var/log/smsd/smsd_stats'}
54 sent = /var/spool/sms/sent 66 sent = /var/spool/sms/sent
55 failed = /var/spool/sms/failed 67 failed = /var/spool/sms/failed
56 ${smstoolsConfig.customConfig || ''} 68 ${smstoolsConfig.customConfig || ''}
57 69
70 ${queuesAndProvidersStr}
71
58 [default] 72 [default]
59 sentsleeptime = ${config.smstools_sentsleeptime || 0} 73 sentsleeptime = ${config.smstools_sentsleeptime || 0}
60 send_delay = ${config.smstools_send_delay || 0} 74 send_delay = ${config.smstools_send_delay || 0}
61 incoming = yes 75 incoming = yes
62 regular_run_interval = 60 76 regular_run_interval = 60
63 regular_run_cmd = AT+CGSN 77 regular_run_cmd = AT+CGSN
64 regular_run_cmd = AT+CIMI 78 regular_run_cmd = AT+CIMI
65 regular_run_cmd = AT+COPS? 79 regular_run_cmd = AT+COPS?
66 regular_run_statfile = /var/spool/sms/regular_run/modemname 80 regular_run_statfile = /var/spool/sms/regular_run/modemname
67 message_limit = ${config.smstools_message_limit || 5} 81 message_limit = ${config.smstools_message_limit || 5}
68 message_count_clear = ${config.smstools_message_count_clear || 1} 82 message_count_clear = ${config.smstools_message_count_clear || 1}
69 83
70 ${modemEntries().join('\n\n')} 84 ${modemEntries().join('\n\n')}
71 85
72 # end of configuration file 86 # end of configuration file
73 `; 87 `;
74 return `${newContent.trim()}\n`; 88 return `${newContent.trim()}\n`;
75 }; 89 };
76 90