Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated and dockerized #8

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM debian:11-slim

MAINTAINER magonzalez112 <[email protected]>

ARG USERNAME=bridge-user
ARG USER_UID=1000
ARG USER_GID=$USER_UID

WORKDIR /opt
COPY asterisk-zammad-cti-bridge /opt
COPY config.cfg /opt

# Create the user and install dependencies
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& apt-get update \
&& apt-get install --no-install-recommends -y perl libanyevent-http-perl libconfig-simple-perl libdata-printer-perl \
liblog-any-perl liblog-any-adapter-dispatch-perl libwww-form-urlencoded-perl libnet-ssleay-perl libcrypt-ssleay-perl make cpanminus \
&& cpanm Asterisk::AMI
#&& apt-get install -y sudo \
#&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
#&& chmod 0440 /etc/sudoers.d/$USERNAME

RUN chown $USER_UID:$USER_GID config.cfg
RUN chown $USER_UID:$USER_GID asterisk-zammad-cti-bridge
RUN chmod u+x asterisk-zammad-cti-bridge
RUN chmod 600 config.cfg

USER $USERNAME

ENTRYPOINT ["/opt/asterisk-zammad-cti-bridge"]
87 changes: 25 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
This Perl script serves as a bridge between an Asterisk server and the Zammad CTI interface. It connects via AMI to Asterisk and monitors it for queue events; the relevant ones will be pushed to Zammad's CTI interface.

This version supports TLS, so you can run it in a different host from asterisk.

# Limitations

- No AMI SSL support yet, so use it only on the Asterisk host.
- Can only monitor queue events and nothing else.

# Setup
Expand All @@ -21,86 +22,48 @@ This Perl script serves as a bridge between an Asterisk server and the Zammad CT

3. Run `manager reload` in `asterisk -r`.

4. Install the Perl dependencies listed in the script.

E.g. on Debian stretch:

```
apt install libanyevent-http-perl libconfig-simple-perl libdata-printer-perl liblog-any-perl liblog-any-adapter-dispatch-perl libwww-form-urlencoded-perl
cpan Asterisk::AMI
```

5. Enable Zammad's CTI (Generic) interface.
4. Enable Zammad's CTI (Generic) interface.

6. Copy `config.cfg.sample` to `config.cfg`:
5. Rename `config.cfg.sample` to `config.cfg`. Edit and fill in your Zammad CTI URL and your AMI secret.

```
cp config.cfg.sample config.cfg
chmod 600 config.cfg
```

7. Edit `config.cfg` and fill in your Zammad CTI URL and your AMI secret.

8. Start the script:
6. Build and start the container:

```
./asterisk-zammad-cti-bridge
docker-compose up --build -d
```

# systemd

An example systemd service file `asterisk-zammad-cti-bridge.service.example` is provided. To install it:

1. Copy the file to `/etc/systemd/system` and remove the `.example`:
7. Check the logs and troubleshoot:

```
cp -a asterisk-zammad-cti-bridge.service.example /etc/systemd/system/asterisk-zammad-cti-bridge.service
docker-compose logs -f
```

# Rebuild when changes are made

2. Create the required user:
1. Take down and remove container:

```
useradd asterisk-zammad-cti-bridge
docker-compose down
```

3. Set the `config.cfg` permissions:
2. Force re-building:

```
chown asterisk-zammad-cti-bridge config.cfg
chmod 0600 config.cfg
docker-compose up --force-recreate --build -d
```

`asterisk-zammad-cti-bridge` will read `config.cfg` from the current working directory or from the application directory, so you can place it either in `/home/asterisk-zammad-cti-bridge` or in `/opt/asterisk-zammad-cti-bridge`.

4. Adapt the service file to your requirements:

- Change `ExecStart` to the correct path where you've placed `asterisk-zammad-cti-bridge.service`. The service defaults to `/opt/asterisk-zammad-cti-bridge`.

- If you want to use different Asterisk/Zammad instances from the config (see "Multiple instances" below), edit the service file as necessary. Create one systemd service file for each `asterisk-zammad-cti-bridge.service` instance.

5. Enable the service:

3. Remove orphan images:

```
systemctl enable asterisk-zammad-cti-bridge.service
docker image prune -f
```

6. Start the service:
BONUS. One-liner

```
systemctl start asterisk-zammad-cti-bridge.service
docker-compose up --force-recreate --build -d && docker image prune -f && docker-compose logs -f
```

# Multiple instances

If you want to bridge multiple Asterisk/Zammad instances, e.g. one Asterisk to two Zammad instances (prod and test), you need to run multiple `asterisk-zammad-cti-bridge` instances. Add a new section to `config.cfg` for each additional instance, e.g.:

```
[zammad-test]
url=https://zammad-test.example.com/api/v1/cti/mytoken
```

Then start a new `asterisk-zammad-cti-bridge` instance and tell it to read the `[zammad-test]` section instead of the `[zammad]` section:

```
./asterisk-zammad-cti-bridge --zammad zammad-test
```

# Multiple Instances
Add config.cfg sections and edit the entrypoint of the Dockerfile accordingly to load them by using an script.
Or just simply spin up a second container with a completely new config.cfg
2 changes: 1 addition & 1 deletion asterisk-zammad-cti-bridge
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ sub cb_default
to => $event->{Queue},
direction => "in",
callId => $event->{Queue}.$event->{Uniqueid},
"user[]" => $event->{CallerIDName},
};
}
elsif ($event->{Event} eq "AgentConnect")
Expand Down Expand Up @@ -393,4 +394,3 @@ my $connection_watcher = AnyEvent->timer(
);

AnyEvent->condvar->recv;

16 changes: 0 additions & 16 deletions asterisk-zammad-cti-bridge.service.example

This file was deleted.

5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: "3.3"
services:
asterisk-zammad-cti-bridge:
build: .
container_name: asterisk-zammad-cti-bridge