Asterisk Readout Values From a Database - mysql

I am attempting to create a simple asterisk dialplan application that reads values from a MySQL database whenever a user calls a certain extension.
The table looks like this:
Type.....Number
H .......... 10
S .......... 60
P .......... 40
G ......... 15
So basically, whenever someone calls, asterisk should readout H 10, S 60, P 40, G 15...
Here's what I have so far:
;Answer call
exten => 123,1,Answer()
;Readout results to caller
;hangup
exten => 123,3,Hangup()
Any help would be appreciated.

You can use func_odbc or asterisk realtime architecture/function REALTIME for that.
Unfortanly both require some db settings and coding, it is not one line of dialplan.

Related

Proper Syntax for Writing Multiple Fields with odbc_func?

This is a follow-up to my previous post. Trying to write to the CDR table on hangup. Asterisk 13 seems to prevent using the CDR() in the h extension (though I could in *11).
SO, I will just create a nice ODBC_FUNC function and use that to write my data.
Except I can't make it work.
I want to write multiple fields:
exten => h,n,Set(ODBC_WRITE_TEST(${E})=First\,Second,Third,Fourth)
or
exten => h,n,Set(ODBC_WRITE_TEST(${E})=${cause_name},${cause_name}, ${TrNumber},${uID})
Neither of these work. They both write a blank record to the table so we know what ODBC is working. But the field content does not get passed.
func_odbc.conf:
[WRITE_TEST]
dsn=asterisk
; writesql=INSERT INTO LogAndDebug (debugMessage, debugData, logMessage) VALUES ('test','123','done')
writesql=INSERT INTO LogAndDebug (debugMessage, debugData, logMessage) VALUES ('${SQL_ESC(${ARG1})}','${SQL_ESC(${VAR2})}','${SQL_ESC(${VAR1})}')
The commented line above does write data as expected. The uncommend line writes an empty record.
I have tried it without the SQL_ESC. The fields are varchars...so quoted text seems correct. It looks as if the ARGx and VARx are not being passed.
I have looked for documentation on this in Asterisk docs, and surprise -- NADA
As of asterisk 1.8 func_odbc is like that:
In func_odbc.conf:
[WRITE_TEST]
dsn=asterisk
writesql=INSERT INTO LogAndDebug (debugMessage, debugData, logMessage) VALUES ('${ARG1}','${VAR2}','${VAR3}')
In dialplan:
exten => s,n,NoOp(WRITE_TEST.${ODBC_WRITE_TEST('this','is','test')})

Why Are Custom CDR fields in Asterisk Not Recorded in MySQL?

Running Asterisk 13 on Fedora 21 Server. SELinux = Permissive.
I have configured asterisk to write CDRs to MySQL. I get all the normal fields written to the CDR.
I also have this in the dial plan (extensions.conf):
exten => h,n,Set(CDR(cause_code)=${HANGUPCAUSE})
exten => h,n,Set(CDR(cause_name)= ${ODBC_GET_CAUSE(${HANGUPCAUSE})})
exten => h,n,Set(TrNumber=${ODBC_GET_DIALED_NUMBER(${CDR(lastdata)})})
exten => h,n(writeTranslate),SET(CDR(TranslatedNumber)=${TrNumber})
Note the custom fields cause_code, cause_name, and TranslatedNumber/
The fields cause_code, cause_name, and TranslatedNumber exist in the cdr table.
When the code runs I get this:
-- Executing [h#context-out:5] Set("SIP/xx.xxx.xx.xx-00000004", "CDR(cause_code)=16") in new stack
-- Executing [h#context-out:6] Set("SIP/xx.xxx.xx.xx-00000004", "CDR(cause_name)= normal call clearing") in new stack
-- Executing [h#context-out:7] Set("SIP/xx.xxx.xx.xx-00000004", "TrNumber=15555552233") in new stack
-- Executing [h#context-out:9] Set("SIP/xx.xxx.xx.xx-00000004", "CDR(translatedNumber)=15555552233") in new stack
This is in verbose mode. Note that the code Setting the CDR runs without error and with data to be posted to the CDR.
cdr_adaptive_odbc.conf looks like this:
[adaptive-connection]
connection=asterisk
table=cdr
alias start => calldate
usegmtime=yes
That is all I should need. The cdr_adaptive_odbc module has been reloaded as has been the dial plan.
YET, these fields are shown as NULL in the cdr table. Suggestions?
You have to add aliases for adding custom fields in CDRs
[aliases]
cause_code = cause_code
cause_name = cause_name
TranslatedNumber = TranslatedNumber
I have tried on asterisk 11 and following is the full guide:
http://blog.ones-app.com/add-custom-fields-in-asterisks-mysql-cdrs/

MySQL CDRs in Asterisk 11?

It appears that since Asterisk 1.8 MySQL CDR storage is built-in (cdr_mysql.so is deprecated as is the Asterisk Add-ons). I have a cdr_mysql.conf configured (similar settings as in res_config_mysql.conf which works) and I have mySQL running and the cdr table created (and yes Asterisk can write to the tables). BUT, I get no CDRs in that table (I do get the Master.csv CDRs). What am I missing?
Suggestions?
In asterisk 11 cdr_mysql still selactable via
make menuconfig
It is depricated. Since cdr_odbc work same, i not see any issue in that.
You also need have cdr.conf file with
[general]
; Define whether or not to use CDR logging. Setting this to "no" will override
; any loading of backend CDR modules. Default is "yes".
enable=yes
And cdr_custom.conf with something like this
[mappings]
Master.csv => ${CSV_QUOTE(${CDR(clid)})},${CSV_QUOTE(${CDR(src)})},${CSV_QUOTE(${CDR(dst)})},${CSV_QUOTE(${CDR(dcontext)})},${CSV_QUOTE(${CDR(channel)})},${CSV_QUOTE(${CDR(dstchannel)})},${CSV_QUOTE(${CDR(lastapp)})},${CSV_QUOTE(${CDR(lastdata)})},${CSV_QUOTE(${CDR(start)})},${CSV_QUOTE(${CDR(answer)})},${CSV_QUOTE(${CDR(end)})},${CSV_QUOTE(${CDR(duration)})},${CSV_QUOTE(${CDR(billsec)})},${CSV_QUOTE(${CDR(disposition)})},${CSV_QUOTE(${CDR(amaflags)})},${CSV_QUOTE(${CDR(accountcode)})},${CSV_QUOTE(${CDR(uniqueid)})},${CSV_QUOTE(${CDR(userfield)})},${CDR(sequence)}
No ODBC! Just enable all Mysql (even if it depreceted) in make menuselect and run:
make clean & make & make install
make clean - is necessary!
In modules.conf write next:
load => app_db.so
load => app_cdr.so
load => app_mysql.so
load => cdr_csv.so
load => cdr_mysql.so
load => func_cdr.so
load => func_db.so
In cdr.conf
[general]
enable=yes
In cdr_mysql.conf - all for connect to MySQL.
after all this go to CLI and type cdr show status and looking for mysql! )) Try to use this command before)
CLI> cdr show status
Call Detail Record (CDR) settings
----------------------------------
Logging: Enabled
Mode: Simple
Log unanswered calls: Yes
Log congestion: No
* Registered Backends
-------------------
mysql
csv

Using mysql with asterisk

I have installed asterisk 11 on my centos 6 ,now i want to connect my asterisk with database
I am following this .I have both installed and configured mysql
I have created an outbound call (b.call)
Channel: DAHDI/g0/09********
MaxRetries: 1
RetryTime: 60
WaitTime: 30
Context: out
Extension: 47******
Priority: 1
and a simple dialplan(extensions.conf)
[out]
exten => 47*****,1,NoOp(<-------IVR----------->)
same => n,dial(DAHDI/g0/09********)
same => n,MYSQL(Connect connid localhost username pass dbname)
same => n,MYSQL(Query resultid ${connid} INSERT INTO `emp` (`name`) VALUES ('Akash'))
My problem is that,first 2 lines of dialplan executes perfectly but database lines are not executed,cli shows only first 2 lines executed and last 2 lines not executed.
Am i missing any configuration settings??
Thanks
Very likly you have no app_mysql loaded.
I higly not recommend use outdated mysql app. Use instead function REALTIME and func_ODBC.

Having trouble running cakephp app on remote server

If you get:
Error: SQLSTATE[42000]: Syntax error or access violation: 1104 The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET MAX_JOIN_SIZE=# if the SELECT is okay
After uploading cake php app and database from xampp localhost to a remote server.
Having tried importing the cake database into a new db on local machine and works fine. So I couldn't see it being the information imported.
Had no idea how to fix this. Its a simple and common problem with an easy fix as below.
After much hair pulling I managed to find the problem/fix with the help of my good friend ten1 on cakephp IRC chat.
When this is a cakephp specific issue which it was in my case you need to do the un-thinkable and edit the core.
The file you need to edit is AclNode.php Located here: /lib/Cake/Model/AclNode.php
You need to add a line before line 113
112 }
$db->query('SET SQL_BIG_SELECTS=1'); //Add this line
113 $result = $db->read($this, $queryData, -1);
114 $path = array_values($path);
This is generally only a problem on servers with shared hosting.
Rather than editing core file you could add a beforeFind method to your app/models/app_model.php file, if wanted it to affect all over or to your particular model file, like the following:
function beforeFind() {
$this->query('SET SQL_BIG_SELECTS=1');
}
For Cakephp 3 following works:
'Datasources' => [
'default' => [
'init' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET SESSION SQL_BIG_SELECTS=1',
), // Add this to the existing array