This enhancement provided via bug 9993, a patch to upgrade cdr_manager to have cdr_custom capabilities. Many thanks to eserra for this contribution
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@70122 f38db490-d61c-443f-a65b-d21fe96a405b
This commit is contained in:
parent
8e6636ad66
commit
c5045a2326
|
@ -41,29 +41,34 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||||
#include "asterisk/utils.h"
|
#include "asterisk/utils.h"
|
||||||
#include "asterisk/manager.h"
|
#include "asterisk/manager.h"
|
||||||
#include "asterisk/config.h"
|
#include "asterisk/config.h"
|
||||||
|
#include "asterisk/pbx.h"
|
||||||
|
|
||||||
#define DATE_FORMAT "%Y-%m-%d %T"
|
#define DATE_FORMAT "%Y-%m-%d %T"
|
||||||
#define CONF_FILE "cdr_manager.conf"
|
#define CONF_FILE "cdr_manager.conf"
|
||||||
|
#define CUSTOM_FIELDS_BUF_SIZE 1024
|
||||||
|
|
||||||
static char *name = "cdr_manager";
|
static char *name = "cdr_manager";
|
||||||
|
|
||||||
static int enablecdr = 0;
|
static int enablecdr = 0;
|
||||||
|
struct ast_str *customfields;
|
||||||
|
|
||||||
static int loadconfigurationfile(void)
|
static int load_config(void)
|
||||||
{
|
{
|
||||||
char *cat;
|
char *cat = NULL;
|
||||||
struct ast_config *cfg;
|
struct ast_config *cfg;
|
||||||
struct ast_variable *v;
|
struct ast_variable *v;
|
||||||
|
|
||||||
|
customfields = NULL;
|
||||||
|
|
||||||
cfg = ast_config_load(CONF_FILE);
|
cfg = ast_config_load(CONF_FILE);
|
||||||
if (!cfg) {
|
if (!cfg) {
|
||||||
/* Standard configuration */
|
/* Standard configuration */
|
||||||
|
ast_log(LOG_WARNING, "Failed to load configuration file. Module not activated.\n");
|
||||||
enablecdr = 0;
|
enablecdr = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cat = ast_category_browse(cfg, NULL);
|
while ( (cat = ast_category_browse(cfg, cat)) ) {
|
||||||
while (cat) {
|
|
||||||
if (!strcasecmp(cat, "general")) {
|
if (!strcasecmp(cat, "general")) {
|
||||||
v = ast_variable_browse(cfg, cat);
|
v = ast_variable_browse(cfg, cat);
|
||||||
while (v) {
|
while (v) {
|
||||||
|
@ -73,10 +78,23 @@ static int loadconfigurationfile(void)
|
||||||
|
|
||||||
v = v->next;
|
v = v->next;
|
||||||
}
|
}
|
||||||
|
} else if (!strcasecmp(cat, "mappings")) {
|
||||||
|
customfields = ast_str_create(CUSTOM_FIELDS_BUF_SIZE);
|
||||||
|
v = ast_variable_browse(cfg, cat);
|
||||||
|
while (v) {
|
||||||
|
if (customfields && !ast_strlen_zero(v->name) && !ast_strlen_zero(v->value)) {
|
||||||
|
if( (customfields->used + strlen(v->value) + strlen(v->name) + 14) < customfields->len) {
|
||||||
|
ast_str_append(&customfields, -1, "%s: ${CDR(%s)}\r\n", v->value, v->name);
|
||||||
|
ast_log(LOG_NOTICE, "Added mapping %s: ${CDR(%s)}\n", v->value, v->name);
|
||||||
|
} else {
|
||||||
|
ast_log(LOG_WARNING, "No more buffer space to add other custom fields\n");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Next category */
|
}
|
||||||
cat = ast_category_browse(cfg, cat);
|
v = v->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ast_config_destroy(cfg);
|
ast_config_destroy(cfg);
|
||||||
|
@ -90,6 +108,8 @@ static int manager_log(struct ast_cdr *cdr)
|
||||||
char strStartTime[80] = "";
|
char strStartTime[80] = "";
|
||||||
char strAnswerTime[80] = "";
|
char strAnswerTime[80] = "";
|
||||||
char strEndTime[80] = "";
|
char strEndTime[80] = "";
|
||||||
|
char buf[CUSTOM_FIELDS_BUF_SIZE];
|
||||||
|
struct ast_channel dummy;
|
||||||
|
|
||||||
if (!enablecdr)
|
if (!enablecdr)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -108,6 +128,14 @@ static int manager_log(struct ast_cdr *cdr)
|
||||||
ast_localtime(&t, &timeresult, NULL);
|
ast_localtime(&t, &timeresult, NULL);
|
||||||
strftime(strEndTime, sizeof(strEndTime), DATE_FORMAT, &timeresult);
|
strftime(strEndTime, sizeof(strEndTime), DATE_FORMAT, &timeresult);
|
||||||
|
|
||||||
|
/* Custom fields handling */
|
||||||
|
memset(buf, 0 , sizeof(buf));
|
||||||
|
if (customfields != NULL && customfields->used > 0) {
|
||||||
|
memset(&dummy, 0, sizeof(dummy));
|
||||||
|
dummy.cdr = cdr;
|
||||||
|
pbx_substitute_variables_helper(&dummy, customfields->str, buf, sizeof(buf) - 1);
|
||||||
|
}
|
||||||
|
|
||||||
manager_event(EVENT_FLAG_CALL, "Cdr",
|
manager_event(EVENT_FLAG_CALL, "Cdr",
|
||||||
"AccountCode: %s\r\n"
|
"AccountCode: %s\r\n"
|
||||||
"Source: %s\r\n"
|
"Source: %s\r\n"
|
||||||
|
@ -126,11 +154,12 @@ static int manager_log(struct ast_cdr *cdr)
|
||||||
"Disposition: %s\r\n"
|
"Disposition: %s\r\n"
|
||||||
"AMAFlags: %s\r\n"
|
"AMAFlags: %s\r\n"
|
||||||
"UniqueID: %s\r\n"
|
"UniqueID: %s\r\n"
|
||||||
"UserField: %s\r\n",
|
"UserField: %s\r\n"
|
||||||
|
"%s",
|
||||||
cdr->accountcode, cdr->src, cdr->dst, cdr->dcontext, cdr->clid, cdr->channel,
|
cdr->accountcode, cdr->src, cdr->dst, cdr->dcontext, cdr->clid, cdr->channel,
|
||||||
cdr->dstchannel, cdr->lastapp, cdr->lastdata, strStartTime, strAnswerTime, strEndTime,
|
cdr->dstchannel, cdr->lastapp, cdr->lastdata, strStartTime, strAnswerTime, strEndTime,
|
||||||
cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition),
|
cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition),
|
||||||
ast_cdr_flags2str(cdr->amaflags), cdr->uniqueid, cdr->userfield);
|
ast_cdr_flags2str(cdr->amaflags), cdr->uniqueid, cdr->userfield,buf);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -138,6 +167,9 @@ static int manager_log(struct ast_cdr *cdr)
|
||||||
static int unload_module(void)
|
static int unload_module(void)
|
||||||
{
|
{
|
||||||
ast_cdr_unregister(name);
|
ast_cdr_unregister(name);
|
||||||
|
if (customfields)
|
||||||
|
ast_free(customfields);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +178,7 @@ static int load_module(void)
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
/* Configuration file */
|
/* Configuration file */
|
||||||
if (!loadconfigurationfile())
|
if (!load_config())
|
||||||
return AST_MODULE_LOAD_DECLINE;
|
return AST_MODULE_LOAD_DECLINE;
|
||||||
|
|
||||||
res = ast_cdr_register(name, "Asterisk Manager Interface CDR Backend", manager_log);
|
res = ast_cdr_register(name, "Asterisk Manager Interface CDR Backend", manager_log);
|
||||||
|
@ -159,7 +191,11 @@ static int load_module(void)
|
||||||
|
|
||||||
static int reload(void)
|
static int reload(void)
|
||||||
{
|
{
|
||||||
loadconfigurationfile();
|
if (customfields) {
|
||||||
|
ast_free(customfields);
|
||||||
|
}
|
||||||
|
|
||||||
|
load_config();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,3 +4,12 @@
|
||||||
[general]
|
[general]
|
||||||
enabled = no
|
enabled = no
|
||||||
|
|
||||||
|
; The "mappings" category can be used to define additional "key: value" pairs
|
||||||
|
; that will be included in the manager event. (after AccountCode, Source, etc).
|
||||||
|
;
|
||||||
|
; Each line like "varname => label" will include a "label: ${CDR(varname)}"
|
||||||
|
; in the generated event where ${CDR(varname)} its replaced with its value
|
||||||
|
;
|
||||||
|
;[mappings]
|
||||||
|
;rate => Rate
|
||||||
|
;carrier => Carrier
|
||||||
|
|
Reference in New Issue