Конфигурация Asterisk

Материал из darklurker wiki
Перейти к: навигация, поиск

Install

dnf install asterisk asterisk-sounds-core-ru-alaw asterisk-fax sox vorbis-tools libtiff-tools

Кодек

На странице ищем кодек g729 оптимизированный под процессор

Если есть поддержка sse4:
cd /usr/lib64/asterisk/modules/
wget http://asterisk.hosting.lv/bin/codec_g729-ast110-gcc4-glibc-x86_64-core2-sse4.so
chmod +x codec_g729-ast110-gcc4-glibc-x86_64-core2-sse4.so
Asterisk-CLI>  module load codec_g729-ast110-gcc4-glibc-x86_64-core2-sse4.so

Конфиги

cat > /etc/systemd/system/asterisk.service << "EOF"
[Unit]
Description=Asterisk PBX and telephony daemon.
After=network.target

[Service]
Type=forking
Environment=HOME=/var/lib/asterisk
WorkingDirectory=/var/lib/asterisk
User=asterisk
Group=asterisk
ExecStart=/usr/sbin/asterisk -F -C /etc/asterisk/asterisk.conf
ExecStop=/usr/sbin/asterisk -rx 'core stop now'
ExecReload=/usr/sbin/asterisk -rx 'core reload'

Nice=0
UMask=0002
#LimitCORE=infinity
#LimitNOFILE=
Restart=always
RestartSec=4

# If you uncomment the following you should add '-c' to the ExecStart line above

#TTYPath=/dev/tty7
#StandardInput=tty
#StandardOutput=tty
#StandardError=tty

PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF
  • features.conf
[featuremap]
blindxfer => *2
atxfer => #

Music on hold

cd /usr/share/asterisk
wget ftp:/user:pass@host/path/to/music.tgz
tar -xzf music.tgz
rm -f music.tgz

CDR

Создание базы данных
 CREATE DATABASE asterisk;
 USE asterisk;
CREATE TABLE `cdr` (
 `calldate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
 `clid` varchar(80)  ,
 `src` varchar(80)  ,
 `dst` varchar(80) ,
 `dcontext` varchar(80) ,
 `channel` varchar(80) ,
 `dstchannel` varchar(80),
 `lastapp` varchar(80),
 `lastdata` varchar(80),
 `duration` int(11) NOT NULL DEFAULT '0',
 `billsec` int(11) NOT NULL DEFAULT '0',
 `disposition` varchar(45)  ,
 `amaflags` int(11) NOT NULL DEFAULT '0',
 `accountcode` varchar(20),
 `uniqueid` varchar(32) ,
 `userfield` varchar(255),
 `usr_src` varchar(80) DEFAULT NULL,
 `usr_dst` varchar(80) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
grant all privileges on asterisk.* to aster@localhost identified by '74123';
(если нужен доступ для астера с удаленных хостов, то):
grant all privileges on asterisk.* to 'aster'@'10.66.1.%' identified by '74123';
yum install unixODBC mysql-connector-odbc asterisk-odbc

nano /etc/odbc.ini

[MySQL-asterisk]
Description     = Asterisk MySQL ODBC
Driver          = MySQL
#Socket          = /var/run/mysqld/mysqld.sock
Server          = 127.0.0.1
User            = aster
Password        = 74123
Database        = asterisk
Option          = 3
#Port           =

nano /etc/asterisk/res_odbc.conf

[ENV]
[mysql]
enabled => yes
dsn => MySQL-asterisk
username => aster
password => 74123
pre-connect => yes

nano /etc/asterisk/cdr_adaptive_odbc.conf

[main]
connection=mysql
table=cdr
alias start => calldate

В астере:

module load res_odbc.so
module load cdr_adaptive_odbc.conf

Просмотр данных в CDR (типовые запросы)

mysql -p asterisk
все звонки за текущий день
mysql> select calldate,src,dst,billsec,disposition,userfield from cdr where datediff(curdate(),calldate)<1;

Лечение мусора в консоли

dnf downgrade libedit --releasever=24

PostgreSQL

CREATE FUNCTION unix_timestamp(timestamp without time zone) RETURNS integer
    LANGUAGE sql
    AS $_$ 
SELECT date_part('epoch', $1)::INTEGER AS RESULT 
$_$;

CREATE TABLE cdr (
    calldate timestamp without time zone NOT NULL,
    clid character varying(80) NOT NULL,
    src character varying(80) NOT NULL,
    dst character varying(80) NOT NULL,
    dcontext character varying(80) NOT NULL,
    channel character varying(80) NOT NULL,
    dstchannel character varying(80) NOT NULL,
    lastapp character varying(80) NOT NULL,
    lastdata character varying(80) NOT NULL,
    duration integer NOT NULL,
    billsec integer NOT NULL,
    disposition character varying(45) NOT NULL,
    amaflags integer NOT NULL,
    accountcode character varying(20) NOT NULL,
    uniqueid character varying(150) NOT NULL,
    userfield character varying(255) NOT NULL,
    peeraccount character varying(20) NOT NULL,
    linkedid character varying(150) NOT NULL,
    sequence integer NOT NULL
);

ALTER TABLE cdr OWNER TO asterisk;

CREATE INDEX cdr_calldate ON cdr USING btree (calldate);

CREATE TABLE monitor (
    uuid character varying(64),
    sound bytea
);
ALTER TABLE monitor OWNER TO asterisk;
CREATE UNIQUE INDEX monitor_uuid_idx ON monitor USING btree (uuid);

CREATE TABLE quality (
    uuid character varying(50) NOT NULL,
    rtcp jsonb
);
ALTER TABLE quality OWNER TO asterisk;
ALTER TABLE ONLY quality
    ADD CONSTRAINT quality_pkey PRIMARY KEY (uuid);