Asterisk & History Info

Hey guys

I am pretty new in Asterisk and still using my Freepbx but configuring now most of it in my custom dialplan. I connected the Asterisk to my Avaya Session Manager and my Avaya Communication Manager.
If I am sending calls from CM via SM to Asterisk, I want to make use of some information from the History fields in the invite (highlited):

Is there any way to do so? I need to check the previously called device (+58843 in my example)…

TIA
Cheers

There is no built in support for that header in either chan_sip or chan_pjsip. The only option would be to use the header retrieval of the respective channel driver to get it from the INVITE. In the case of chan_pjsip this is the PJSIP_HEADER[1] dialplan function. You would then need to parse and interpret it yourself.

[1] https://wiki.asterisk.org/wiki/display/AST/Asterisk+14+Function_PJSIP_HEADER

1 Like

Hey jcolp

As I wrote before, I am very new to Asterisk. I am also not a native english speaker… I am German…
Would you mind giving me a hint on how to put this history info into an Asterisk variable?

TIA
Cheers

https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Function_PJSIP_HEADER

https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+Function_SIP_HEADER

Hey guys

I am struggeling right from the beginning… :frowning:

Wanted to start with the example out of the Asterisk documentation and just write the content of a sip header “From” read-out into a file. Did it this way in my extensions_custom.conf:

[CallDisplayOnTV]

displays incoming calls to desired extensions in CM on TV and logs to file

exten => 90999,1,NoOp
exten => 90999,n,Set(mysipvar=${PJSIP_HEADER(read,From)})
exten => 90999,n,System(echo “${STRFTIME(${EPOCH},%d.%m.%Y, %H:%M:%S)} - ${mysipvar}” >> /var/log/asterisk/Sascha-Sipvar.log)
exten => 90999,n,Macro(CallDisplayOnTV)

After calling a station (which has kind of “double call” administered in my CM to 90999) I get a file output, but just with the time and date. Seems that my variable “mysipvar” does not have any content:

[root@VoIPServer ~]# cat /var/log/asterisk/Sascha-Sipvar.log
23.02.2017, 12:26:53 -
23.02.2017, 12:31:27 -
[root@VoIPServer ~]#

Where is my mistake?

TIA

I’d suggest adding a step which does a NoOp of the value ${mysipvar} to confirm that the contents are as you expect before the call to System.

Like this?

exten => 90999,n,Set(mysipvar=${PJSIP_HEADER(read,From)})
exten => 90999,n,NoOp
exten => 90999,n,System(echo “${STRFTIME(${EPOCH},%d.%m.%Y, %H:%M:%S)} - ${mysipvar}” >> /var/log/asterisk/Sascha-Sipvar.log)

No change…

No, you have to have NoOp output the value like so:

NoOp(${mysipvar})

If that does not contain the value then the problem is with PJSIP_HEADER. If it does then the problem is with your use of System.

This helps narrow it down.

Okay…

Hope I picked the proper output from log:

[2017-02-23 14:34:22] VERBOSE[23236][C-0000007c] pbx.c: Executing [90999@CallDisplayOnTV:3] NoOp(“SIP/AvayaSessionManager-0000007c”, “”) in new stack

Seems that the value indeeed is empty, right?

Yes, because you are using chan_sip and not chan_pjsip. The PJSIP_HEADER dialplan function is for chan_pjsip. You need to use SIP_HEADER which @david551 linked earlier.

Where do you see that from this log output?

Checking the SIP_Header documentation it seems to be very limited… pjsip offers more examples…
How - for my example - can you translate the line to get my variable filled with a value?

Also it seems for me chan_sip seems to be outdated? Can I easlily switch between those two versions?

Cheers

I can see you are using the SIP channel driver based on the name of the channel: SIP/AvayaSessionManager-0000007c

If you were using PJSIP it would start with PJSIP/

I haven’t used SIP_HEADER before but the documentation shows that it would be ${SIP_HEADER(From)}

As for easily switching they take completely different configuration files, so you would need to rewrite your sip.conf into pjsip.conf

Thanks, jcolp!

Will try. As this is a FreePBX with a GUI, this seems to be able to be changed via the Web interface somehow. But will try your suggestion first.

Wow!

Seems to work now basically :wink:

Output of my logfile now has some more information:

23.02.2017, 14:55:30 - sip:000496158xxxxx@sip.saschakamm.local;tag=bcd63e2cf9cf41e6bb720c29b8fde3

Now I can start playing around with the fields I am really looking for :wink:

Thanks for your support!

Again: WOW! :smiley:

Works also with the History-Info field:

23.02.2017, 15:01:17 - sip:+58176@sip.saschakamm.local;index=1

Thanks again. Now I just need to parse the string into the values I need to work on with them!

Cheers

Here I am again…

This is where I am currently:

exten => s,n,Set(sipinvitehistory3=${SIP_HEADER(History-Info,3)})
exten => s,n,Set(historyname=${sipinvitehistory3:0:8}
exten => s,n,Set(historynumber=${sipinvitehistory3:14:6}
exten => s,n,System(echo “${STRFTIME(${EPOCH},%d.%m.%Y, %H:%M:%S)} - ${historyname} - ${historynumber}” >> /var/log/asterisk/Sascha-Sipvar.log)

So, I am reading the history info from the invite and split it into two new variables:
The name and the number.
Result looks good in my log:

24.02.2017, 12:39:20 - Sascha - +58176

But: The name could be different length (number also) and I am unable to find an asterisk command to check a string for the position of a character which I can use…
I would need a command which gives me back the position of the character < out of my string ‘24.02.2017, 09:44:14 - Sascha sip:+58176@sip.saschakamm.local;index=1.2’ which I get back from reading the History info field…
If I know the position of ‘<’ and ‘@’ it is just a little bit of mathematics and I always get the result I am looking for - regardless length of numer and name.

TIA
Cheers

I would look at the : operator in https://wiki.asterisk.org/wiki/display/AST/Operators

Also consider https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Function_CUT

I think there are others, as well.

You guys are all really cool…

Don’t share the answer on a silver tablet but point to the documentation where I can find my information needed, but still need to make use of my brain :wink:

Kind of: “RTFM” but look into this one here :wink:

But: Seens to work.
I do not know If I am doing too many steps in between for what I want to get, but it is now working.

These are my steps in dialplan:

exten => s,n,Set(sipinvitehistory3=${SIP_HEADER(History-Info,3)})
exten => s,n,Set(historyname=${CUT(sipinvitehistory3,<,1)})
exten => s,n,Set(historynumber1=${CUT(sipinvitehistory3,<,2)})
exten => s,n,Set(historynumber2=${historynumber1:4:50}
exten => s,n,Set(historynumber=${CUT(historynumber2,@,1)})
exten => s,n,Set(historydomain1=${CUT(historynumber2,@,2)})
exten => s,n,Set(historydomain=${CUT(historydomain1,>,1)})
exten => s,n,System(echo “${STRFTIME(${EPOCH},%d.%m.%Y, %H:%M:%S)} - ${historyname} - ${historynumber} - ${historydomain}” >> /var/log/asterisk/Sascha-Sipvar.log)

And this is the output result in my logfile:

24.02.2017, 14:27:59 - Sascha - +58176 - sip.saschakamm.local
24.02.2017, 14:31:26 - MTA - +58661 - sip.saschakamm.local
[root@VoIPServer asterisk]#

I now have all the information needed in seperate variables to continue working with them.

Thank you for your support! :smiley:
Cheers