Skip to content

Commit

Permalink
V0.3 (#17)
Browse files Browse the repository at this point in the history
- [APM] added mongoDB APM functions.
- [CONFIG MONGODB] added code for update2, store and destroy.
- [MONGO C LOGGIN] added mongoc logging handler.
- [UNIFIED CONFIG] unified configs for ast_mongo to one.
- [IMPROVED] release db pool properly.
- [MONGO C DRIVER] updated to 1.8.2
- [ASTERISK] updated to 15.1.3
- [CONFIG.JSON] removed useless parameters from config.json
- [CONFIG.JSON] specify 'bundled' to use bundled option with pjsip
- [UNIFIED CONFIG] unified configs for ast_mongo to one.
- [TEST] added new testing (#16)
    - [NEW TEST] added new test
    - [RES CONFIG MONGODB] added a feature to handle id as ObjectID
    - [DOCS] update docs for new test
    - [TRAVIS CI] added Travis CI for testing (#15)
  • Loading branch information
minoruta authored Apr 24, 2018
1 parent 6bada4b commit 0ef2406
Show file tree
Hide file tree
Showing 63 changed files with 9,894 additions and 329 deletions.
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
sudo: required
services:
- docker
before_install:
- docker pull minoruta/pjsip-node-alpine
- docker image ls
install:
- cd test/docker
- docker-compose build
before_script:
- docker-compose up -d
script:
- docker exec -it tester ash -c 'cd ast_mongo && npm install && npm test'
74 changes: 74 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
ARG VERSION_UBUNTU=latest
FROM ubuntu:$VERSION_UBUNTU
MAINTAINER KINOSHITA minoru <[email protected]>

ARG VERSION_ASTERISK=15.1.3
ARG VERSION_MONGOC=1.8.2

WORKDIR /root
RUN mkdir src
COPY src/* src/
RUN mkdir ast_mongo
#COPY ./LICENSE ast_mongo/
#COPY README.md ast_mongo/

RUN apt update -q \
&& apt install -y -q \
libssl-dev \
libsasl2-dev \
libncurses5-dev \
libnewt-dev \
libxml2-dev \
libsqlite3-dev \
libjansson-dev \
libcurl4-openssl-dev \
libsrtp0-dev \
pkg-config \
build-essential \
autoconf \
uuid-dev \
wget \
file \
git

RUN cd $HOME \
&& wget -nv "https://github.com/mongodb/mongo-c-driver/releases/download/$VERSION_MONGOC/mongo-c-driver-$VERSION_MONGOC.tar.gz" -O - | tar xzf - \
&& cd mongo-c-driver-$VERSION_MONGOC \
&& ./configure --disable-automatic-init-and-cleanup > /dev/null \
&& make all install \
&& cd $HOME \
&& rm -rf mongo-c-driver-$VERSION_MONGOC

RUN cd $HOME \
&& wget -nv "http://downloads.asterisk.org/pub/telephony/asterisk/releases/asterisk-$VERSION_ASTERISK.tar.gz" -O - | tar -zxf - \
&& cd asterisk-$VERSION_ASTERISK \
&& git config --global user.email "[email protected]" \
&& git init && git add . && git commit . -m "initial" \
&& cd $HOME/asterisk-$VERSION_ASTERISK/cdr \
&& cp $HOME/src/cdr_mongodb.c . \
&& git add . \
&& cd $HOME/asterisk-$VERSION_ASTERISK/cel \
&& cp $HOME/src/cel_mongodb.c . \
&& git add . \
&& cd $HOME/asterisk-$VERSION_ASTERISK/res \
&& cp $HOME/src/res_mongodb.c . \
&& cp $HOME/src/res_mongodb.exports.in . \
&& cp $HOME/src/res_config_mongodb.c . \
&& git add . \
&& cd $HOME/asterisk-$VERSION_ASTERISK/include/asterisk \
&& cp $HOME/src/res_mongodb.h . \
&& git add . \
&& cd $HOME/asterisk-$VERSION_ASTERISK \
&& patch -p1 -F3 -i $HOME/src/mongodb.for.asterisk.patch \
&& git diff build_tools/menuselect-deps.in configure.ac makeopts.in > $HOME/ast_mongo/mongodb.for.asterisk.patch \
&& git diff HEAD > $HOME/ast_mongo/ast_mongo-$VERSION_ASTERISK.patch \
&& ./bootstrap.sh \
&& ./configure --disable-xmldoc > /dev/null \
&& tar czf $HOME/ast_mongo/asterisk-$VERSION_ASTERISK-config.log.tgz config.log \
&& make all \
&& make install \
&& ldconfig /usr/lib \
&& make samples


CMD asterisk -c > /dev/null
92 changes: 68 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ Plugin name |Realtime |CDR|CEL|Source code|Config file(s)
The plugins are provided as source code patches to Asterisk.
See [patches](patches) in detail.

## Test
See [Test](test/docker).

## Test bench
## ~~Test bench~~
**(Deprecated, use [Test](test/docker) instead of it)**

The test bench based on Docker technology for these plugins is also provided.
You can examine how it works on your desktop simply.
Expand All @@ -47,13 +50,68 @@ Name of DB |Name of Collection |Comment
`cdr` | `cdr`
`cel` | `cel`

### Config files for the exmaple


- [`res_config_mongodb.conf`](test_bench/configs/res_config_mongodb.conf) for realtime configuration engine

[mongodb]
### Config files as example
- *[email protected]*: The three config files `res_config_mongodb.conf`, `cdr_mongodb.conf` and `cel_mongodb.conf` have compiled into one `ast_mongo.conf`.
- [`ast_mongo.conf`](test_bench/configs/ast_mongo.conf) for ast_mongo plugins;

;==========================================
;
; for common configuration
;
[common]
;------------------------------------------
; MongoDB C Driver - Logging configuration
; see http://mongoc.org/libmongoc/current/logging.html in detail
;
; -1 = disable logging of mongodb-c-driver
; 0 = MONGOC_LOG_LEVEL_ERROR,
; 1,2,...,
; 6 = MONGOC_LOG_LEVEL_TRACE
; default is -1
;mongoc_log_level=-1
;------------------------------------------
; MongoDB C Driver - APM configuration
; see http://mongoc.org/libmongoc/current/application-performance-monitoring.html in detail
;
; 0 = disable monitoring
; 0 != enable monitoring
; default is 0
;apm_command_monitoring=0
;apm_sdam_monitoring=0
;==========================================
;
; for realtime configuration engine
;
[config]
uri=mongodb://mongodb.local/asterisk ; location of database
;------------------------------------------
; 0 != enable APM
; default is disabled (0)
;apm=0
;==========================================
;
; for CDR plugin
;
[cdr]
uri=mongodb://mongodb.local/cdr ; location of database
database=cdr ; name of database
collection=cdr ; name of collection to record cdr data
;------------------------------------------
; 0 != enable APM
; default is disabled (0)
;apm=0
;==========================================
;
; for CEL plugin
;
[cel]
uri=mongodb://mongodb.local/cel ; location of database
database=cel ; name of database
collection=cel ; name of collection to record cel data
;------------------------------------------
; 0 != enable APM
; default is disabled (0)
;apm=0

- [`sorcery.conf`](test_bench/configs/sorcery.conf) specifies map from asterisk's resources to database's collections.

Expand All @@ -73,30 +131,16 @@ Name of DB |Name of Collection |Comment
ps_aors => mongodb,asterisk

; map extensions.conf to ast_config collection of asterisk database
extensions.conf => mongodb,asterisk,ast_config
extensions.conf => mongodb,asterisk,ast_config
pjsip.conf => mongodb,asterisk,ast_config

- [`cdr_mongodb.conf`](test_bench/configs/cdr_mongodb.conf) specifies the location, name and collection of database for cdr backend.

[mongodb]
uri=mongodb://mongodb.local/cdr ; location of database
database=cdr ; name of database
collection=cdr ; name of collection to record cdr data

- [`cel_mongodb.conf`](test_bench/configs/cel_mongodb.conf) specifies the location, name and collection of database for cel backend.

[mongodb]
uri=mongodb://mongodb.local/cel ; location of database
database=cel ; name of database
collection=cel ; name of collection to record cel data

- See Asterisk's official document [Setting up PJSIP Realtime][5] as well.

## License and Copyright

- The related code to Asterisk:
- The related code to Asterisk:
- GNU GENERAL PUBLIC LICENSE Version 2
- Any other resources and files:
- Any other resources and files:
- The MIT License (MIT)
- Copyright: (C) 2016-17, KINOSHITA minoru, [viktike][9] for cel_mongodb

Expand Down
20 changes: 18 additions & 2 deletions src/cdr_mongodb.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ ASTERISK_REGISTER_FILE()
#include "asterisk/res_mongodb.h"

static const char NAME[] = "cdr_mongodb";
static const char CATEGORY[] = "mongodb";
static const char CATEGORY[] = "cdr";
static const char URI[] = "uri";
static const char DATABSE[] = "database";
static const char COLLECTION[] = "collection";
static const char SERVERID[] = "serverid";
static const char CONFIG_FILE[] = "cdr_mongodb.conf";
static const char CONFIG_FILE[] = "ast_mongo.conf";

enum {
CONFIG_REGISTERED = 1 << 0,
Expand All @@ -61,6 +61,8 @@ static char *dbname = NULL;
static char *dbcollection = NULL;
static mongoc_client_pool_t *dbpool = NULL;
static bson_oid_t *serverid = NULL;
static void* apm_context = NULL;
static int apm_enabled = 0;

static int mongodb_log(struct ast_cdr *cdr)
{
Expand Down Expand Up @@ -212,6 +214,15 @@ static int mongodb_load_module(int reload)
bson_oid_init_from_string(serverid, tmp);
}

if ((tmp = ast_variable_retrieve(cfg, CATEGORY, "apm"))
&& (sscanf(tmp, "%u", &apm_enabled) != 1)) {
ast_log(LOG_WARNING, "apm must be a 0|1, not '%s'\n", tmp);
apm_enabled = 0;
}

if (apm_context)
ast_mongo_apm_stop(apm_context);

if (dbpool)
mongoc_client_pool_destroy(dbpool);
dbpool = mongoc_client_pool_new(uri);
Expand All @@ -220,6 +231,9 @@ static int mongodb_load_module(int reload)
break;
}

if (apm_enabled)
apm_context = ast_mongo_apm_start(dbpool);

res = 0; // suceess
} while (0);

Expand Down Expand Up @@ -249,6 +263,8 @@ static int unload_module(void)
ast_free(dbname);
if (dbcollection)
ast_free(dbcollection);
if (apm_context)
ast_mongo_apm_stop(apm_context);
if (dbpool)
mongoc_client_pool_destroy(dbpool);
return 0;
Expand Down
22 changes: 19 additions & 3 deletions src/cel_mongodb.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ ASTERISK_REGISTER_FILE()
// #define DATE_FORMAT "%Y-%m-%d %T.%6q"

static const char NAME[] = "cel_mongodb";
static const char CATEGORY[] = "mongodb";
static const char CATEGORY[] = "cel";
static const char URI[] = "uri";
static const char DATABSE[] = "database";
static const char COLLECTION[] = "collection";
static const char SERVERID[] = "serverid";
static const char CONFIG_FILE[] = "cel_mongodb.conf";
static const char CONFIG_FILE[] = "ast_mongo.conf";

enum {
CONFIG_REGISTERED = 1 << 0,
Expand All @@ -74,6 +74,8 @@ static char *dbname = NULL;
static char *dbcollection = NULL;
static mongoc_client_pool_t *dbpool = NULL;
static bson_oid_t *serverid = NULL;
static void* apm_context = NULL;
static int apm_enabled = 0;

static void mongodb_log(struct ast_event *event)
{
Expand All @@ -99,7 +101,7 @@ static void mongodb_log(struct ast_event *event)
};

if (ast_cel_fill_record(event, &record)) {
ast_log(LOG_ERROR, "unexpected error, failed to extract event data\n");
ast_log(LOG_ERROR, "unexpected error, failed to extract event data\n");
return;
}
/* Handle user define events */
Expand Down Expand Up @@ -247,6 +249,15 @@ static int _load_module(int reload)
bson_oid_init_from_string(serverid, tmp);
}

if ((tmp = ast_variable_retrieve(cfg, CATEGORY, "apm"))
&& (sscanf(tmp, "%u", &apm_enabled) != 1)) {
ast_log(LOG_WARNING, "apm must be a 0|1, not '%s'\n", tmp);
apm_enabled = 0;
}

if (apm_context)
ast_mongo_apm_stop(apm_context);

if (dbpool)
mongoc_client_pool_destroy(dbpool);
dbpool = mongoc_client_pool_new(uri);
Expand All @@ -255,6 +266,9 @@ static int _load_module(int reload)
break;
}

if (apm_enabled)
apm_context = ast_mongo_apm_start(dbpool);

res = 0; // suceess
} while (0);

Expand All @@ -280,6 +294,8 @@ static int unload_module(void)
ast_free(dbname);
if (dbcollection)
ast_free(dbcollection);
if (apm_context)
ast_mongo_apm_stop(apm_context);
if (dbpool)
mongoc_client_pool_destroy(dbpool);
return 0;
Expand Down
Loading

0 comments on commit 0ef2406

Please sign in to comment.