I need to insert some data to SQL ftom Asterisk dialplan. I am using ODBC connection and func_odbc.conf file. There are good way to READ several values from SQl, but apparently, i can't find any working solution for inserting several variables to func_odbc function.
I already tried to use NoOp(ODBC_FunctionName(${ARG1},${ARG2},${ARG3})) and it does not work with 'writesql'. Set(${ODBC_Function()={${ARG1},${ARG2},${ARG3}}) is not working either due to Set limited for one name/value pair.
Here is my func_odbc:
[putClientEvaluation]
;${ARG1} - uniqueid
;${ARG2} - operator
;${ARG3} - client
;${ARG4} - rating
;${ARG5} - queue
dsn=voip
writesql=INSERT INTO cc_service_rating(timestamp,callid,operator,client,rating,queue) values(now(),'${SQL_ESC(${ARG1})}','${SQL_ESC(${ARG2})}','${SQL_ESC(${ARG3})}','${SQL_ESC(${ARG4})}','${SQL_ESC(${ARG5})}')
So i need a working way to pass several arguments at once to odbc writesql function.
UPDATE:
Looks like i just have to use VAL instead of ARG:
writesql=INSERT INTO cc_service_rating(timestamp,callid,operator,client,rating,queue) values(now(),'${SQL_ESC(${VAL1})}','${SQL_ESC(${VAL2})}','${SQL_ESC(${VAL3})}','${SQL_ESC(${VAL4})}','${SQL_ESC(${VAL5})}')
But i still get warning from Set:
WARNING[1227][C-00000020]: pbx_variables.c:1155 pbx_builtin_setvar: Set requires one variable name/value pair.
So, how do i do this without using Set?
UPD:
Did this, no warnings now:
macro extension
exten => s,n,Set(operator=${ARG1})
exten => s,n,Set(quename=${ARG2})
exten => s,n,Set(client=${ARG3})
;timestamp,callid,operator,client,rating,queue
exten => s,n,Set(ODBC_putClientEvaluation()=${UNIQUEID},${operator},${client},${MACRO_EXTEN},${quename})
function
writesql=INSERT INTO cc_service_rating(timestamp,callid,operator,client,rating,queue) values(now(),'${VAL1}','${ARG1}','${ARG3}','${VAL2}','${ARG3}')
Not shure why does this work, obviousely i don't understand how ARG and VAL works here, and why putting args in function brackets does not work at all (even with comma screening).
You are using variables incorrect. Please read book article about variables.
Set(ODBC_Function(${ARG1},${ARG2})=${VAL1},"fixed_param",${VAL3})
I think you should try like this:
Set(ODBC_Function()=${VAR1},"fixed_param",${VAL3});
Related
Asterisk 16 has the status of macros deprecated.
Which is an alternative of the macros in Asterisk?
Macro() and MacroExit() are now replaced by Gosub() and Return()
Be carefull when runing Gosub's, as variables will be shared across all of your Gosub.
In case you call a Gosub(context_1,s,1) that's running a same => n,Set(test="foo") to set variable test, this variable will be accessible and set on a Gosub(context_2,s,1) for example
Alternative:
Macro() => Gosub()
MacroExit() => Return()
Please note, the name of the context you are going in to Gosub() to, are not prefixed, like it was with Macro(), where it was prefixed with "macro-".
I have a text file that contains some basic passwords and some variants of those basic passwords. They are typed out together like this:
qwerty, qwerty1
password, password1
default, default 1
123, 12345, 123456
I am trying to take these values and split them, storing them in a tuple and then print out the values as 'Password' and then any variants, but I am getting a syntax error on the print BIF? (I am aware this will not print out the password '123456', I am just trying to solve the syntax error first.)
for each_line in passwords:
(passwd, passwd_variant) = each_line.split(',',1)
print(f'Password: {passwd}, Variant {passwd_variant}')
SyntaxError: invalid syntax
normally if I was writing a script, in the editor I would put print on a new line, however a new line in IDLE simply executes the code above it. is there a shortcut or something to do a carriage return and write the print statement on a new line and if so, is that the cause of the syntax error and why?
Cheers
EDIT: I would like my output to be this
Finally discovered that you need to hit Enter after the for in statement, this will then take you to a new line inside for in statement. Was up all night trying to work it out, maybe my fresh brain helped this morning.
I am using Asterisk 1.4.44-vici built by abuild # build12 on a i686 running Linux on 2013-05-03 19:48:13 UTC
I have tried several ways to make the following work to no avail:
My callfile successfully calls out and records a message.
I want to send a variable that will be used for the recording file name.
In my callfile I have tried the following methods all failing:
Set: RECORDINGFILE=whatever
SetVar: RECORDINGFILE=whatever
Variable: RECORDINGFILE=whatever
Then in my Extension I have the following, watch for wrapping:
[meetme-outbound]
exten => _9XXXXXXXXXXXXXXXXXXXX1NXXNXXXXXX,1,MixMonitor(/var/spool/asterisk/monitorDONE/MP3/${SIPUSERAGENT}${EXTEN:1}${RECORDINGFILE}${STRFTIME(${EPOCH},$
exten => _9XXXXXXXXXXXXXXXXXXXX1NXXNXXXXXX,n,Dial(SIP/voipessential2/${EXTEN:21},,To)
exten => _9XXXXXXXXXXXXXXXXXXXX1NXXNXXXXXX,n,Hangup
THe above will record the file as if RECORDINGFILE, doesn't exist. Very annoying!
What could I be doing wrong? Is there a configuration setting that I am not aware of?
Any help would be greatly appreciated.
Greg Hill
Variable will be set only on one direction of call
To get variable from other direction use
${SHARED(RECORDINGGILE,${BRIDGEPEER})}
http://www.voip-info.org/wiki/view/Asterisk+Detailed+Variable+List
The transaction AL11 returns a mapping of "directory parameters" to file paths on the application server AFAIK.
The trouble with transaction AL11 is that its program only calls c modules, there's almost no trace of select statements or function calls to analize there.
I want the ability to do this dynamically, in my code, like for instance a function module that took "DATA_DIR" as input and "E:\usr\sap\IDS\DVEBMGS00\data" as output.
This thread is about a similar topic, but it doesn't help.
Some other guy has the same problem, and he explains it quite well here.
I strongly suspect that the only way to get these values is through the kernel directly. some of them can vary depending on the application server, so you probably won't be able to find them in the database. You could try this:
TYPE-POOLS abap.
TYPES: BEGIN OF t_directory,
log_name TYPE dirprofilenames,
phys_path TYPE dirname_al11,
END OF t_directory.
DATA: lt_int_list TYPE TABLE OF abaplist,
lt_string_list TYPE list_string_table,
lt_directories TYPE TABLE OF t_directory,
ls_directory TYPE t_directory.
FIELD-SYMBOLS: <l_line> TYPE string.
START-OF-SELECTION-OR-FORM-OR-METHOD-OR-WHATEVER.
* get the output of the program as string table
SUBMIT rswatch0 EXPORTING LIST TO MEMORY AND RETURN.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = lt_int_list.
CALL FUNCTION 'LIST_TO_ASCI'
EXPORTING
with_line_break = abap_true
IMPORTING
list_string_ascii = lt_string_list
TABLES
listobject = lt_int_list.
* remove the separators and the two header lines
DELETE lt_string_list WHERE table_line CO '-'.
DELETE lt_string_list INDEX 1.
DELETE lt_string_list INDEX 1.
* parse the individual lines
LOOP AT lt_string_list ASSIGNING <l_line>.
* If you're on a newer system, you can do this in a more elegant way using regular expressions
CONDENSE <l_line>.
SHIFT <l_line> LEFT DELETING LEADING '|'.
SHIFT <l_line> RIGHT DELETING TRAILING '|'.
SPLIT <l_line>+1 AT '|' INTO ls_directory-log_name ls_directory-phys_path.
APPEND ls_directory TO lt_directories.
ENDLOOP.
Try the following
data : dirname type DIRNAME_AL11.
CALL 'C_SAPGPARAM' ID 'NAME' FIELD 'DIR_DATA'
ID 'VALUE' FIELD dirname.
Alternatively if you wanted to use your own parameters(AL11->configure) then read these out of table user_dir.
I want to do the following in my extensions.conf in asterisk:
Read in a number entered by a user. - easy
Feed that number into a script which returns a wav file.
This wav file is then played.
I know the system command, but have not been able to figure out a way for it to return a value.
Any help is most welcome,
Thanks,
Sriram.
For such things I use Asterisk AGI. Idea is similar to CGI scripts for Web servers. You can use various languages, but I use Python with pyst: Python for Asterisk library. Such AGI script/program can read or set channel variable and this way communicate with Asterisk dialplan.
Example of such code with pyst agilib:
wav_to_play = 'other.wav'
user_nr = agilib.get_variable('user_entered_number')
if not user_nr:
wav_to_play = 'nothing.wav'
elif user_nr.endswith('0'):
wav_to_play = 'zero.wav'
# ...
agilib.set_variable('wav_selected', wav_to_play)
After saving such code in wav_selector.agi (you must add normal Python header, libs etc) you can use it in dialplan like:
exten => s,n,Set(user_entered_number=5)
exten => s,n,AGI(wav_selector.agi)
exten => s,n,Background((${wav_selected})
One can have the program/script write the value to a file and then use the functions within asterisk such as ReadFile to get the value. This can be done like so:
Within the script:
echo -n ${value} > ${fileName}
From within asterisk:
exten => 0,n,ReadFile(ValueReadFromFile=${fileName},${MAX_FILE_CHAR})
where: ${MAX_FILE_CHAR} is the max. characters that need to be read from the file ${fileName}. The value you want read will be stored in ValueReadFromFile.