|
@@ -22,13 +22,13 @@ class ApiJsonEncoder(JSONEncoder):
|
|
|
def default(self, o):
|
|
def default(self, o):
|
|
|
if isinstance(o, dt):
|
|
if isinstance(o, dt):
|
|
|
return o.isoformat()
|
|
return o.isoformat()
|
|
|
- if isinstance(o, CELEventChannel):
|
|
|
|
|
|
|
+ if isinstance(o, CdrChannel):
|
|
|
return str(o)
|
|
return str(o)
|
|
|
- if isinstance(o, CELEvent):
|
|
|
|
|
|
|
+ if isinstance(o, CdrEvent):
|
|
|
return o.__dict__
|
|
return o.__dict__
|
|
|
- if isinstance(o, CELEvents):
|
|
|
|
|
|
|
+ if isinstance(o, CdrEvents) or isinstance(o, CelEvents):
|
|
|
return o.all
|
|
return o.all
|
|
|
- if isinstance(o, CELCall):
|
|
|
|
|
|
|
+ if isinstance(o, CdrCall) or isinstance(o, CelCall):
|
|
|
return o.__dict__
|
|
return o.__dict__
|
|
|
return JSONEncoder.default(self, o)
|
|
return JSONEncoder.default(self, o)
|
|
|
|
|
|
|
@@ -157,74 +157,33 @@ async def presenceStatusCallback(mngr: Manager, msg: Message):
|
|
|
if combinedState != prevState:
|
|
if combinedState != prevState:
|
|
|
await userStateChangeCallback(user, combinedState, prevState)
|
|
await userStateChangeCallback(user, combinedState, prevState)
|
|
|
|
|
|
|
|
-async def getCDR(start=None, end=None, **kwargs):
|
|
|
|
|
|
|
+async def getCDR(start=None, end=None, table='cdr', field='calldate'):
|
|
|
_cdr = {}
|
|
_cdr = {}
|
|
|
if end is None:
|
|
if end is None:
|
|
|
end = dt.now()
|
|
end = dt.now()
|
|
|
if start is None:
|
|
if start is None:
|
|
|
start=(end - td(hours=24))
|
|
start=(end - td(hours=24))
|
|
|
- async for row in db.iterate(query='''SELECT linkedid,
|
|
|
|
|
- uniqueid,
|
|
|
|
|
- calldate,
|
|
|
|
|
- did,
|
|
|
|
|
- src,
|
|
|
|
|
- dst,
|
|
|
|
|
- clid,
|
|
|
|
|
- dcontext,
|
|
|
|
|
- channel,
|
|
|
|
|
- dstchannel,
|
|
|
|
|
- lastapp,
|
|
|
|
|
- duration,
|
|
|
|
|
- billsec,
|
|
|
|
|
- disposition,
|
|
|
|
|
- recordingfile,
|
|
|
|
|
- cnum,
|
|
|
|
|
- cnam,
|
|
|
|
|
- outbound_cnum,
|
|
|
|
|
- outbound_cnam,
|
|
|
|
|
- dst_cnam,
|
|
|
|
|
- peeraccount
|
|
|
|
|
- FROM cdr
|
|
|
|
|
|
|
+ async for row in db.iterate(query='''SELECT *
|
|
|
|
|
+ FROM {table}
|
|
|
WHERE linkedid
|
|
WHERE linkedid
|
|
|
IN (SELECT DISTINCT(linkedid)
|
|
IN (SELECT DISTINCT(linkedid)
|
|
|
- FROM cdr
|
|
|
|
|
- WHERE calldate
|
|
|
|
|
- BETWEEN :start AND :end)
|
|
|
|
|
- ORDER BY linkedid,
|
|
|
|
|
- calldate,
|
|
|
|
|
- uniqueid;''',
|
|
|
|
|
|
|
+ FROM {table}
|
|
|
|
|
+ WHERE {field}
|
|
|
|
|
+ BETWEEN :start AND :end);'''.format(table=table,
|
|
|
|
|
+ field=field),
|
|
|
values={'start':start,
|
|
values={'start':start,
|
|
|
'end':end}):
|
|
'end':end}):
|
|
|
- event = {_k: str(_v) for _k, _v in row.items() if _k != 'linkedid' and _v != ''}
|
|
|
|
|
- _cdr.setdefault(row['linkedid'],[]).append(event)
|
|
|
|
|
|
|
+ if row['linkedid'] in _cdr:
|
|
|
|
|
+ _cdr[row['linkedid']].events.add(row)
|
|
|
|
|
+ else:
|
|
|
|
|
+ _cdr[row['linkedid']]=CdrCall(row)
|
|
|
cdr = []
|
|
cdr = []
|
|
|
for _id in sorted(_cdr.keys()):
|
|
for _id in sorted(_cdr.keys()):
|
|
|
- cdr.append({'id':_id,'events':_cdr[_id]})
|
|
|
|
|
|
|
+ cdr.append(_cdr[_id])
|
|
|
return cdr
|
|
return cdr
|
|
|
|
|
|
|
|
-async def getCEL(start=None, end=None, **kwargs):
|
|
|
|
|
- _cel = {}
|
|
|
|
|
- if end is None:
|
|
|
|
|
- end = dt.now()
|
|
|
|
|
- if start is None:
|
|
|
|
|
- start=(end - td(hours=24))
|
|
|
|
|
- async for row in db.iterate(query='''SELECT *
|
|
|
|
|
- FROM cel
|
|
|
|
|
- WHERE linkedid
|
|
|
|
|
- IN (SELECT DISTINCT(linkedid)
|
|
|
|
|
- FROM cel
|
|
|
|
|
- WHERE eventtime
|
|
|
|
|
- BETWEEN :start AND :end);''',
|
|
|
|
|
- values={'start':start,
|
|
|
|
|
- 'end':end}):
|
|
|
|
|
- if row['linkedid'] in _cel:
|
|
|
|
|
- _cel[row['linkedid']].events.add(row)
|
|
|
|
|
- else:
|
|
|
|
|
- _cel[row['linkedid']]=CELCall(row)
|
|
|
|
|
- cel = []
|
|
|
|
|
- for _id in sorted(_cel.keys()):
|
|
|
|
|
- cel.append(_cel[_id])
|
|
|
|
|
- return cel
|
|
|
|
|
|
|
+async def getCEL(start=None, end=None, table='cel', field='eventtime'):
|
|
|
|
|
+ return await getCDR(start, end, table, field)
|
|
|
|
|
|
|
|
@app.before_first_request
|
|
@app.before_first_request
|
|
|
async def initHttpClient():
|
|
async def initHttpClient():
|
|
@@ -809,8 +768,8 @@ class DeviceUnBind(Resource):
|
|
|
|
|
|
|
|
@app.route('/cdr')
|
|
@app.route('/cdr')
|
|
|
class CDR(Resource):
|
|
class CDR(Resource):
|
|
|
- @app.param('end', 'End of datetime range. Defaults to now. Allowed formats are: timestamp, ISO 8601 or yyyymmddHHMMSS', 'query')
|
|
|
|
|
- @app.param('start', 'Start of datetime range. Defaults to end-24h. Allowed formats are: timestamp, ISO 8601 or yyyymmddHHMMSS', 'query')
|
|
|
|
|
|
|
+ @app.param('end', 'End of datetime range. Defaults to now. Allowed formats are: timestamp, ISO 8601 or YYYYMMDDhhmmss', 'query')
|
|
|
|
|
+ @app.param('start', 'Start of datetime range. Defaults to end-24h. Allowed formats are: timestamp, ISO 8601 or YYYYMMDDhhmmss', 'query')
|
|
|
@app.response(HTTPStatus.OK, 'JSON reply')
|
|
@app.response(HTTPStatus.OK, 'JSON reply')
|
|
|
@app.response(HTTPStatus.UNAUTHORIZED, 'Authorization required')
|
|
@app.response(HTTPStatus.UNAUTHORIZED, 'Authorization required')
|
|
|
async def get(self):
|
|
async def get(self):
|
|
@@ -824,8 +783,8 @@ class CDR(Resource):
|
|
|
|
|
|
|
|
@app.route('/cel')
|
|
@app.route('/cel')
|
|
|
class CEL(Resource):
|
|
class CEL(Resource):
|
|
|
- @app.param('end', 'End of datetime range. Defaults to now. Allowed formats are: timestamp, ISO 8601 or yyyymmddHHMMSS', 'query')
|
|
|
|
|
- @app.param('start', 'Start of datetime range. Defaults to end-24h. Allowed formats are: timestamp, ISO 8601 or yyyymmddHHMMSS', 'query')
|
|
|
|
|
|
|
+ @app.param('end', 'End of datetime range. Defaults to now. Allowed formats are: timestamp, ISO 8601 or YYYYMMDDhhmmss', 'query')
|
|
|
|
|
+ @app.param('start', 'Start of datetime range. Defaults to end-24h. Allowed formats are: timestamp, ISO 8601 or YYYYMMDDhhmmss', 'query')
|
|
|
@app.response(HTTPStatus.OK, 'JSON reply')
|
|
@app.response(HTTPStatus.OK, 'JSON reply')
|
|
|
@app.response(HTTPStatus.UNAUTHORIZED, 'Authorization required')
|
|
@app.response(HTTPStatus.UNAUTHORIZED, 'Authorization required')
|
|
|
async def get(self):
|
|
async def get(self):
|
|
@@ -839,8 +798,8 @@ class CEL(Resource):
|
|
|
|
|
|
|
|
@app.route('/calls')
|
|
@app.route('/calls')
|
|
|
class Calls(Resource):
|
|
class Calls(Resource):
|
|
|
- @app.param('end', 'End of datetime range. Defaults to now. Allowed formats are: timestamp, ISO 8601 and yyyymmddHHMMSS', 'query')
|
|
|
|
|
- @app.param('start', 'Start of datetime range. Defaults to end-24h. Allowed formats are: timestamp, ISO 8601 and yyyymmddHHMMSS', 'query')
|
|
|
|
|
|
|
+ @app.param('end', 'End of datetime range. Defaults to now. Allowed formats are: timestamp, ISO 8601 and YYYYMMDDhhmmss', 'query')
|
|
|
|
|
+ @app.param('start', 'Start of datetime range. Defaults to end-24h. Allowed formats are: timestamp, ISO 8601 and YYYYMMDDhhmmss', 'query')
|
|
|
@app.response(HTTPStatus.OK, 'JSON reply')
|
|
@app.response(HTTPStatus.OK, 'JSON reply')
|
|
|
@app.response(HTTPStatus.UNAUTHORIZED, 'Authorization required')
|
|
@app.response(HTTPStatus.UNAUTHORIZED, 'Authorization required')
|
|
|
async def get(self):
|
|
async def get(self):
|