Reference13r1:Concept App Service Reporting

From innovaphone-wiki

Jump to: navigation, search


The App Service Reporting is an App Service which can be installed on an innovaphone App Platform. It is used to provide call lists in myApps or myPBX and to create call reports.

Contents

Applies To

  • innovaphone PBX from version 13r1

Technical Overview

Image:Concept_reporting.png

Apps

innovaphone-reporting

This is the Reporting UI App.

innovaphone-calllist

This is the Call list App.

Parameters:

Websocket

innovaphone-calllist-api

This is an App, which provides the Call list API (com.innovaphone.calllist). This API can be used to find the recent calls of a user.

Parameters:

Websocket

mypbx

This is the interface for the support of the old myPBX client.

PBX Manager Plugins

Reporting

With the Reporting plugin App objects can be created, edited and deleted for the provided Apps.

Configuration

Following configuration options are offered:

  • CDR handling
    • automatic deletion of CDRs
    • deletion interval - default is 90 days
  • Account for CDR authentication
  • compatibility to use reporting for for myPBX call lists. Configured account data also have to be used in the MyPBX configuration.

Concepts

Database Structure

cdrs

Each received cdr-xml is formed by a cdr tag and an undefined number of event and group tags. (Refer to: CDR)

This section is composed by four tables: cdrs, events, groups and cdr_properties. The first three tables contain the corresponding fields to store the information contained in the cdr, event and group tags.
Each CDR represents the call in the view of one PBX object. So there might be multiple CDRs for one call if multiple PBX objects are used within the call.

  • cdr fields:
    • id
    • guid
    • user_guid
    • conf
    • sys
    • pbx
    • node
    • phys
    • device
    • h323
    • e164
    • cn
    • dn
    • email
    • dir
    • external
    • licensed
    • more_calls: set inside the CDR XML if there are multiple calls for the same call and user (e.g. multiple registrations)
    • conn_duration
    • alert_duration
    • call_duration
    • billing_duration
    • utc_stamp: unix timestamp in milliseconds since 1970
    • cause
    • remote_e164
    • remote_h323
    • remote_dn
    • call_list: CDR which is suitable for calllist or report queries (this flag is set depending on data received inside a CDR)
    • missed_call
    • status: the final state of the CDR (co: connected, al: alerting, er: error, bu: busy)
    • further: flag is set if CDR has been cancelled with cause 26 (non selected user clearing) indicating that there will be another more suitable CDR for the same call
    • user_id
    • callback_e164
    • callback_h323
    • callback_dn
    • callback_time
    • remote_clir: this flag is set if the remote side suppresses the calling information (number, name etc.)
  • event fields:
    • id
    • cdr_id
    • msg
    • ext
    • e164
    • h323
    • dn
    • conf
    • cause
    • time: the kernel uptime of the sending gateway in seconds. Substract time from a newer event (higher id) of a previous event to get the elapsed seconds inbetween.
    • clir
  • group fields:
    • id
    • name
    • active
    • type
    • cdr_id

id field is assigned by postgresql for each entry and has nothing to do with the information present in the cdr. It is different for each entry inside the table.

The events table has two additional fields, called cdr_id, to associate these events to the corresponding cdr entry and order_index to keep their position inside the cdr. Groups table has also the cdr_id field to associate the group entries to the corresponding cdr and events entries.

The table cdrp_properties from version 10 has been removed. Most columns can be now found directly in the table cdrs.
If you need the callflow in a similar way, you can JOIN the events table (GROUP BY cdr_id) and run a query which creates an array string from the events table:

array_agg(array[ev.msg, COALESCE(ev.e164,), COALESCE(ev.h323,), COALESCE(ev.dn,)] ORDER BY ev.id) AS callflow

cdr_users

This table contains a timestamp missed_calls_time for the last call list access by a user sip. It is used to retrieve information about missed calls since the last use of mypbx/myApps.
The timestamp clear_report_time indicates the last clearance time.

Database query samples

Calllist query

SELECT cdr.id, cdr.cn, cdr.conf, dir, external, alert_duration, call_duration, conn_duration, billing_duration, 
   sys, pbx, node, phys, cdr.cause, utc_stamp, status, further, 
   CASE WHEN remote_clir THEN '' ELSE remote_e164 END, 
   CASE WHEN remote_clir THEN '' ELSE remote_h323 END, 
   CASE WHEN remote_clir THEN '' ELSE remote_dn END, 
   callback_e164, callback_h323, callback_dn, callback_time, cdr.e164, cdr.h323 
FROM cdrs cdr 
JOIN cdr_users cu ON cdr.user_id = cu.id 
WHERE (cu.sip = 'sip' OR cu.guid = '00000000000000000000000000000000') 
   AND cdr.call_list = true 
   AND (cu.clear_report_time IS NULL OR utc_stamp > cu.clear_report_time) 
ORDER BY utc_stamp DESC, cdr.id DESC LIMIT '5' OFFSET '0'

Reporting query

WITH inp AS (SELECT 1611187200000::BIGINT AS from, 1611211143042::BIGINT AS to, 'sip'::VARCHAR AS sip, 'cn'::VARCHAR AS cn, 'TRUE'::BOOLEAN AS check_objects) 
SELECT cdr.id, cdr.cn, cdr.conf, dir, external, alert_duration, call_duration, conn_duration, 
   billing_duration, sys, pbx, node, phys, cdr.cause, utc_stamp, status, further, remote_e164, 
   remote_h323, remote_dn, callback_e164, callback_h323, callback_dn, callback_time, cdr.e164, 
   cdr.h323, cdr.dn, 
   array_agg(array[ev.msg, COALESCE(ev.e164,''), COALESCE(ev.h323,''), COALESCE(ev.dn,''), 'false'] ORDER BY ev.id) 
FROM inp, cdrs cdr 
JOIN cdr_users cu ON cdr.user_id = cu.id 
JOIN events ev ON ev.cdr_id = cdr.id 
WHERE cdr.call_list = true 
   AND cdr.licensed = true 
   AND utc_stamp >= inp.from 
   AND utc_stamp < inp.to 
   AND (inp.check_objects=false OR LOWER(cu.sip) LIKE LOWER(inp.sip) OR LOWER(cu.cn) LIKE LOWER(inp.cn)) 
GROUP BY cdr.id 
ORDER BY utc_stamp ASC 
LIMIT 10000

Database access

You have to grant database access in the AP-Platform.
The database user and password can be configured for every Reporting instance inside the AP Manager if you edit the instance.
These database credentials are just used internally and not e.g. inside the PBX App Objects.

Write an own app

Currently there can be two ways for an own App:

  • You receive the CDRs from the CDR interfaces yourself and store them into your own database with your own structure.
  • You hand the Reporting database credentials to your own App and connect directly to the Reporting database within your own App. This saves you the parsing and storing of the data, but you must maintain your queries if something in the Reporting database is changed. It is important, that you should just access this data readonly and that you do not modify table data!


Example for automatic download of existing CSV files:

  1. establish a web socket connection for reporting using PHP-access
  2. request the session key with { "mt": "Start" }
  3. receive the session key which e.g. looks like {"mt": "StartResult", "session": "189", "key": "552ca6fe05a19"}
  4. while the web socket connection is established, a GET request using received data can be sent like this:
    • http://AP-IP/DOMAIN/reporting/reports/report-20200408-1015.csv?session=189&key=552ca6fe05a19&lang=de&tz=Europe/Berlin&type=csv&sip=&from=1586304000000&to=1586333749607

Appendix

Personal tools