database - 可以直接从数据库查询 Asterisk CEL 信息吗? (PostgreSQL)

标签 database postgresql asterisk voip birt

你好,

我正在寻找一种使用 PostgreSQL 直接从数据库中查询我的 VOIP 信息的方法。 VOIP 服务是 CEL(每事件行) Asterisk 。 我的数据库如下所示:

|Field name  | Value/Example            | Notes
|eventtype   | CHAN_START               | The name of the event. The list of events that may occur can be found in Table 24.7, “CEL event types”.
|eventtime   | 2010-08-19 07:27:19      | The time that the event occurred.
|cidname     | Julie Bryant             | The caller ID name set on the channel associated with this event.
|cidnum      | 18435551212              | The caller ID number set on the channel associated with this event.
|cidani      | 18435551212              | The Automatic Number Identification (ANI) number set on the channel associated with this event.
|cidrdnis    | 18435551234              | The redirecting number set on the channel associated with this event.
|ciddnid     | 18435550987              | The dialed number set on the channel associated with this event.
|exten       | 101                      | The extension in the dialplan that is currently being executed.
|context     | LocalSets                | The context for the extension in the dialplan that is currently being executed.
|channame    | SIP/0004F2060EB4-00000010| The name of the channel associated with this event.
|appname     | Dial                     | The name of the dialplan application currently being executed.
|appdata     | SIP/0004F2060E55         | The arguments that were passed to the dialplan application that is currently being executed.
|amaflags    | DOCUMENTATION            | The Automatic Message Accounting (AMA) flag associated with this call. This may be one of the following: OMIT, BILLING, DOCUMENTATION, or Unknown.
|accountcode | 1234                     | An account ID. This field is user-defined and is empty by default.
|uniqueid    | 1282218999.18            | The unique ID for the channel that is associated with this event.
|userfield   | I like waffles!          | User-defined event content.
|linkedid    | 1282218999.18            | The per-call ID. This ID helps tie together multiple events from multiple channels that are all a part of the same logical call. The ID comes from the uniqueid of the first channel in the call.
|peer        | SIP/0004F2060E55-00000020| The name of the channel bridged to the channel identified by channame. 

我想获得今天日期的所有已接电话。我尝试了流动:

    --COMPLETE PHONECALL
SELECT  T.ID, T.EVENTTYPE, T.EVENTTIME, T.CID_NAME, T.CID_NUM, T.CID_ANI, T.CID_DNID, T.CID_RDNIS, T.EXTEN, T.CONTEXT, T.CHANNAME,
    T.APPNAME, T.APPDATA, T.AMAFLAGS, T.ACCOUNTCODE, T.PEERACCOUNT, T.UNIQUEID, T.LINKEDID
FROM PUBLIC.CEL T
WHERE LINKEDID IN (
    SELECT LINKEDID
    FROM PUBLIC.CEL T1
    WHERE DATE(T1.EVENTTIME) = (SELECT MAX(DATE(EVENTTIME)-1) FROM PUBLIC.CEL)
    AND EVENTTYPE = 'CHAN_START'
    AND CID_NUM NOT LIKE '20%'
    AND EXISTS(
        SELECT * 
        FROM PUBLIC.CEL T2
        WHERE 1=1 --DATE(T2.EVENTTIME) = (SELECT MAX(DATE(EVENTTIME)) FROM PUBLIC.CEL)
        AND EVENTTYPE = 'APP_START'
        AND T1.ID < T2.ID
        AND T1.UNIQUEID = T2.UNIQUEID
        AND EXISTS(
            SELECT * 
            FROM PUBLIC.CEL T3
            WHERE 1=1 --DATE(T3.EVENTTIME) = (SELECT MAX(DATE(EVENTTIME)) FROM PUBLIC.CEL)
            AND EVENTTYPE = 'ANSWER'
            AND T2.ID < T3.ID 
            AND T2.UNIQUEID = T3.UNIQUEID
            AND EXISTS(
                SELECT * 
                FROM PUBLIC.CEL T4
                WHERE 1=1 --DATE(T4.EVENTTIME) = (SELECT MAX(DATE(EVENTTIME)) FROM PUBLIC.CEL)
                AND EVENTTYPE = 'HANGUP'
                AND T3.ID < T4.ID 
                AND T3.UNIQUEID = T4.UNIQUEID
                AND EXISTS(
                    SELECT * 
                    FROM PUBLIC.CEL T5
                    WHERE 1=1 --DATE(T5.EVENTTIME) = (SELECT MAX(DATE(EVENTTIME)) FROM PUBLIC.CEL)
                    AND EVENTTYPE = 'CHAN_END'
                    AND T4.ID < T5.ID
                    AND T4.UNIQUEID = T5.UNIQUEID
                    )
                )
            )
        )
    GROUP BY T1.LINKEDID
    ORDER BY T1.LINKEDID ASC
)
ORDER BY T.LINKEDID ASC

但这没有用! 我尝试的另一件事是:

SELECT *
FROM PUBLIC.CEL
DATE(EVENTTIME) = (SELECT MAX(DATE(EVENTTIME)) 

然后我使用 birt 过滤所需的输出..但没有给我所需的输出。

有没有关于如何使用SQL查询CEL数据库的文档? 我不想使用像“Asternic”这样的工具

谢谢

附言。 这是一个解释 CEL“表”数据库的链接 http://www.asteriskdocs.org/en/3rd_Edition/asterisk-book-html-chunk/Monitoring_id246945.html#Monitoring_id255410

最佳答案

如果您只想要当天接听的电话,请执行以下操作:

select * from cel WHERE eventtype = 'ANSWER' and eventtime > curdate() limit 1 GROUP BY linkedid;

但我想您正在寻找更多信息?你能澄清一下你到底在找什么吗?您是否正在寻找所有已接电话的时间长度?还是您只想要接听电话的所有事件?

要获取已接电话的所有事件,您可以尝试类似的操作:

SELECT * FROM cel WHERE eventtime > curdate() and linkedid IN (select DISTINCT linkedid from cel WHERE eventtype = 'ANSWER' and eventtime > curdate());

请在评论中告诉我您想要获取的确切信息,我会看看我能想出什么。

关于database - 可以直接从数据库查询 Asterisk CEL 信息吗? (PostgreSQL),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30871166/

相关文章:

database - 线性数据库设计

PostgreSQL:在一个函数中插入、删除和更新的 If Else 语句

mysql - 无法从 Asterisk 拨号方案访问mysql数据库

database - 十六进制病毒特征库

database - 如何将基于 xBase 的 ERP 连接到 Web 应用程序?

python - Django 设置 DigitalOcean Postgres "DATABASES = {"错误

postgresql - 将字符串类型转换为整数

asterisk - 挂断通知声音

mysql - 将 Asterisk CDR 保存在 2 个不同的数据库中

php - Yii2 创建数据库连接