Difference between revisions of "3rd party software/Asterisk"

From Freeside
Jump to: navigation, search
(psql login test)
(Verify new data records)
Line 53: Line 53:
 
freeside=>
 
freeside=>
 
</pre>
 
</pre>
 +
 +
=== 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.
 +
 +
<code>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;</code>
 +
 +
The psql client will respond similar to this:
 +
 +
<pre>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=# </pre>
  
 
=== Verify new data records ===
 
=== Verify new data records ===

Revision as of 10:09, 20 February 2008


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

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

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