Random Quote
I would rather vote for a man with character, than vote for a man who is a character.
Author about George W. Bush in 2004
"I remember the day in January I told Osama, 'If George steals the election, make those rich conservatives pay' " - Glenn Reynolds.

Post details: Asterisk modification for Queue logging to mySQL

01/07/07

Permalink 02:44:44 pm, Categories: Software, 511 words   English (US)

Asterisk modification for Queue logging to mySQL

Looking on the Digium forums, I found a very nice idea for a patch to the logger.c file in Asterisk from vixtor {link is above}.

The patch was created for 1.2.3 by vixtor so I ported the patch over to 1.4.0 and causes the queue log to be written to SQL in real-time. This allows you to get the statistics for the queue in real-time instead of having to import the existing queue log.

I always have issues with bulky patches to code because they are not a quick hook of the code but a lengthy addition. Therefore, what I have done is move the bulk of the code out of the patch and placed it in a file to be included. While I should have created a .h and a .c file to be proper, this will have to do to make things simpler.

That way the changes to the core files can be minimal and even if you need to hack this for future version, all you need to do is place 4 lines into the existing code.

I doubt that Digium will include this in their production system due to the difference between Digium licensing and mySQL licensing, so my guess is that we will need to patch this for each version.

1. You will need to place the logger-mysql.c file in the main directory below your build directory.
2. You will need to create a sql table something like this:

CREATE TABLE `asterisk_queue_log` (
`id` int(11) NOT NULL auto_increment,
`time` datetime NOT NULL default '0000-00-00 00:00:00',
`callid` varchar(20) NOT NULL default '',
`queuename` varchar(20) NOT NULL default '',
`agent` varchar(20) NOT NULL default '',
`event` varchar(20) NOT NULL default '',
`arg1` varchar(100) NOT NULL default '',
`arg2` varchar(100) NOT NULL default '',
`arg3` varchar(100) NOT NULL default '',
PRIMARY KEY (`id`)
) ;

3. You will need to patch the Makefile and main/logger.c fiel, which is also here.

diff -u -r ./Makefile.sav ./Makefile
--- ./Makefile.sav 2006-12-22 16:33:46.000000000 -0600
+++ ./Makefile 2007-01-07 10:19:04.000000000 -0600
@@ -183,6 +183,8 @@
ASTCFLAGS+=-pipe -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(DEBUG)

ASTCFLAGS+=-include $(ASTTOPDIR)/include/asterisk/autoconfig.h
+ASTCFLAGS+=-I/usr/include/mysql
+ASTLDFLAGS+=-L/usr/lib/mysql -lmysqlclient

ifeq ($(AST_DEVMODE),yes)
ASTCFLAGS+=-Werror -Wunused
diff -u -r ./main/logger.c.sav ./main/logger.c
--- ./main/logger.c.sav 2006-11-10 20:04:28.000000000 -0600
+++ ./main/logger.c 2007-01-07 02:51:54.000000000 -0600
@@ -86,6 +86,9 @@
static int filesize_reload_needed = 0;
static int global_logmask = -1;

+/* Added for mysql */
+#include "logger-mysql.c"
+
static struct {
unsigned int queue_log:1;
unsigned int event_log:1;
@@ -337,6 +340,9 @@
if ((s = ast_variable_retrieve(cfg, "general", "event_log")))
logfiles.event_log = ast_true(s);

+/* Added for mysql */
+ init_mysql_logger(cfg);
+
AST_LIST_LOCK(&logchannels);
var = ast_variable_browse(cfg, "logfiles");
for (; var; var = var->next) {
@@ -359,6 +365,8 @@
fprintf(qlog, "%ld|%s|%s|%s|%s|", (long)time(NULL), callid, queuename, agent, event);
vfprintf(qlog, fmt, ap);
fprintf(qlog, "\n");
+/* Added for mysql */
+ write_mysql_logger(queuename,callid,agent,event,fmt, ap);
va_end(ap);
fflush(qlog);
}

4. You will need to add these lines into /etc/asterisk/logger.conf:

[mysql]
hostname=localhost
dbname=asterisk
table=asterisk_queue_log
password=*
user=asterisk
port=3306
sock=/var/lib/mysql/mysql.sock

UPDATE: Fixed the diff file so it is more proper

Comments:

Comment from: Sajjad [Visitor]
After patch i tried to recomplie Asterisk 1.4.0 and found the following error

make
make[1]: Entering directory `/asterisk/asterisk-1.4.0/menuselect'
make[2]: Entering directory `/asterisk/asterisk-1.4.0/menuselect'
make[2]: `menuselect' is up to date.
make[2]: Leaving directory `/asterisk/asterisk-1.4.0/menuselect'
make[1]: Leaving directory `/asterisk/asterisk-1.4.0/menuselect'
menuselect/menuselect --check-deps menuselect.makeopts
[LD] astman.o md5.o -> astman
/usr/bin/ld: cannot find -lmysqlclient
collect2: ld returned 1 exit status
make[1]: *** [astman] Error 1
make: *** [utils] Error 2
Permalink 02/13/07 @ 01:38
Comment from: author [Member] · http://www.plack.net/
Sajjad,
The error you show is that you do not have the mysqlclient library installed on that machine or your LIB path is wrong. Check your ./configure in asterisk about the mysqlclient. This has nothing really to do with the patch.

"/usr/bin/ld: cannot find -lmysqlclient"
Permalink 02/13/07 @ 16:47
Comment from: Krisz [Visitor]
If there is no communication for long time the logger stop logging to mysql. Maybe the mysql close the connection. Any idea how to solve this problem?
Permalink 03/05/07 @ 04:29
Comment from: Peter [Visitor]
if not use some time queue, this path don`t insert into mysql rows. Can any help me with problems?

Thanks
Permalink 06/17/07 @ 04:31
Comment from: author [Member] · http://www.plack.net/
You did not specify which database you are using, but I assume mySQL because the mySQL client will timeout if there are no queries. This may be an asterisk bug, but I have the issue with other clients to mySQL. Check the version of client you are using. This is not an issue with the patch, just an issue with the client.
Permalink 06/17/07 @ 13:33
Comment from: kokoska.rokoska [Visitor]
I have tried to apply this patch to x86_64 system (CentOS 5.1) and Asterisk died with coredump during startup. I have tried Asterisk version 1.4.6 and 1.4.17, both with same result...
On i386 system everything works fine.

Could anyone point me to some solution?

Thanx. kokoska.rokoska
Permalink 01/18/08 @ 03:41
Comment from: Matt [Visitor]
I have Asterisk 1.4.17 and i patched the Makefile without an error . I created the mysql table and edited the
logger file .
I use freepbx to create an queue. There are restart and configure load messages in queue_log file but none in the mysql.
realtime mysql is on and connected.
Am i doing things wrong or are the configure reload and queuestart messages not imported into mysql ??

Any help on this woulod be much apprecited .

thanks in forward

Matt
Permalink 01/19/08 @ 02:52
Comment from: Thierry R. [Visitor] · http://thierry.randrianiriana.org/
I tried your patch and I changed it to support the next table schema in the next stable release and 500 len is to small for a long event name.
The files are here http://thierry.randrianiriana.org/asterisk/, it's for asterisk 1.4.17 .

Permalink 02/07/08 @ 10:12
Comment from: Matt [Visitor]
good day everyone

has anyone solved the problem with logging timeouts to mysql ??

i use mysql5 .

appreciate any help

good day
Permalink 03/04/08 @ 03:23
Comment from: Sean [Visitor] · http://c0w.eu/asterisk
Updated version for 1.4.11 with reconnection its not fully tested but its been running for 5 days with no stale mysql connections.


http://c0w.eu/asterisk
Sean
Permalink 04/08/08 @ 03:20
Comment from: Matt [Visitor]
It is the Mysql destroying the connection after some time of inactivity.

wait_timeout and interactive_timeout

just add them

in the /etc/mysql/my.cnf.

just add
interactive_timeout = value in seconds
wait_timeout = value in seconds

and it should be ok
Permalink 09/23/08 @ 02:39
Comment from: Darren [Visitor]
hello i have tested this with 1.4.21
my issue is that is seg faults on

if(vsnprintf(myquery_ap, 100, myfmt, ap)
Permalink 10/01/08 @ 20:28
Comment from: Darren [Visitor]
any ideas .


d
Permalink 10/01/08 @ 20:32
Comment from: Diego [Visitor]
Hi.

how is the patch applied over DEBIAN.

I need a code to run this patch.

is it ok for asterisk 1.4.23.

thaks.
Permalink 01/12/09 @ 03:38
Comment from: buy steroids [Visitor] · http://gproids.com
hello i have tested this with 1.4.21
my issue is that is seg faults on
Permalink 06/09/09 @ 07:54
Comment from: ron_hartmann [Member]
I am desperately trying to get the logger-mysql.c file to compile on asterisk-1.4.22 for somereason adding in the:
ASTCFLAGS+=-I/usr/include/mysql
ASTLDFLAGS+=-L/usr/lib/mysql -lmysqlclient
does not seam to actually trigger the include or linker for inclusion of the libmysql stuff.

Any help would be greatly greatly appreciated.
Permalink 08/04/09 @ 12:46
Comment from: tom [Visitor] · http://blog.nohideip.com
test it with mysql, works well!
Permalink 11/03/09 @ 23:19
Comment from: anabolics [Visitor] · http://etalaze.net
it’s really cool to see something like this....
Permalink 01/14/10 @ 04:31

Leave a comment:

Your email address will not be displayed on this site.
Your URL will be displayed.
Allowed XHTML tags: <p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>

authimage

Options:
 
(Line breaks become <br />)
(Set cookies for name, email & url)

PLACK.NET

Dying daily to live forever.

Welcome, my attempt to post some personal thoughts on interesting topics.

March 2010
Mon Tue Wed Thu Fri Sat Sun
<<  <   >  >>
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        

Search

Syndicate this blog XML

What is RSS?

powered by
b2evolution

7936 visits to this site