3rd party software/Asterisk

From Freeside
Revision as of 13:02, 20 February 2008 by Supaplex (talk | contribs) (pg_hba.conf)

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 postgres 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

See Also: pg_hba.conf at postgres.org for more information on Postgres client authentication.

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=>

GRANT asterisk permissions

We are allowing asterisk limited access to the Freeside database. Freeside isn't expected to have GRANT permissions on the freeside database. Connect as the postgres superuser.

Code snippet to GRANT selective permissions to asterisk.

GRANT SELECT ON cdr TO asterisk;
GRANT INSERT ON cdr TO asterisk;
GRANT UPDATE ON cdr TO asterisk;
GRANT SELECT ON cdr_acctid_seq to asterisk;
GRANT UPDATE ON cdr_acctid_seq to asterisk;

The psql client will respond similar to this:

freeside=# GRANT SELECT ON cdr TO asterisk;
GRANT
freeside=# GRANT INSERT ON cdr TO asterisk;
GRANT
freeside=# GRANT UPDATE oN cdr TO asterisk;
GRANT
freeside=# GRANT SELECT ON cdr_acctid_seq to asterisk;
GRANT
freeside=# GRANT UPDATE ON cdr_acctid_seq to asterisk;
GRANT
freeside=# 

Reload cdr_pgsql

Changes to the cdr_pgsql.conf only need a reload of the cdr_pgsql.so module for changes to be applied immediately.

asterisk -rx "reload cdr_pgsql.so"

Make a test call

If your asterisk configuration is able to make calls, place a test call that applies to your needs of freeside and asterisk (eg, a sample call that would be billed).

Verify new data records

We check for CDR entries to confirm our call progress is being recorded properly.

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=#

Troubleshooting

Trouble may arise due to insufficent permissions, invalid username or password in the config files, failure to reload cdr_pgsql after settings are updated, and a number of other related factors. The system logs and asterisk console are a good starting point when attempting to isolate underlying causes of your issue.

This sample was due to insufficent GRANT permissions to asterisk on the cdr_acctid_seq object.

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