Custome extensions

I have a custom extension for our monitoring system zabbix, it send a call via asterisk to inform us with the problem on our servers,

the problem that I should add custom extension for each problem on each server and I have many extensions there to serve all alerts,

I need to know if I can use a varibles inside customer extension so I can reduce the file and arrange it

sample of extension I use

[HOSTRECOVERY|PROBLEMPROBLEMTYPE]
exten => h,1,Hangup
exten => s,1,Set(LOOPCOUNT=0)
exten => s,n,GotoIf($[“${CDR(disposition)}” = “ANSWERED”]?begin)
exten => s,n,Answer
exten => s,n,Wait(1)
exten => s,n(begin),Set(TIMEOUT(digit)=3)
exten => s,n,Set(TIMEOUT(response)=1)
exten => s,n,agi(googletts.agi,"text to speach depenfs on the problem and hostname ",en)
exten => s,n,WaitExten(,)
exten => hang,1,Playback(vm-goodbye)
exten => hang,n,Hangup
exten => i,1,Playback(invalid)
exten => i,n,Goto(loop,1)
exten => t,1,Goto(loop,1)
exten => loop,1,Set(LOOPCOUNT=$[${LOOPCOUNT} + 1])
exten => loop,n,GotoIf($[${LOOPCOUNT} > 7]?hang,1)
exten => loop,n,Goto(HOSTRECOVERY|PROBLEMPROBLEMTYPE,s,begin)

Thanks

  1. What OS and version of Asterisk?
  2. Please provide an example of how the servers call Asterisk.*
  3. Please provide the console output executing the above snippet including the outbound call origination.*

*) Cut and paste text wrapped in pre-formatted text tags – no pictures or screen shots.

CentOS Linux release 7.8.2003 (Core)
Asterisk 16.7.0

script zabbix use to send the call to asterisk
ssh user@pbx.bisan.com ‘bash -s’ < /usr/lib/zabbix/alertscripts/alert.sh {HOST.NAME} Net PROBLEM {EVENT.NAME}

alert.sh

if [ $2 = “All” ]
then

MOBILE1=123123123

    #Create ftp file content
    /bin/echo bin > $1ftp
    /bin/echo put $1$3$4$5$2F >> $1ftp
    /bin/echo bye >> $1ftp

    #Create Extension & dialout file
    /bin/echo channel: DAHDI/g10/$MOBILE1 > $1$3$4$5$2F
    /bin/echo MaxRetries: 5  >> $1$3$4$5$2F
    /bin/echo RetryTime: 60 >> $1$3$4$5$2F
    /bin/echo WaitTime: 60 >> $1$3$4$5$2F
    /bin/echo Context: $1$3$4$5 >> $1$3$4$5$2F
    /bin/echo Extension: s >> $1$3$4$5$2F
    /bin/echo Priority: 1 >> $1$3$4$5$2F
    cp $1$3$4$5$2F /var/spool/asterisk/outgoing
    chown asterisk.asterisk /var/spool/asterisk/outgoing/$1$3$4$5$2F

fi

2023-04-28 12:21:36] VERBOSE[2567] asterisk.c: Remote UNIX connection
[2023-04-28 12:21:36] VERBOSE[6486] asterisk.c: Remote UNIX connection disconnected
[2023-04-28 12:21:36] VERBOSE[6384][C-00014478] res_agi.c: <SIP/Paltel-SIP-000284e9>AGI Script googletts.agi completed, returning 0
[2023-04-28 12:21:36] VERBOSE[6384][C-00014478] pbx.c: Executing [s@FF-Swicth-56RECOVERYHOSTPING:8] WaitExten(“SIP/Paltel-SIP-000284e9”, “,”) in new stack
[2023-04-28 12:21:37] VERBOSE[2567] asterisk.c: Remote UNIX connection
[2023-04-28 12:21:37] VERBOSE[6493] asterisk.c: Remote UNIX connection disconnected
[2023-04-28 12:21:37] VERBOSE[6384][C-00014478] pbx_builtins.c: Timeout on SIP/Paltel-SIP-000284e9, going to ‘t’
[2023-04-28 12:21:37] VERBOSE[6384][C-00014478] pbx.c: Executing [t@FF-Swicth-56RECOVERYHOSTPING:1] Goto(“SIP/Paltel-SIP-000284e9”, “loop,1”) in new stack
[2023-04-28 12:21:37] VERBOSE[6384][C-00014478] pbx_builtins.c: Goto (FF-Swicth-56RECOVERYHOSTPING,loop,1)
[2023-04-28 12:21:37] VERBOSE[6384][C-00014478] pbx.c: Executing [loop@FF-Swicth-56RECOVERYHOSTPING:1] Set(“SIP/Paltel-SIP-000284e9”, “LOOPCOUNT=1”) in new sta
ck
[2023-04-28 12:21:37] VERBOSE[6384][C-00014478] pbx.c: Executing [h@FF-Swicth-56RECOVERYHOSTPING:1] Hangup(“SIP/Paltel-SIP-000284e9”, “”) in new stack
[2023-04-28 12:21:37] VERBOSE[6384][C-00014478] pbx.c: Spawn extension (FF-Swicth-56RECOVERYHOSTPING, h, 1) exited non-zero on ‘SIP/Paltel-SIP-000284e9’
[2023-04-28 12:21:37] NOTICE[6384][C-00014478] pbx_spool.c: Call completed to SIP/Paltel-SIP/MOBILENUMBER
[2023-04-28 12:21:38] VERBOSE[2567] asterisk.c: Remote UNIX connection
[2023-04-28 12:21:38] VERBOSE[6501] asterisk.c: Remote UNIX connection disconnected
[2023-04-28 12:21:39] VERBOSE[2567] asterisk.c: Remote UNIX connection
[2023-04-28 12:21:39] VERBOSE[6508] asterisk.c: Remote UNIX connection disconnected
[2023-04-28 12:21:40] VERBOSE[6395][C-00014479] res_agi.c: <SIP/Paltel-SIP-000284ea>AGI Script googletts.agi completed, returning 0
[2023-04-28 12:21:40] VERBOSE[6395][C-00014479] pbx.c: Executing [s@FF-Swicth-56RECOVERYHOSTPING:8] WaitExten(“SIP/Paltel-SIP-000284ea”, “,”) in new stack
[2023-04-28 12:21:40] VERBOSE[2567] asterisk.c: Remote UNIX connection
[2023-04-28 12:21:40] VERBOSE[6515] asterisk.c: Remote UNIX connection disconnected
[2023-04-28 12:21:40] VERBOSE[2567] asterisk.c: Remote UNIX connection
[2023-04-28 12:21:40] VERBOSE[6524] asterisk.c: Remote UNIX connection disconnected
[2023-04-28 12:21:40] VERBOSE[6395][C-00014479] pbx.c: Spawn extension (FF-Swicth-56RECOVERYHOSTPING, s, 8) exited non-zero on ‘SIP/Paltel-SIP-000284ea’
[2023-04-28 12:21:40] VERBOSE[6395][C-00014479] pbx.c: Executing [h@FF-Swicth-56RECOVERYHOSTPING:1] Hangup(“SIP/Paltel-SIP-000284ea”, “”) in new stack
[2023-04-28 12:21:40] VERBOSE[6395][C-00014479] pbx.c: Spawn extension (FF-Swicth-56RECOVERYHOSTPING, h, 1) exited non-zero on ‘SIP/Paltel-SIP-000284ea’
[2023-04-28 12:21:40] NOTICE[6395][C-00014479] pbx_spool.c: Call completed to SIP/Paltel-SIP/MOBILENUMBER
[2023-04-28 12:21:41] VERBOSE[2567] asterisk.c: Remote UNIX connection
[2023-04-28 12:21:41] VERBOSE[6537] asterisk.c: Remote UNIX connection disconnected

you can add variables to your call_file that you then can use in the dialplan
Setvar: <var=value>
https://wiki.asterisk.org/wiki/display/AST/Asterisk+Call+Files

echo > $1$3$4$5$2F << EOL
channel: DAHDI/g10/$MOBILE1
MaxRetries: 5
RetryTime: 60
WaitTime: 60
Context: $1$3$4$5
Extension: s
Priority: 1
Setvar: GoogleTTS="Hello World"
SetVar: GoogleTTSlang=en
EOL

also you may want to clean this:

exten => h,1,Hangup
exten => s,1,Set(LOOPCOUNT=0)
exten => s,n,GotoIf($[“${CDR(disposition)}” = “ANSWERED”]?begin)
exten => s,n,Answer
exten => s,n,Wait(1)
exten => s,n(begin),Set(TIMEOUT(digit)=3)
exten => s,n,Set(TIMEOUT(response)=1)
exten => s,n,agi(googletts.agi,"text to speach depenfs on the problem and hostname ",en)

to this

exten => s,1,Set(LOOPCOUNT=0)
same => n,Answer(1000) ; if not answered answer and wait 1000ms
same => n,Set(TIMEOUT(digit)=3)
same => n,Set(TIMEOUT(response)=1)
same => n,agi(googletts.agi,"${GoogleTTS}",${GoogleTTSlang})

https://wiki.asterisk.org/wiki/display/AST/Asterisk+20+Application_Answer

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.