Skip to content

Commit 68deae2

Browse files
committed
bug fixes
1 parent b723f1f commit 68deae2

File tree

7 files changed

+56
-40
lines changed

7 files changed

+56
-40
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ docker-compose.override.yml
99
deploy/ansible-deployment
1010
odoo/src/odoo
1111
# Ignore .conf files from local bound conainer folder
12-
asterisk/etc/asterisk/
12+
asterisk/etc/asterisk/*.conf

asterisk/Dockerfile

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1-
# vim:set ft=dockerfile:
2-
FROM litnimax/alpine-asterisk
1+
FROM alpine:edge
32

4-
ENV maintainer [email protected]
5-
6-
RUN apk update && \
7-
apk add supervisor git python py2-pip py2-tornado py2-setproctitle py2-gevent py2-requests py2-paho-mqtt
3+
RUN apk update && apk upgrade && \
4+
apk add supervisor git python py2-pip py2-tornado py2-setproctitle \
5+
py2-gevent py2-requests py2-paho-mqtt \
6+
asterisk asterisk-odbc asterisk-sample-config asterisk-sounds-en asterisk-sounds-moh asterisk-srtp
87

98
#Install optional tools
10-
RUN apk add tcpdump ethtool vlan iftop ngrep bash vim screen tmux mosquitto-clients
9+
RUN apk add tcpdump ethtool vlan iftop ngrep bash vim screen tmux mosquitto-clients curl
10+
11+
# grab dockerize for generation of the configuration file and wait on postgres
12+
RUN curl https://github.com/jwilder/dockerize/releases/download/v0.6.0/dockerize-alpine-linux-amd64-v0.6.0.tar.gz -L | tar xz -C /usr/local/bin
1113

1214
RUN mkdir /var/log/supervisor
1315

14-
COPY ./ /
16+
# Asterisk conf templates
17+
COPY ./etc/ /etc/
18+
COPY ./services /services/
1519

1620
RUN pip install -r /services/requirements.txt
21+
22+
COPY ./docker-entrypoint.sh /
23+
24+
EXPOSE 5060/udp 8088 5038
25+
26+
ENTRYPOINT ["/docker-entrypoint.sh"]

asterisk/etc/supervisord.conf

+9-9
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ directory=/services
2929
command=python asterisk_helper.py
3030
redirect_stderr=true
3131

32-
[program:ami_broker]
33-
directory=/services
34-
command=python ami_broker.py
35-
redirect_stderr=true
36-
37-
[program:stasis_apps]
38-
directory=/services
39-
command=python stasis_apps.py
40-
redirect_stderr=true
32+
#[program:ami_broker]
33+
#directory=/services
34+
#command=python ami_broker.py
35+
#redirect_stderr=true
36+
37+
#[program:stasis_apps]
38+
#directory=/services
39+
#command=python stasis_apps.py
40+
#redirect_stderr=true

asterisk/services/mqtt_client.py

+22-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import logging
23
import paho.mqtt.client as mqtt
34
import re
45
import socket
@@ -12,13 +13,13 @@
1213
MQTT_KEEPALIVE_INTERVAL = 45
1314
HOSTNAME = socket.gethostname()
1415

16+
logging.basicConfig(level=logging.INFO)
1517

16-
17-
class Client():
18+
class Client:
1819

1920
def __init__(self):
2021
self.uid = os.environ.get('UID') or '{}'.format(uuid.getnode())
21-
print 'UID: ' + self.uid
22+
logging.info('UID: ' + self.uid)
2223
self.mqtt_client = mqtt.Client(client_id=self.uid)
2324
self.mqtt_client.on_connect = self.on_connect
2425
self.mqtt_client.on_message = self.on_message
@@ -27,57 +28,63 @@ def __init__(self):
2728
self.mqtt_client.on_log = self.on_log
2829
# Subscribe to myself
2930
self.mqtt_client.connect(MQTT_HOST, MQTT_PORT, MQTT_KEEPALIVE_INTERVAL)
30-
self.mqtt_client.subscribe('/asterisk/' + self.uid + '/#', 0)
31+
self.mqtt_client.subscribe('asterisk/' + self.uid + '/#', 0)
3132
self.mqtt_client.loop_forever()
3233

3334

34-
3535
def on_connect(self, client, userdata, flags, rc):
36-
print("rc: " + str(rc))
36+
logging.info("rc: " + str(rc))
3737

3838

3939
def on_message(self, client, userdata, msg):
40-
print(msg.info, msg.dup, msg.mid, msg.qos, msg.retain, msg.state, msg.timestamp, msg.topic)
41-
found = re.search('^/asterisk/{}/(.+)$'.format(self.uid), msg.topic)
40+
logging.info('Topic: {}, Dup: {}, Mid: {}, QoS: {}, Retain: {}, '
41+
'State: {}, Info: {}'.format(msg.topic, msg.dup, msg.mid,
42+
msg.qos, msg.retain, msg.state, msg.info))
43+
found = re.search('^asterisk/{}/(.+)$'.format(self.uid), msg.topic)
4244
if not found:
43-
print('Error: topic {} not understood.'.format(msg.topic))
45+
logging.error('Error: topic {} not understood.'.format(msg.topic))
46+
return
4447
event_handler = getattr(self, 'on_' + found.group(1), self.handler_not_found)
4548
event_handler(client, userdata, msg)
4649

50+
4751
def on_publish(self, client, obj, mid):
48-
print("mid: " + str(mid))
52+
logging.info("mid: " + str(mid))
4953

5054

5155
def on_subscribe(self, client, obj, mid, granted_qos):
52-
print("Subscribed: " + str(mid) + " " + str(granted_qos))
56+
logging.info("Subscribed: " + str(mid) + " " + str(granted_qos))
5357

5458

5559
def on_log(self, client, obj, level, string):
56-
print(string)
60+
logging.info(string)
5761

5862

5963
def handler_not_found(self, client, userdata, msg):
60-
print 'Topic {} handler not found.'.format(msg.topic)
64+
logging.error('Topic {} handler not found.'.format(msg.topic))
6165

6266

6367
def _extract_message(self, payload):
6468
try:
6569
msg = json.loads(payload)
6670
return msg
6771
except ValueError as e:
68-
print(e.message, ': ', payload)
72+
logging.error(e.message, ': ', payload)
6973

7074

7175
def on_file(self, client, userdata, msg):
7276
data = self._extract_message(msg.payload)
7377
file_name = data.get('FileName')
7478
dest_folder = data.get('DestinationFolder')
7579
filename = os.path.join(dest_folder, file_name)
76-
print 'Updating file %s' % filename
80+
logging.info('Updating file %s' % filename)
7781
with open(filename, 'w') as f:
7882
f.write(data.get('Content'))
7983

8084

85+
def on_sip_reload(self, client, userdata, msg):
86+
logging.info('SIP reload')
87+
8188

8289
# Initiate MQTT Client
8390
mqttc = Client()

asterisk/services/requirements.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ odoorpc
44
py-Asterisk
55
terminado
66

7-
#next dependencies are installed with aline's apk but left here for reference
8-
#gevent
9-
#requests
10-
#setproctitle
7+
# Next dependencies are installed with aline's apk but left here for reference
8+
# gevent
9+
# requests
10+
# setproctitle

broker/Dockerfile

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ FROM alpine:edge
22

33
ENV maintainer [email protected]
44

5-
RUN apk add --no-cache bash mosquitto
5+
RUN apk add --no-cache bash mosquitto mosquitto-clients
66

77
EXPOSE 1883
88

99
CMD ["/usr/sbin/mosquitto", "-v"]
10-

odoo/local-src/asterisk_base/models/server.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def sync_conf(self, conf):
115115
conf.filename,
116116
conf.server.name,
117117
broker_host))
118-
topic = '/asterisk/' + self.uid + '/file'
118+
topic = 'asterisk/' + self.uid + '/file'
119119
msg = {
120120
'Content': conf.content,
121121
'FileName': conf.filename,

0 commit comments

Comments
 (0)