Using mysql with asterisk - mysql

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.

Related

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

Asterisk Readout Values From a Database

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.

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

Cakephp Auth login returns false even though SQL query finds rows

I have Cakephp app installed on a linux box.
The Mysql Driver is installed and php-pecl-acl has been removed.
There are no problems with the Cookies. The users and passwords exist in the database. The password is a CHAR(40) in the database.
The Auth->login() method always returns false, even though the sql query debug log shows that rows affected = 1
array(
'log' => array(
(int) 0 => array(
'query' => 'SELECT `User`.`id`, `User`.`username`, `User`.`password`, `User`.`email`, FROM `somedatabase`.`users` AS `User` WHERE `User`.`username` = 'someuser' AND `User`.`password` = '2d7a34c9ef8efa2cfdf4b89175f7edec1cd0ddda' LIMIT 1',
'params' => array(),
'affected' => (int) 1,
'numRows' => (int) 1,
'took' => (float) 2
)
),
'count' => (int) 1,
'time' => (float) 2
Please help.
Thank you.
Sounds like the exact same issue I was having that ended up being a server-specific issue related to PDO / PECL:
$this->Auth->login() creates correct query that returns 1 row, but fails IF check (server specific issue)
Edit:
Comment from OP about how he fixed:
I uninstalled PECL, then uninstalled php-pdo and put back the original
php.ini file. After that I reinstalled mysql-php and php-pdo packages
from Amazon and it worked. You were correct it was server issue with
the pdo installation.
I to had the same problem. I had contacted my server man he said that we didn't installed either PECL or php-pdo packages. What would be the problem.