diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 6744e428..ac92e429 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1 +1 @@ -- Upgrade smpp dep from 0.3.1 to 0.5.1 +- Upgrade smpp dep from 0.3.1 to 0.5.1 \ No newline at end of file diff --git a/Changelog b/Changelog index 81d41afb..d428fd98 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,18 @@ +1.34.0 (July 30th, 2024) + +- Fix: smtpConfig after error in emailAction rule (#798) + +1.33.0 (July 29th, 2024) + +- Fix: do not search in entities collection with strict mode by non_signal checker (#793) +- Fix: do not try cast entity id and entity type in update rules when expand parameters of rule to avoid BadRequest en CB tries to update that entities (#791) +- Fix: do not invoke calback twice when error about trust not found in trustConf (#790) + +1.32.0 (June 13th, 2024) + +- Add: Send multiple sms when multiple destination in sms action +- Fix: upgrade rule in mongo using service and subservice to avoid match with other rule (#783) + 1.31.0 (June 11th, 2024) - Fix: release transport resources of nodemailer after send email diff --git a/lib/models/emailAction.js b/lib/models/emailAction.js index 50721584..9e5ac7ab 100644 --- a/lib/models/emailAction.js +++ b/lib/models/emailAction.js @@ -80,10 +80,10 @@ function SendMail(action, event, callback) { smtpConfig = config.smtp; msgFromConfig = 'from global'; } - var smtpAuth = smtpConfig.auth; - smtpConfig.auth = { user: 'UUU', pass: 'XXX' }; + var smtpAuth = smtpConfig.auth ? Object.assign({}, smtpConfig.auth) : undefined; // force clone + smtpConfig.auth = { user: 'UUU', pass: 'XXX' }; // fake auth for log purposes logger.debug('Using smtp transporter %j config: %j', msgFromConfig, smtpConfig); - smtpConfig.auth = smtpAuth; + smtpConfig.auth = smtpAuth; // restore auth transporter = nodemailer.createTransport(smtpTransport(smtpConfig)); metrics.IncMetrics(event.service, event.subservice, metrics.actionEmail); @@ -105,6 +105,7 @@ function SendMail(action, event, callback) { }; opt2log.smtp.auth = { user: 'UUU', pass: 'XXX' }; myutils.logErrorIf(err, util.format('emailAction.SendMail %j', opt2log)); + smtpConfig.auth = smtpAuth; // ensure smtpConfig.auth is not tainted alarm.raise(alarm.EMAIL); } else { metrics.IncMetrics(event.service, event.subservice, metrics.okActionEmail); diff --git a/lib/models/entitiesStore.js b/lib/models/entitiesStore.js index 423fcf86..2e0ef42a 100644 --- a/lib/models/entitiesStore.js +++ b/lib/models/entitiesStore.js @@ -151,7 +151,7 @@ function findSilentEntitiesByMongo(service, subservice, ruleData, alterFunc, cal async.waterfall( [ - db.collection.bind(db, entitiesCollectionName, { strict: true }), + db.collection.bind(db, entitiesCollectionName, { strict: false }), function(col, cb) { col.find(criterion) .batchSize(config.orionDb.batchSize) diff --git a/lib/models/keystone.js b/lib/models/keystone.js index 1fd2516b..0d23eb85 100644 --- a/lib/models/keystone.js +++ b/lib/models/keystone.js @@ -59,8 +59,8 @@ function getToken(trust, callback) { // check trust was found or log it if (!trustConf) { - logger.error('Trust %s not found in configTrust file with content %s', trust, configTrust); - callback(new errors.TokenRetrievalError(trust, 'trust not found' + trust)); + logger.error('Trust %s not found in configTrust file', trust); + throw errors.TokenRetrievalError(trust, 'trust not found' + trust); } var options = { url: 'http://' + trustConf.host + ':' + trustConf.port + '/v3/auth/tokens', diff --git a/lib/models/rulesStore.js b/lib/models/rulesStore.js index 8d01fd96..2926f2b9 100644 --- a/lib/models/rulesStore.js +++ b/lib/models/rulesStore.js @@ -190,7 +190,11 @@ module.exports = { db.collection.bind(db, rulesCollectionName, { strict: true }), function(col, cb) { col.findOneAndUpdate( - { name: id }, + { + name: id, + service: r.service, + subservice: r.subservice + }, { $set: r }, { upsert: false, diff --git a/lib/models/smsAction.js b/lib/models/smsAction.js index e1134aaa..c2d4a46a 100644 --- a/lib/models/smsAction.js +++ b/lib/models/smsAction.js @@ -71,10 +71,6 @@ function doIt(action, event, callback) { if (options.sms && options.sms.from) { from = options.sms.from; } - msg = { to: buildTo(options.to), message: options.text, from: from }; - - metrics.IncMetrics(event.service, event.subservice, metrics.actionSMS); - var url = config.sms.URL; var apiKey = config.sms.API_KEY; var apiSecret = config.sms.API_SECRET; @@ -89,33 +85,41 @@ function doIt(action, event, callback) { apiSecret = options.sms.API_SECRET; } } - myutils.requestHelper( - 'post', - { - url: url, - json: true, - body: msg, - headers: { - 'User-Agent': 'request', - API_KEY: apiKey, - API_SECRET: apiSecret - } - }, - function(err, data) { - myutils.logErrorIf(err, util.format('%s -> %s', url, msg.to)); - if (err) { - metrics.IncMetrics(event.service, event.subservice, metrics.failedActionSMS); + metrics.IncMetrics(event.service, event.subservice, metrics.actionSMS); - alarm.raise(alarm.SMS); - } else { - metrics.IncMetrics(event.service, event.subservice, metrics.okActionSMS); + var tos = buildTo(options.to); - alarm.release(alarm.SMS); + for (var singleto of tos) { + msg = { to: [singleto], message: options.text, from: config.sms.from }; + myutils.requestHelper( + 'post', + { + url: url, + json: true, + body: msg, + headers: { + 'User-Agent': 'request', + API_KEY: apiKey, + API_SECRET: apiSecret + } + }, + function(err, data) { // jshint ignore:line + myutils.logErrorIf(err, util.format('%s -> %s', url, msg.to)); + if (err) { + metrics.IncMetrics(event.service, event.subservice, metrics.failedActionSMS); + alarm.raise(alarm.SMS); + } else { + metrics.IncMetrics(event.service, event.subservice, metrics.okActionSMS); + alarm.release(alarm.SMS); + } + logger.info('smsAction.SendSMS done url:%s result:%j, msg: %j', url, err || data, msg); + if (tos[tos.length - 1] === singleto) { + // ensure callback is returned just one time + return callback(err, data); + } } - logger.info('smsAction.SendSMS done url:%s result:%j, msg: %j', url, err || data, msg); - return callback(err, data); - } - ); + ); + } } catch (ex) { metrics.IncMetrics(event.service, event.subservice, metrics.failedActionSMS); diff --git a/lib/models/updateAction.js b/lib/models/updateAction.js index b9cbf3f4..1c916c25 100644 --- a/lib/models/updateAction.js +++ b/lib/models/updateAction.js @@ -169,8 +169,9 @@ function processOptionParams(action, event) { changes[key].metadata = theMeta; } }); - changes.id = myutils.expandVar(action.parameters.id, event, true); - changes.type = myutils.expandVar(action.parameters.type, event, true); + // Do not expandVar with trycast, since entity id and type should be always string values types + changes.id = myutils.expandVar(action.parameters.id, event, false); + changes.type = myutils.expandVar(action.parameters.type, event, false); logger.debug('processOptionParams changes: %j', changes); return changes; } @@ -477,7 +478,7 @@ function makeTokenListenerFunc(action, event, version, callback) { if (error || !token) { return callback(error); } else { - logger.debug('tokenHandlerFunc retrying with', token); + logger.debug('tokenHandlerFunc retrying with %s', token); return doRequestV2(action, event, token, function cbDoReqUpdAxn(error, data) { callback(error, data); }); diff --git a/package.json b/package.json index f743451d..4b65ede2 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "perseo", "description": "IOT CEP front End", "license": "AGPL-3.0-only", - "version": "1.31.0-next", + "version": "1.34.0-next", "author": { "name": "crbrox", "email": "carlos.romerobrox@telefonica.com" @@ -60,8 +60,8 @@ "keywords": [], "dependencies": { "async": "2.6.4", - "body-parser": "~1.18.2", - "express": "4.19.2", + "body-parser": "~1.20.3", + "express": "4.20.0", "logops": "2.1.2", "mongodb": "3.6.12", "ngsijs": "1.4.1",