3rd party software/Asterisk

From Freeside
Revision as of 08:57, 20 February 2008 by Supaplex (talk | contribs) (Testing with psql)

Jump to: navigation, search


Asterisk can be used as Soft Switch (among many other things). Freeside can examine recorded CDR data for subscriber billing purposes.

cdr_pgsql

Call detail records are stored by asterisk (by means of the cdr_pgsql extension) into a database of our choice. We will need to edit /etc/asterisk/cdr_pgsql.conf, add the asterisk user to postgres, add rights for asterisk to access the cdr table, and verify settings actually work.

cdr_pgsql.conf

This is our example config file. You will need to change the password to suit your install.

; Sample Asterisk config file for CDR logging to PostgresSQL

[global]
hostname=postgres
port=5432
dbname=freeside
password=FIXTHIS
user=asterisk
table=cdr               ;SQL table where CDRs will be inserted
spool=pgsql.spool

pg_hba.conf

This pg_hba.conf sample is only a snippet of the ACL to permit asterisk to connect.

hostssl (or host)
The connection type.
10.14.0.0/24
This example is a class C subnet.
md5
Password authentication required
hostssl         asterisk        freeside        10.14.0.0/24              md5

psql login test

We login to the database from the asterisk server to verify our setup is (so far) working okay. pghostname is the postgres host where your freeside database is.

pbx:~$ psql -h pghostname -U asterisk freeside
Password for user asterisk:
Welcome to psql 8.1.11, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)

freeside=>

Check for storage results in the sql table.

freeside=# SELECT acctid,calldate,src,dst,duration,billsec,disposition from cdr;
 acctid |        calldate        |     src    |    dst      | duration | billsec | disposition
--------+------------------------+------------+-------------+----------+---------+-------------
      1 | 2008-02-20 15:40:00+00 | 8005551212 | 18004664411 |       19 |       0 | NO ANSWER
      2 | 2008-02-20 15:48:52+00 | 8005551212 | 18004664411 |       14 |      10 | ANSWERED
(2 rows)

freeside=#

If needed, /var/log/asterisk/messages or the asterisk interactive cli will provide reporting for any errors.

Error logs here were from insufficient GRANT permissions to asterisk (as a Pg user).

Feb 20 15:37:40 ERROR[3404]: cdr_pgsql.c:159 pgsql_log: cdr_pgsql: Failed to insert call detail record into database!
Feb 20 15:37:40 ERROR[3404]: cdr_pgsql.c:160 pgsql_log: cdr_pgsql: Reason: ERROR:  permission denied for sequence cdr_acctid_seq
Feb 20 15:37:40 ERROR[3404]: cdr_pgsql.c:161 pgsql_log: cdr_pgsql: Connection may have been lost... attempting to reconnect.
Feb 20 15:37:40 ERROR[3404]: cdr_pgsql.c:164 pgsql_log: cdr_pgsql: Connection reestablished.
Feb 20 15:37:40 ERROR[3404]: cdr_pgsql.c:170 pgsql_log: cdr_pgsql: HARD ERROR!  Attempted reconnection failed.  DROPPING CALL RECORD!
Feb 20 15:37:40 ERROR[3404]: cdr_pgsql.c:171 pgsql_log: cdr_pgsql: Reason: ERROR:  permission denied for sequence cdr_acctid_seq

See Also