Skip to content
Snippets Groups Projects
Commit 7377ebbd authored by Matt O'Gorman's avatar Matt O'Gorman
Browse files

cdr_csv logging parameters in cdr.conf

 usegmtime, log date/time in GMT
 loguniqueid log uniqueid
 loguserfield log user field
 patch provided by bug 5015


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@11586 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent 30a97234
Branches
Tags
No related merge requests found
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
ASTERISK_FILE_VERSION(__FILE__, "$Revision$") ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/config.h"
#include "asterisk/channel.h" #include "asterisk/channel.h"
#include "asterisk/cdr.h" #include "asterisk/cdr.h"
#include "asterisk/module.h" #include "asterisk/module.h"
...@@ -52,6 +53,11 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") ...@@ -52,6 +53,11 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#define DATE_FORMAT "%Y-%m-%d %T" #define DATE_FORMAT "%Y-%m-%d %T"
static int usegmtime = 0;
static int loguniqueid = 0;
static int loguserfield = 0;
static char *config = "cdr.conf";
/* #define CSV_LOGUNIQUEID 1 */ /* #define CSV_LOGUNIQUEID 1 */
/* #define CSV_LOGUSERFIELD 1 */ /* #define CSV_LOGUSERFIELD 1 */
...@@ -89,6 +95,58 @@ static char *name = "csv"; ...@@ -89,6 +95,58 @@ static char *name = "csv";
static FILE *mf = NULL; static FILE *mf = NULL;
static int load_config(void)
{
struct ast_config *cfg;
struct ast_variable *var;
char *tmp;
usegmtime = 0;
loguniqueid = 0;
loguserfield = 0;
cfg = ast_config_load(config);
if (!cfg) {
ast_log(LOG_WARNING, "unable to load config: %s\n", config);
return -1;
}
var = ast_variable_browse(cfg, "csv");
if (!var) {
ast_config_destroy(cfg);
return -1;
}
tmp = ast_variable_retrieve(cfg, "csv", "usegmtime");
if (tmp) {
usegmtime = ast_true(tmp);
if (usegmtime) {
ast_log(LOG_DEBUG, "logging time in GMT\n");
}
}
tmp = ast_variable_retrieve(cfg, "csv", "loguniqueid");
if (tmp) {
loguniqueid = ast_true(tmp);
if (loguniqueid) {
ast_log(LOG_DEBUG, "logging CDR field UNIQUEID\n");
}
}
tmp = ast_variable_retrieve(cfg, "csv", "loguserfield");
if (tmp) {
loguserfield = ast_true(tmp);
if (loguserfield) {
ast_log(LOG_DEBUG, "logging CDR user-defined field\n");
}
}
ast_config_destroy(cfg);
return 0;
}
static int append_string(char *buf, char *s, size_t bufsize) static int append_string(char *buf, char *s, size_t bufsize)
{ {
int pos = strlen(buf); int pos = strlen(buf);
...@@ -140,7 +198,11 @@ static int append_date(char *buf, struct timeval tv, size_t bufsize) ...@@ -140,7 +198,11 @@ static int append_date(char *buf, struct timeval tv, size_t bufsize)
strncat(buf, ",", bufsize - strlen(buf) - 1); strncat(buf, ",", bufsize - strlen(buf) - 1);
return 0; return 0;
} }
localtime_r(&t,&tm); if (usegmtime) {
gmtime_r(&t,&tm);
} else {
localtime_r(&t,&tm);
}
strftime(tmp, sizeof(tmp), DATE_FORMAT, &tm); strftime(tmp, sizeof(tmp), DATE_FORMAT, &tm);
return append_string(buf, tmp, bufsize); return append_string(buf, tmp, bufsize);
} }
...@@ -181,15 +243,12 @@ static int build_csv_record(char *buf, size_t bufsize, struct ast_cdr *cdr) ...@@ -181,15 +243,12 @@ static int build_csv_record(char *buf, size_t bufsize, struct ast_cdr *cdr)
append_string(buf, ast_cdr_disp2str(cdr->disposition), bufsize); append_string(buf, ast_cdr_disp2str(cdr->disposition), bufsize);
/* AMA Flags */ /* AMA Flags */
append_string(buf, ast_cdr_flags2str(cdr->amaflags), bufsize); append_string(buf, ast_cdr_flags2str(cdr->amaflags), bufsize);
#ifdef CSV_LOGUNIQUEID
/* Unique ID */ /* Unique ID */
append_string(buf, cdr->uniqueid, bufsize); if (loguniqueid)
#endif append_string(buf, cdr->uniqueid, bufsize);
#ifdef CSV_LOGUSERFIELD
/* append the user field */ /* append the user field */
append_string(buf, cdr->userfield,bufsize); if(loguserfield)
#endif append_string(buf, cdr->userfield,bufsize);
/* If we hit the end of our buffer, log an error */ /* If we hit the end of our buffer, log an error */
if (strlen(buf) < bufsize - 5) { if (strlen(buf) < bufsize - 5) {
/* Trim off trailing comma */ /* Trim off trailing comma */
...@@ -268,6 +327,8 @@ int unload_module(void) ...@@ -268,6 +327,8 @@ int unload_module(void)
int load_module(void) int load_module(void)
{ {
int res; int res;
load_config();
res = ast_cdr_register(name, desc, csv_log); res = ast_cdr_register(name, desc, csv_log);
if (res) { if (res) {
...@@ -280,6 +341,7 @@ int load_module(void) ...@@ -280,6 +341,7 @@ int load_module(void)
int reload(void) int reload(void)
{ {
load_config();
return 0; return 0;
} }
......
...@@ -48,4 +48,9 @@ ...@@ -48,4 +48,9 @@
; submission of CDR data during asterisk shutdown, set this to "yes". Default ; submission of CDR data during asterisk shutdown, set this to "yes". Default
; is "yes". ; is "yes".
;safeshutdown=yes ;safeshutdown=yes
;
;[csv]
;usegmtime=yes ;log date/time in GMT
;loguniqueid=yes ;log uniqueid
;loguserfield=yes ;log user field
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment