-
Problem report
-
Resolution: Fixed
-
Trivial
-
None
-
None
-
Sprint 76 (May 2021)
-
1
For detection of active channels per trunk following JS code is used:
response = Ami.request(url, 'command&command=core%20show%20channels'); channels = response.body; var fields = { active_channels: 'active channels?', active_calls: 'active calls?', calls_processed: 'calls? processed' };
So first - channels is filled with result of 'core show channels' command. After that for each trunk active channels is searched in 'channels' with:
asterisk.pjsip.trunks.forEach(function (trunk) { var active_channels = channels.match(new RegExp(' PJSIP/' + trunk.ObjectName.split('/')[0], 'g')); trunk.active_channels = (active_channels === null) ? 0 : active_channels.length; });
Problem is that 'core show channels' output channel name is limited to 20 characters (including PJSIP/):
Action: Command Command: core show channels Response: Success Message: Command output follows Output: Channel Location State Application(Data) Output: PJSIP/1000-0000004c 141@from-internal:1 Ringing AppDial((Outgoing Line)) Output: *PJSIP/trunk_+3754478* s@macro-dial:24 Ring Dial(PJSIP/1000/sip:[email protected] Output: 2 active channels Output: 1 active call Output: 48 calls processed
But trunk name is longer than that:
Action: PJSIPShowEndpoints Response: Success EventList: start Message: A listing of Endpoints follows, presented as EndpointList events Event: EndpointList ObjectType: endpoint *ObjectName: trunk_+375447889910* <...skip...> DeviceState: Not in use
So, if trunk naming is 'trunk_'+ full number - Active channels is always zero.
If we use core show channels concise
We receive following with full channel name:
freepbxtst*CLI> core show channels concise PJSIP/1000-00000052!from-internal!141!1!Ringing!AppDial!(Outgoing Line)!1000!!!3!8!!1620540014.84 *PJSIP/trunk_+375447889917-00000051*!macro-dial!s!24!Ring!Dial!PJSIP/1000/sip:[email protected]:42034;ob,15,HhtrQ(NO_ANSWER)M(auto-blkvm)b(func-apply-sipheaders^s^1),!+375296521507!!!3!9!!1620540013.83
Also if trunk name contains reserved characters (+ in my case) in must be escaped.
Following patch fixes that (not tested with IAX2):
--- asterisk.js.orig 2021-02-01 18:27:04.004398291 +0300 +++ asterisk.js 2021-05-09 09:53:01.097621580 +0300 @@ -81,6 +82,10 @@ } }; +function escapeRegExp(text) { + return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); +} + function block2Object(text) { var fields = [], dict = {}; @@ -138,7 +143,7 @@ } }); asterisk.sip.trunks.forEach(function (trunk) { - var active_channels = channels.match(new RegExp(' SIP/' + trunk.ObjectName.split('/')[0], 'g')); + var active_channels = full_channels.match(new RegExp(escapeRegExp('SIP/' + trunk.ObjectName.split('/')[0]), 'g')); trunk.active_channels = (active_channels === null) ? 0 : active_channels.length; }); } @@ -166,7 +171,7 @@ }); asterisk.iax.online = asterisk.iax.total - asterisk.iax.offline; asterisk.iax.trunks.forEach(function (trunk) { - var active_channels = channels.match(new RegExp('( IAX2/' + trunk.ObjectName.split('/')[0] + + var active_channels = full_channels.match(new RegExp('( IAX2/' + trunk.ObjectName.split('/')[0] + '| IAX2/' + trunk.ObjectUsername + ')', 'g')); trunk.active_channels = (active_channels === null) ? 0 : active_channels.length; }); @@ -187,11 +192,19 @@ }); asterisk.pjsip.available = asterisk.pjsip.total - asterisk.pjsip.unavailable; asterisk.pjsip.trunks.forEach(function (trunk) { - var active_channels = channels.match(new RegExp(' PJSIP/' + trunk.ObjectName.split('/')[0], 'g')); + var active_channels = full_channels.match(new RegExp(escapeRegExp('PJSIP/' + trunk.ObjectName.split('/')[0]), 'g')); trunk.active_channels = (active_channels === null) ? 0 : active_channels.length; }); } @@ -230,6 +243,9 @@ calls_processed: 'calls? processed' }; +response = Ami.request(url, 'command&command=core%20show%20channels%20concise'); +full_channels = response.body; + Object.keys(fields).forEach(function (field) { var match = channels.match('(\\d+) ' + fields[field]); if (match !== null && typeof match[1] !== 'undefined') {
- is duplicated by
-
ZBX-19492 Asterisk Template Incorrect Reload Trigger
- Closed