-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcdrterminator.py
More file actions
executable file
·60 lines (47 loc) · 1.56 KB
/
Copy pathcdrterminator.py
File metadata and controls
executable file
·60 lines (47 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
import sys
import urllib
import urllib2
import re
import json
import time
from datetime import datetime, date, time, timedelta
import syslog
timeout = 60
if len(sys.argv) > 1:
timeout = int(sys.argv[1])
print "Checking CDR for calls older then %d mins" % timeout
request_headers = {
'Accept': 'application/json',
'Content-Type': 'application/json; charset=UTF-8'
}
url = 'http://127.0.0.1:10080'
parms = '?pageNum=1&proto=SIP&callState=answered,connected'
request = urllib2.Request(url+'/cdr/query/run'+parms, headers=request_headers)
response = urllib2.urlopen(request).read()
#print(response)
resp = json.loads(response)
cdr_data = resp['queryData']
cdr_list = cdr_data['cdrArray']
cdr_size = cdr_data['cdrCount']
#print(cdr_list)
count = 0
now = datetime.now()
#print "Now is %s" % now
for cdr in cdr_list:
count += 1
#print "CDR %d of %d" % (count,cdr_size)
#print "%r " % record
starttime = cdr['callStartTime']
starttime = starttime[0:19]
callId = cdr['callId']
print "CDR %d/%d: %s @ %s" % (count,cdr_size,callId, starttime)
st = datetime.strptime(starttime,"%Y-%m-%d %H:%M:%S")
durration = now - st
if durration > timedelta(minutes=timeout):
print " *** This an old call (%s) - Terminating ***" % durration
syslog.syslog('Terminating - CallId = %s , durration = %s' % (callId,durration))
parms = '?callId=%s' % callId
request = urllib2.Request(url+'/cdr/query/terminatecall'+parms, headers=request_headers)
response = urllib2.urlopen(request).read()
#print(response)