mirror of
https://github.com/jambonz/sbc-inbound.git
synced 2025-12-19 04:37:43 +00:00
reject calls on hosted jambonz with no active subscriptions (#191)
This commit is contained in:
@@ -295,24 +295,22 @@ module.exports = function(srf, logger) {
|
|||||||
logger.debug(`checkLimits: call count is now ${calls}, limit is ${minLimit}`);
|
logger.debug(`checkLimits: call count is now ${calls}, limit is ${minLimit}`);
|
||||||
if (calls <= minLimit) return next();
|
if (calls <= minLimit) return next();
|
||||||
|
|
||||||
if (process.env.JAMBONES_HOSTING) {
|
const accountCapacities = await lookupAccountCapacitiesBySid(account_sid);
|
||||||
const accountCapacities = await lookupAccountCapacitiesBySid(account_sid);
|
const accountLimit = accountCapacities.find((c) => c.category == 'voice_call_session');
|
||||||
const accountLimit = accountCapacities.find((c) => c.category == 'voice_call_session');
|
if (accountLimit) {
|
||||||
if (accountLimit) {
|
/* check account limit */
|
||||||
/* check account limit */
|
const limit_sessions = accountLimit.quantity;
|
||||||
const limit_sessions = accountLimit.quantity;
|
if (calls > limit_sessions) {
|
||||||
if (calls > limit_sessions) {
|
debug(`checkLimits: limits exceeded: call count ${calls}, limit ${limit_sessions}`);
|
||||||
debug(`checkLimits: limits exceeded: call count ${calls}, limit ${limit_sessions}`);
|
logger.info({calls, limit_sessions}, 'checkLimits: limits exceeded');
|
||||||
logger.info({calls, limit_sessions}, 'checkLimits: limits exceeded');
|
writeAlerts({
|
||||||
writeAlerts({
|
alert_type: AlertType.ACCOUNT_CALL_LIMIT,
|
||||||
alert_type: AlertType.ACCOUNT_CALL_LIMIT,
|
service_provider_sid: account.service_provider_sid,
|
||||||
service_provider_sid: account.service_provider_sid,
|
account_sid,
|
||||||
account_sid,
|
count: limit_sessions
|
||||||
count: limit_sessions
|
}).catch((err) => logger.info({err}, 'checkLimits: error writing alert'));
|
||||||
}).catch((err) => logger.info({err}, 'checkLimits: error writing alert'));
|
res.send(503, 'Maximum Calls In Progress');
|
||||||
res.send(503, 'Maximum Calls In Progress');
|
return req.srf.endSession(req);
|
||||||
return req.srf.endSession(req);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (trackingOn) {
|
else if (trackingOn) {
|
||||||
@@ -333,6 +331,11 @@ module.exports = function(srf, logger) {
|
|||||||
});
|
});
|
||||||
return req.srf.endSession(req);
|
return req.srf.endSession(req);
|
||||||
}
|
}
|
||||||
|
if (!account_limit && !sp_limit && process.env.JAMBONES_HOSTING) {
|
||||||
|
logger.info(`checkLimits: no active subscription found for account ${account_sid}, rejecting call`);
|
||||||
|
res.send(503, 'No Active Subscription');
|
||||||
|
return req.srf.endSession(req);
|
||||||
|
}
|
||||||
if (process.env.JAMBONES_TRACK_SP_CALLS && sp_limit > 0 && callsSP > sp_limit) {
|
if (process.env.JAMBONES_TRACK_SP_CALLS && sp_limit > 0 && callsSP > sp_limit) {
|
||||||
logger.info({callsSP, sp_limit}, 'checkLimits: service provider limits exceeded');
|
logger.info({callsSP, sp_limit}, 'checkLimits: service provider limits exceeded');
|
||||||
writeAlerts({
|
writeAlerts({
|
||||||
|
|||||||
14
package-lock.json
generated
14
package-lock.json
generated
@@ -11,7 +11,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-auto-scaling": "^3.549.0",
|
"@aws-sdk/client-auto-scaling": "^3.549.0",
|
||||||
"@aws-sdk/client-sns": "^3.549.0",
|
"@aws-sdk/client-sns": "^3.549.0",
|
||||||
"@jambonz/db-helpers": "^0.9.7",
|
"@jambonz/db-helpers": "^0.9.9",
|
||||||
"@jambonz/digest-utils": "^0.0.5",
|
"@jambonz/digest-utils": "^0.0.5",
|
||||||
"@jambonz/http-health-check": "^0.0.1",
|
"@jambonz/http-health-check": "^0.0.1",
|
||||||
"@jambonz/realtimedb-helpers": "^0.8.8",
|
"@jambonz/realtimedb-helpers": "^0.8.8",
|
||||||
@@ -1410,9 +1410,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@jambonz/db-helpers": {
|
"node_modules/@jambonz/db-helpers": {
|
||||||
"version": "0.9.7",
|
"version": "0.9.9",
|
||||||
"resolved": "https://registry.npmjs.org/@jambonz/db-helpers/-/db-helpers-0.9.7.tgz",
|
"resolved": "https://registry.npmjs.org/@jambonz/db-helpers/-/db-helpers-0.9.9.tgz",
|
||||||
"integrity": "sha512-5qN/CJZJXpbMkMn+8gFn8PpQ0ZImZxp1EjKyxLUlmMn+xgjeNb29c3pjeVt/6EQnBB65jAax6TNsVzVIfpvE2w==",
|
"integrity": "sha512-aUr7kq78NUiOg7/aqFW+KseHqwujtThaJHu7O1Bp5OznHLMDNFB8jJJDs3LGIqaRHEM/c4oaKtpKA4wahgP99w==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cidr-matcher": "^2.1.1",
|
"cidr-matcher": "^2.1.1",
|
||||||
"debug": "^4.3.4",
|
"debug": "^4.3.4",
|
||||||
@@ -7907,9 +7907,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@jambonz/db-helpers": {
|
"@jambonz/db-helpers": {
|
||||||
"version": "0.9.7",
|
"version": "0.9.9",
|
||||||
"resolved": "https://registry.npmjs.org/@jambonz/db-helpers/-/db-helpers-0.9.7.tgz",
|
"resolved": "https://registry.npmjs.org/@jambonz/db-helpers/-/db-helpers-0.9.9.tgz",
|
||||||
"integrity": "sha512-5qN/CJZJXpbMkMn+8gFn8PpQ0ZImZxp1EjKyxLUlmMn+xgjeNb29c3pjeVt/6EQnBB65jAax6TNsVzVIfpvE2w==",
|
"integrity": "sha512-aUr7kq78NUiOg7/aqFW+KseHqwujtThaJHu7O1Bp5OznHLMDNFB8jJJDs3LGIqaRHEM/c4oaKtpKA4wahgP99w==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"cidr-matcher": "^2.1.1",
|
"cidr-matcher": "^2.1.1",
|
||||||
"debug": "^4.3.4",
|
"debug": "^4.3.4",
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
"jslint:fix": "npm run jslint --fix"
|
"jslint:fix": "npm run jslint --fix"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@jambonz/db-helpers": "^0.9.7",
|
"@jambonz/db-helpers": "^0.9.9",
|
||||||
"@jambonz/http-health-check": "^0.0.1",
|
"@jambonz/http-health-check": "^0.0.1",
|
||||||
"@jambonz/realtimedb-helpers": "^0.8.8",
|
"@jambonz/realtimedb-helpers": "^0.8.8",
|
||||||
"@jambonz/rtpengine-utils": "^0.4.4",
|
"@jambonz/rtpengine-utils": "^0.4.4",
|
||||||
|
|||||||
Reference in New Issue
Block a user