MySQL CDRs in Asterisk 11? - mysql

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

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/

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.

Ruby MySQL output conflicting on different servers

I have coded a Ruby IRC bot which is on github (/ninjex/rubot) which is having some conflicting output with MySQL on a dedicated server I just purchased.
Firstly we have the connection to the database in the MySQL folder (in .gitignore) which looks similar to the following code block.
#con = Mysql.new('localhost', 'root', 'pword', 'db_name')
Then we have an actual function to query the database
def db_query
que = get_message # Grabs query from user i.e,./db_query SELECT * FROM words
results = #con.query(que) # Send query through the connection i.e, #con.query("SELECT * FROM WORDS")
results.each {|x| chan_send(x)} # For each row returned, send it to the channel via
end
On my local machine, when running the command:
./db_query SELECT amount, user from words WHERE user = 'Bob' and word = 'hello'
I receive the output in IRC in an Array like fashion: ["17", "Bob"] Where 17 is amount and Bob is the user.
However, using this same function on my dedicated server results in an output like: 17Bob I have attempted many changes in the code, as well as try to parse the data into it's own variable, however it seems that 17Bob is coming out as a single variable, making it impossible to parse into something like an array, which I could then use to send the data correctly.
This seems odd to me on both my local machine and the dedicated server, as I was expecting the output to first send 17 to the IRC and then Bob like:
17
Bob
For all the functions and source you can check my github /Ninjex/rubot, however you may need to install some gems.
A few notes:
Make sure you are sanitizing query via get_message. Or you are opening yourself up to some serious security problems.
Ensure you are using the same versions of the mysql gem, ruby and MySql. Differences in any of these may alter the expected output.
If you are at your wits end and are unable to resolve the underlying issue, you can always send a custom delimiter and use it to split. Unfortunately, it will muck up the case that is actually working and will need to be stripped out.
Here's how I would approach debugging the issue on the dedicated machine:
def db_query
que = get_sanitized_message
results = #con.query(que)
require 'pry'
binding.pry
results.each {|x| chan_send(x)}
end
Add the pry gem to your Gemfile, or gem install pry.
Update your code to use pry: see above
This will open up a pry console when the binding.pry line is hit and you can interrogate almost everything in your running application.
I would take a look at results and see if it's an array. Just type results in the console and it will print out the value. Also type out results.class. It's possible that query is returning some special result set object that is not an array, but that has a method to access the result array.
If results is an array, then the issue is most likely in chan_send. Perhaps it needs to be using something like puts vs print to ensure there's a new line after each message. Is it possible that you have different versions of your codebase deployed? I would also add a sleep 1 within the each block to ensure that this is not related to your handling of messages arriving at the same time.

Backup database(s) using query without using mysqldump

I'd like to dump my databases to a file.
Certain website hosts don't allow remote or command line access, so I have to do this using a series of queries.
All of the related questions say "use mysqldump" which is a great tool but I don't have command line access to this database.
I'd like CREATE and INSERT commands to be created at the same time - basically, the same performance as mysqldump. Is SELECT INTO OUTFILE the right road to travel, or is there something else I'm overlooking - or maybe it's not possible?
Use mysqldump-php a pure-PHP solution to replicate the function of the mysqldump executable for basic to med complexity use cases - I understand you may not have remote CLI and/or mysql direct access, but so long as you can execute via an HTTP request on a httpd on the host this will work:
So you should be able to just run the following purely PHP script straight from a secure-directory in /www/ and have an output file written there and grab it with a wget.
mysqldump-php - Pure PHP mysqldump on GitHub
PHP example:
<?php
require('database_connection.php');
require('mysql-dump.php')
$dumpSettings = array(
'include-tables' => array('table1', 'table2'),
'exclude-tables' => array('table3', 'table4'),
'compress' => CompressMethod::GZIP, /* CompressMethod::[GZIP, BZIP2, NONE] */
'no-data' => false,
'add-drop-table' => false,
'single-transaction' => true,
'lock-tables' => false,
'add-locks' => true,
'extended-insert' => true
);
$dump = new MySQLDump('database','database_user','database_pass','localhost', $dumpSettings);
$dump->start('forum_dump.sql.gz');
?>
With your hands tied by your host, you may have to take a rather extreme approach. Using any scripting option your host provides, you can achieve this with just a little difficulty. You can create a secure web page or strait text dump link known only to you and sufficiently secured to prevent all unauthorized access. The script to build the page/text contents could be written to follow these steps:
For each database you want to back up:
Step 1: Run SHOW TABLES.
Step 2: For each table name returned by the above query, run SHOW CREATE TABLE to get the create statement that you could run on another server to recreate the table and output the results to the web page. You may have to prepend "DROP TABLE X IF EXISTS;" before each create statement generated by the results of these queryies (!not in your query input!).
Step 3: For each table name returned from step 1 again, run a SELECT * query and capture full results. You will need to apply a bulk transformation to this query result before outputing to screen to convert each line into an INSERT INTO tblX statement and output the final transformed results to the web page/text file download.
The final web page/text download would have an output of all create statements with "drop table if exists" safeguards, and insert statements. Save the output to your own machine as a ".sql" file, and execute on any backup host as needed.
I'm sorry you have to go through with this. Note that preserving mysql user accounts that you need is something else entirely.
Use / Install PhpMySQLAdmin on your web server and click export. Many web hosts already offer you this as a service pre-configured, and it's easy to install if you don't already have it (pure php): http://www.phpmyadmin.net/
This allows you to export your database(s), as well as perform other otherwise tedious database operations very quickly and easily -- and it works for older versions of PHP < 5.3 (unlike the Mysqldump.php offered as another answer here).
I am aware that the question states 'using query' but I believe the point here is that any means necessary is sought when shell access is not available -- that is how I landed on this page, and PhpMyAdmin saved me!

Second RMySQL operation fails - why?

I am running a script that stores different datasets to a MySQL database. This works so far, but only sequentially. e.g.:
# write table1
replaceTable(con,tbl="table1",dframe=dframe1)
# write table2
replaceTable(con,tbl="table2",dframe=dframe2)
If I select both (I use StatET / Eclipse) and run the selection, I get an error:
Error in function (classes, fdef, mtable) :
unable to find an inherited method for function "dbWriteTable",
for signature "MySQLConnection", "data.frame", "data.frame".
I guess this has to do with the fact that my con is still busy or so when the second request is started. When I run the script line after line it just works fine. Hence I wonder, how can I tell R to wait til the first request is ready and then go ahead ? How can I make R scripts interactive (just console like plot examples - no tcl/tk).
EDIT:
require(RMySQL)
replaceTable <- function(con,tbl,dframe){
if(dbExistsTable(con,tbl)){
dbRemoveTable(con,tbl)
dbWriteTable(con,tbl,dframe)
cat("Existing database table updated / overwritten.")
}
else {
dbWriteTable(con,tbl,dframe)
cat("New database table created")
}
}
dbWriteTable has two important arguments:
overwrite: a logical specifying whether to overwrite an existing table
or not. Its default is ‘FALSE’.
append: a logical specifying whether to append to an existing table
in the DBMS. Its default is ‘FALSE’.
For past project I have successfully achieve appending, overwriting, creating, ... of tables with proper combinations of these.