-
Notifications
You must be signed in to change notification settings - Fork 0
/
record_missed.py
executable file
·45 lines (37 loc) · 1.38 KB
/
record_missed.py
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
#!/usr/bin/python3
import sys
import json
import postgresql
from datetime import datetime
from datetime import timezone
dbconn = json.load(open("/opt/asterisk/database.json"))
db = postgresql.open(**dbconn)
tmstmp = datetime.utcnow().replace(tzinfo=timezone.utc)
out=open("/tmp/loghangup", "a")
out.write(str(tmstmp) + ' ' + repr(sys.argv) + '\n')
event = sys.argv[1]
cl_phone = sys.argv[2]
sip_host = sys.argv[3]
sip_ext = sys.argv[4]
cause = sys.argv[5]
cl_uid = sys.argv[6]
try:
q1 = db.prepare("select shop_phone, shop_name from shops join sip_ext on (phone=shop_phone) where host=$1 and myext=$2")
for (shop_phone, shop_name) in q1(sip_host, sip_ext):
# q2=db.prepare("insert into call_log (cl_tag, cl_client_phone, cl_shop_phone, cl_shop_name, cl_ring_time, cl_end_time, cl_close_time, cl_direction, cl_uid)"
# " values (3, $1, $2, $3, $4, $4, $4, 'incoming', $5) on conflict (cl_uid) do nothing")
q2=db.prepare("insert into call_log (cl_tag, cl_client_phone, cl_shop_phone, cl_shop_name, cl_ring_time, cl_end_time, cl_close_time, cl_direction, cl_uid)"
" values (3, $1, $2, $3, $4, $4, $4, 'incoming', $5)")
q2(cl_phone, shop_phone, shop_name, tmstmp, cl_uid)
break
except Exception as e:
out.write("error\n")
out.write(str(e)+"\n")
#cl_tag=3
#cl_client_phone=
#cl_shop_phone=
#cl_shop_name=
#cl_ring_time=
#cl_end_time=
#cl_close_time=
#cl_direction='incoming'