Was this page helpful?

CDR-stats - CDR報表工具(新版)

    介紹

    CDR_Stats-MonthlyTraffic.pngCDR-stats 這是一套非常資深的 Asterisk 報表工具,並且被收納在 FreePBX 的套件內,不過此篇要介紹的是最新版本。

    官方網站:http://www.cdr-stats.org/

    Prerequisties

    • Python 2.6+
       

    系統環境

    • CentOS 5.5
    • PIAF 1.7.5.5
       

    安裝心得

    • 為了要使 Python 2.6 可以工作,過程發生了許多問題,雖然耗時但也都能一一解決。
       

    更多文章

    升級 Python

    以 EPEL 套件庫使最簡單的升級方式,參閱 EPEL

    wget http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
    rpm -ivh epel-release-5-4.noarch.rpm
    yum install python26 
    

    使 setuptools 可支援 2.6,下載位址:http://pypi.python.org/pypi/setuptools

    wget http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg#md5=bfa92100bd772d5a213eedd356d64086
    sh setuptools-0.6c11-py2.6.egg 
    

    安裝 Diango

    官方網址:https://www.djangoproject.com/download/

    cd /usr/src
    wget http://www.djangoproject.com/download/1.3/tarball/
    tar xzf Django-1.3.tar.gz
    cd Django-1.3
    python26 setup.py install 
    

    安裝 Python Module: Dateutils

     easy_install DateUtils

    安裝 Python Module: Django Uni-Form

    下載最新版:https://github.com/areski/django-uni-form/downloads

    wget --no-check-certificate https://github.com/areski/django-uni-form/tarball/0.8.0
    tar xzf areski-django-uni-form-0.8.0-0-gd2a2b14.tar.gz
    cd areski-django-uni-form-3a7c9d6/
    python26 setup.py build
    python26 setup.py bdist_egg
    easy_install dist/django_uni_form-0.8.0-py2.6.egg

    編譯安裝 mod_python

    下載位址:http://archive.apache.org/dist/httpd/modpython/

    yum install httpd-devel
    cd /usr/src
    wget http://archive.apache.org/dist/httpd/modpython/mod_python-3.3.1.tgz
    tar xzf mod_python-3.3.1.tgz
    cd mod_python/
    ./configure --with-apxs=/usr/sbin/apxs --with-python=/usr/bin/python26 
    make
    make install
    

    安裝 CDR-stats 主程式

    下載最新版:https://github.com/areski/cdr-stats/downloads
    注意:安裝程式必須解壓到 /usr/src/

    mkdir /usr/share/django_app/
    cd /usr/src
    wget --no-check-certificate https://github.com/areski/cdr-stats/tarball/v1.1.0
    tar xzf areski-cdr-stats-v1.1.0-0-g7107bbd.tar.gz
    cd areski-cdr-stats-7d95205
    ln -s /usr/src/areski-cdr-stats-7d95205/cdr_stats/ /usr/share/django_app/cdr_stats
    

    安裝套件

    yum install sqlite sqlite-devel mod_python
    easy_install pip
    

    變更 Secret Key

    產生一組隨機的亂數組合
    < /dev/urandom tr -dc A-Za-z0-9| (head -c $1 > /dev/null 2>&1 || head -c 50);echo;
    
    將亂數密碼寫入 settings.py
    sed -i "s/^SECRET_KEY.*/SECRET_KEY = \'HereISranDOMpASSworD\'/g"  /usr/share/django_app/cdr_stats/settings.py 
    

    關閉 DEBUG

    sed -i "s/DEBUG = True/DEBUG = False/g"  /usr/share/django_app/cdr_stats/settings.py
    sed -i "s/TEMPLATE_DEBUG = DEBUG/TEMPLATE_DEBUG = False/g"  /usr/share/django_app/cdr_stats/settings.py 
    

    備份原有的 CDR DB

    mysqldump -uroot -p MYSQLROOTPASSWOOD asteriskcdrdb > /root/asteriskcdrdb-TODAY.sql
    

    設定 settings.py
    編輯 /usr/src/areski-cdr-stats-7d95205/cdr_stats/settings.py

    DATABASES = {
        'default': {
            'ENGINE': 'mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
            'NAME': 'asteriskcdrdb', # Or path to database file if using sqlite3.
            'USER': 'DB_USER',                      # Not used with sqlite3.
            'PASSWORD': 'DB_PASS',                  # Not used with sqlite3.
            'HOST': 'localhost',                      # Set to empty string for localhost. Not used with sqlite3.
            'PORT': '3306',                      # Set to empty string for default. Not used with sqlite3.
        },
    }
    ....
    MEDIA_URL = 'http://localhost:9000/resources/' 
    

    Tips:

    * 資料庫連結資訊必須與 /etc/asterisk/cdr_mysql.conf 相同。

    新增 SQLite 資料庫
    這是用來儲存網頁介面的帳號及一些資料,與 CDR 不同。

    cd /usr/share/django_app/cdr_stats/
    mkdir database
    chmod 777 databse
    python26 manage.py syncdb
    

    Would you like to create one now? (yes/no): 輸入 yes
    Username (Leave blank to use 'root'): 管理者帳號,預設是 root
    E-mail address: 隨便輸入郵址
    Password: 輸入密碼
    Password (again): 確認密碼

    *這是網頁登入的管理者帳號資訊

    更新 CDR 資料庫
    新增一個資料庫匯入檔 cdr-stats.sql

    cdr-stats-sql :

    use asteriskcdrdb
    CREATE TABLE cdr_new (
    acctid integer NOT NULL AUTO_INCREMENT PRIMARY KEY,
    src varchar(80) NOT NULL,
    dst varchar(80) NOT NULL,
    calldate datetime NOT NULL,
    clid varchar(80) NOT NULL,
    dcontext varchar(80) NOT NULL,
    channel varchar(80) NOT NULL,
    dstchannel varchar(80) NOT NULL,
    lastapp varchar(80) NOT NULL,
    lastdata varchar(80) NOT NULL,
    duration integer unsigned NOT NULL,
    billsec integer unsigned NOT NULL,
    disposition integer unsigned NOT NULL,
    amaflags integer unsigned NOT NULL,
    accountcode integer unsigned NOT NULL,
    uniqueid varchar(32) NOT NULL,
    userfield varchar(80) NOT NULL
    );
    
    
    INSERT INTO cdr_new (src,dst,calldate,clid,dcontext,channel,dstchannel,lastapp,lastdata,duration,billsec,disposition,amaflags,accountcode,uniqueid,userfield) SELECT src,dst,calldate,clid,dcontext,channel,dstchannel,lastapp,lastdata,duration,billsec,disposition,amaflags,accountcode,uniqueid,userfield FROM cdr;
    
    RENAME TABLE cdr TO cdr_backup;
    
    RENAME TABLE cdr_new TO cdr;
    ALTER TABLE cdr ADD INDEX ( calldate );
    ALTER TABLE cdr ADD INDEX ( dst );
    ALTER TABLE cdr ADD INDEX ( accountcode );
    
    quit
    

    執行匯入

    mysql -uroot -p < cdr-stats.sql
    

    設定 Apache
    新增設定檔

    /etc/httpd/conf.d/cdr-stats.conf :

    Listen *:9000
    
    <VirtualHost *:9000>
    DocumentRoot /usr/share/django_app/cdr_stats/
    ErrorLog /usr/share/django_app/err-cdr_stats.log
    
    <Location "/">
    SetHandler mod_python
    PythonHandler django.core.handlers.modpython
    PythonPath "['/usr/share/django_app/cdr_stats/', '/usr/share/django_app/'] + sys.path"
    SetEnv DJANGO_SETTINGS_MODULE cdr_stats.settings
    PythonDebug On
    SetEnv PYTHON_EGG_CACHE /usr/share/django_app/cdr_stats/.python-eggs
    </Location>
    
    <location "/media">
    SetHandler None
    </location>
    </VirtualHost>
    

    更新 Admin Media 路徑

    cd /usr/share/django_app/cdr_stats/resources
    ln -s /usr/lib/python2.6/site-packages/django/contrib/admin/media/ admin 
    

    Tips:

    * 確認 settings.py 的路徑有對應 ADMIN_MEDIA_PREFIX。

    * 確認 SoftLink 目錄是有效的,否則自行找尋相應目錄。

    建立一個 cach目錄

    mkdir /usr/share/django_app/cdr_stats/.python-eggs
    chmod 777 /usr/share/django_app/cdr_stats/.python-eggs
    service httpd restart

    Q & A

    Q: 執行 python26 manage.py syncdb 指令時,發生錯誤: Error loading MySQLdb module: No module named MySQLdb
    A: 解決如下

    yum install python26-devel mysql-devel
    easy_install mysql-python 
    

    Q: 錯誤訊息 Error: No module named south
    A:

    easy_install South

    Q: 錯誤訊息 Error: No module named dilla
    A:

    git clone git://github.com/aerosol/django-dilla
    python26 setup.py install

    Q: 為何網頁顯示不完整
    A: 請檢查 /usr/share/django_app/cdr_stats/settings.py,這個參數是否正確,改完必須重啟 httpd 服務。

    MEDIA_URL = 'http://123.123.123.123:9000/resources/'

    Q: 使用搜尋時,出現錯誤:CSRF verification failed. Request aborted
    A: 編輯 settings.py,加上這兩行

    'django.middleware.csrf.CsrfViewMiddleware', 
    'django.middleware.csrf.CsrfResponseMiddleware',

    重啟 httpd 服務。

    Q: 啟動 httpd 服務,錯誤 Syntax error on line 11 of /etc/httpd/conf.d/cdr-stats.conf
    A: 關閉 SELinux

    Was this page helpful?
    標籤 (Edit tags)
    • No tags

    文件 1

    文件大小日期附件上傳者 
     CDR_Stats-MonthlyTraffic.png
    CDR-stats
    19.93 KB13:39, 29 Jul 2011alang動作
    您必須 登入 才能發佈評論。
    Powered by MindTouch Core