CDR variable problem

Dear Asterisk users,

I have been writing an interface to allow Guard Duty records for each department in my company.

I am using DBQuery module for that, but I have a problem concerning a variable in the dialplan !

Let me explain how I work :

Each department has a emergency number assigned :

2020 = NGN
2021 = TEL
2022 = IT

The engineer that is on call logs in the queue/agent of his department extension.

Example : XXX is on call for NGN : he calls AgentCallBackLogin, logs in extension 2020 with his mobile phone.

When our NOC wants to reach the on call engineer, he just needs to dial 2020 or public number going to 2020 and call is directly queued to the mobile phone of the logged in engineer.

Dialplan :

[restricted]

;GUARDUTY ADDON : incoming calls sent to [guarduty]
[color=red]exten => _202[0-2],1,Goto(guarduty,${EXTEN},1)[/color]

[guarduty]

; Call following, selecting database where to record the call
exten => _202[0-2],1,ExecIf($[${EXTEN}=2020]|Set|GLOBAL(table)=“guarduty-ngn”)
exten => _202[0-2],2,ExecIf($[${EXTEN}=2021]|Set|GLOBAL(table)=“guarduty-tel”)
exten => _202[0-2],3,ExecIf($[${EXTEN}=2022]|Set|GLOBAL(table)=“guarduty-it”)
[color=red]exten => _202[0-2],4,Queue(${EXTEN},r)[/color]
exten => _202[0-2],5,Hangup()

; Call recording to database on Hangup(), then clearing engineer variable
exten => h,1,DBQuery(${table},(${CDR(clid)},${CDR(src)},${CDR(dst)},[color=red]${engineer}[/color],${CDR(disposition)}))
exten => h,2,Set(GLOBAL(engineer)="")

[queuerelay]
include => queuelondon

[color=red]exten => 202[0-2],1,Set(GLOBAL(engineer)=${EXTEN})[/color]
exten => 202[0-2],2,Dial(SIP/${EXTEN},rt)
exten => 202[0-2],3,Hangup()

in QUEUERELAY I set the global variable ENGINEER to the extension logged in the 2020 (so, a mobile number). This is to assign the calls by number, to each engineer. Here is my problem, sometimes the variable is filled with the good data, sometimes when the engineer hangup, the variable is filled with something else, maybe because it’s global ?

In GUARDUTY, I just set the table name for the database writing, just here for your information.

How could I take care of this to be sure that each variable is linked to a call and cannot be modified if another call is done during the first call… ?

If I call 2020 :

– Executing [h@guarduty:1] DBQuery(“SIP/2069-a3554f28”, “guarduty-ngn|(”—" <3271XX2069>|3271XX2069|2020[color=red]||[/color]ANSWERED)") in new stack
– Executing [h@guarduty:2] Set(“SIP/2069-a3554f28”, “GLOBAL(engineer)=”"") in new stack

Between the two red | | , there should be the $engineer variable displayed.

[ul]Is it a way to use variable that are linked for each call (such as CDR variables) ?
Is there a variable, in CDR variables, that can be used to get the number of an agent logged in a queue ?[/ul]

Thank you very much for your assistance.

My problem to go deeper is that I use several contexts to make the calls go through, and it is in the last context that now I am setting the engineer variable :

[defver]

exten => _00.,1,Set(GLOBAL(engineer)=${EXTEN})
exten => _00.,2,Dial(SIP/${EXTEN:2}@172.16.100.100,)
exten => _00.,3,Goto(s-${DIALSTATUS},1)

This is for outgoing calls, so 2020 send to queue and queue dials mobile number sending it to our soft switch (here up).

The problem is that : GLOBAL engineer is modified in case of another call go through the outgoing before the first one hangup.

If I set it without GLOBAL, the hangup does not find the variable as this one has not the same call ID link.

-- Executing [2020@be:1] Set("SIP/2069-b50fcc98", "CALLERID(num)=003271492069") in new stack
-- Executing [2020@be:2] Goto("[b]SIP/2069-b50fcc98[/b]", "open|2020|1") in new stack
-- Goto (open,2020,1)
-- Executing [2020@open:1] Goto("[b]SIP/2069-b50fcc98[/b]", "guarduty|2020|1") in new stack
-- Goto (guarduty,2020,1)
-- Executing [2020@guarduty:1] ExecIf("[b]SIP/2069-b50fcc98[/b]", "1|Set|table="guarduty-ngn"") in new stack
-- Executing [2020@guarduty:2] ExecIf("[b]SIP/2069-b50fcc98[/b]", "0|Set|table="guarduty-tel"") in new stack
-- Executing [2020@guarduty:3] ExecIf("[b]SIP/2069-b50fcc98[/b]", "0|Set|table="guarduty-it"") in new stack
-- Executing [2020@guarduty:4] Queue("[b]SIP/2069-b50fcc98[/b]", "2020|r") in new stack
-- outgoing agentcall, to agent '2020', on [b]

[color=red]‘Local/32479XXX860@queuerelay-7304,1’[/color][/b]
– Executing [32479XXX860@queuerelay:1] Goto("[color=red]Local/32479XXX860@queuerelay-7304,2[/color]", “open|0032479XXX860|1”) in new stack
– Goto (open,0032479XXX860,1)
– Executing [0032479XXX860@open:1] Set(“Local/32479XXX860@queuerelay-7304,2”, “GLOBAL(engineer)=0032479XXX860”) in new stack
== Setting global variable ‘engineer’ to ‘0032479XXX860’
– Executing [0032479XXX860@open:2] Dial("[color=red]Local/32479XXX860@queuerelay-7304[/color],2", “SIP/32479XXX860@172.16.100.100||”) in new stack
– Called 32479XXX860@172.16.100.100
== Spawn extension (open, 0032479XXX860, 2) exited non-zero on ‘Local/32479XXX860@queuerelay-7304,2’

== Spawn extension (guarduty, 2020, 4) exited non-zero on ‘SIP/2069-b50fcc98’
– Executing [h@guarduty:1] DBQuery(“SIP/2069-b50fcc98”, “guarduty-ngn|(“Cedric Brohee” <3271492069>|3271XX2069|2020|0032479XXX860|NO ANSWER)”) in new stack
– Executing [h@guarduty:2] Set(“SIP/2069-b50fcc98”, “GLOBAL(engineer)=”"") in new stack
== Setting global variable ‘engineer’ to ‘’

Well … last reply as I found the solution :smile:

[guarduty]

; Call following
exten => _202[0-2],1,ExecIf($[${EXTEN}=2020]|Set|table=“guarduty-ngn”)
exten => _202[0-2],2,ExecIf($[${EXTEN}=2020]|Set|engineer=${AGENT(2020:exten)})
exten => _202[0-2],3,ExecIf($[${EXTEN}=2021]|Set|table=“guarduty-tel”)
exten => _202[0-2],4,ExecIf($[${EXTEN}=2021]|Set|engineer=${AGENT(2021:exten)})
exten => _202[0-2],5,ExecIf($[${EXTEN}=2022]|Set|table=“guarduty-it”)
exten => _202[0-2],6,ExecIf($[${EXTEN}=2022]|Set|engineer=${AGENT(2022:exten)})
exten => _202[0-2],7,Queue(${EXTEN},r)
exten => _202[0-2],8,Hangup()

; Call to set cases to >CLOSED< state
;exten => _203[0-2],1,ExecIf($[${EXTEN}=2030]|Set|GLOBAL(table)=“guarduty-ngn”)
;exten => _203[0-2],2,ExecIf($[${EXTEN}=2031]|Set|GLOBAL(table)=“guarduty-tel”)
;exten => _203[0-2],3,ExecIf($[${EXTEN}=2032]|Set|GLOBAL(table)=“guarduty-it”)
;exten => _203[0-2],4,Background(vm-msgsaved)
;exten => _203[0-2],5,Set(GLOBAL(engineer)=“CLOSED”)
;exten => _203[0-2],6,Hangup()

; Call recording to database on Hangup()
;exten => h,1,Set(engineer=${AGENT(2020:exten)})
exten => h,1,DBQuery(${table},(${CDR(clid)},${CDR(src)},${CDR(dst)},${engineer},${CDR(disposition)}))