This is not actually the case, the channel variables you’re looking for are available at that point in the call flow. The problem is with nesting variables inside variables. I have added a monitor script to 2 trunks on a system, one with ${}
and one without. The value you put in the "Monitor Trunk Failures’ fields is first written to sql
MariaDB [asterisk]> select trunkid, name, failscript from trunks;
+---------+--------+--------------------------+
| trunkid | name | failscript |
+---------+--------+--------------------------+
| 1 | fpbx-1 | trunkfail.agi,${AMPUSER} |
| 2 | fpbx-2 | trunkfail.agi,AMPUSER |
+---------+--------+--------------------------+
2 rows in set (0.01 sec)
Then on rebuild, these values are written to extensions_additional.conf as global variables:
[root@58448910 asterisk]# grep OUTFAIL /etc/asterisk/extensions_additional.conf
OUTFAIL_1 = trunkfail.agi,${AMPUSER}
OUTFAIL_2 = trunkfail.agi,AMPUSER
Which in turn is loaded by asterisk:
[root@58448910 asterisk]# asterisk -x "dialplan show globals" | grep OUTFAIL_
OUTFAIL_2=trunkfail.agi,AMPUSER
OUTFAIL_1=trunkfail.agi,
and those global variables are finally referenced in dialplan when the alert is triggered.
My above tests show that the entire Monitor Trunk Failures field is faithfully written to SQL and to the conf file, but Asterisk fails to load it properly if the global has the ${}
characters. Not sure if there is any way to write a global var so it references a channel var or not.
The only supported way to do this that I can think of is to use a php script and then load the phpagi libraries so you can reference the channel variables directly in the script, instead of passing as args. Realize this is easier said than done, so here is a rough start on how that might be accomplished: lgaetz-trunk-monitor.php · GitHub
With that script, trunk name is logged in full log:
[2020-06-27 16:02:17] VERBOSE[11835][C-00000001] pbx.c: Executing [continue@macro-dialout-trunk:2] AGI("PJSIP/6014-00000000", "agi://127.0.0.1/lgaetz-trunk-monitor.php") in new stack
[2020-06-27 16:02:17] VERBOSE[11835][C-00000001] res_agi.c: agi://127.0.0.1/lgaetz-trunk-monitor.php: Oubound call faled on trunk: @fpbx-1