Asterisk gravando ligações no MySQL

By Helder Morais

Para gravar os dados na tabela cdr do banco de dados MySQL , é preciso ajustar alguns parâmetros no Asterisk.

Instalação do Banco MySQL

Para instalar o MySQL, basta usar o comando abaixo.

 apt-get install mysql-server-5.0

Criação do usuário e strutura

Após instalar o Banco MySQL, entrar com o usuário root e executar o script abaixo.

 CREATE DATABASE asteriskcdrdb; 

 GRANT INSERT
  ON asteriskcdrdb.*
  TO asteriskcdruser@localhost
  IDENTIFIED BY 'yourpassword'; 

 USE asteriskcdrdb; 

 CREATE TABLE cdr (
 `id` bigint NOT NULL auto_increment PRIMARY KEY,
 `calldate` datetime NOT NULL default '0000-00-00 00:00:00',
 `clid` varchar(80) NOT NULL default '',
 `src` varchar(80) NOT NULL default '',
 `dst` varchar(80) NOT NULL default '',
 `dcontext` varchar(80) NOT NULL default '',
 `channel` varchar(80) NOT NULL default '',
 `dstchannel` varchar(80) NOT NULL default '',
 `lastapp` varchar(80) NOT NULL default '',
 `lastdata` varchar(80) NOT NULL default '',
 `duration` int(11) NOT NULL default '0',
 `billsec` int(11) NOT NULL default '0',
 `disposition` varchar(45) NOT NULL default '',
 `amaflags` int(11) NOT NULL default '0',
 `accountcode` varchar(20) NOT NULL default '',
 `userfield` varchar(255) NOT NULL default '',
 `enviado`char(1) NOT NULL default 'N'
 ) ENGINE = innodb; 

 ALTER TABLE `cdr` ADD INDEX ( `calldate` );
 ALTER TABLE `cdr` ADD INDEX ( `dst` );

Ajustar o cdr_mysql.conf

Criar um arquivo de configuração informando a senha do Banco MySQL.
Exemplo: /etc/asterisk/cdr_mysql.conf

 ;
 ; Note - if the database server is hosted on the same machine as the
 ; asterisk server, you can achieve a local Unix socket connection by
 ; setting hostname=localhost
 ;
 ; port and sock are both optional parameters.  If hostname is specified
 ; and is not "localhost", then cdr_mysql will attempt to connect to the
 ; port specified or use the default port.  If hostname is not specified
 ; or if hostname is "localhost", then cdr_mysql will attempt to connect
 ; to the socket file specified by sock or otherwise use the default socket
 ; file.
 ;
 [global]
  hostname=localhost
  dbname=asteriskcdrdb
  password=yourpassword
  user=asteriskcdruser
  ;port=3306
  ;sock=/tmp/mysql.sock
  ;userfield=1

Ajustar o modules.conf

Editar o /etc/asterisk/modules.conf e acrescentar

 load cdr_addon_mysql.so

e reinicializar o asterisk para carregar o módulo.

Verificando a implenetação

Entre no asterisk com asterisk -r e dê um restart now .

Entre novamente, e verifique:

asterisk*CLI> cdr mysql status
Connected to asteriskcdrdb@localhost, port 3306 using table cdr for 8 seconds.
Wrote 0 records since last restart.
asterisk*CLI>

Pronto, seu asterisk já está gravando o CDR em MySQL.

Obs: se voce for compilar o asterisk, lembre-se se acrescentar o “add on” e a biblioteca do MySQL (libmysqlclient15-dev).

Uma resposta para “Asterisk gravando ligações no MySQL”

  1. Video | Enjolt.com | Innovate for Success Disse:

    [...] [...]

Deixe uma resposta

Você precisa fazer o login para publicar um comentário.