diff options
-rw-r--r-- | cdr/cdr_adaptive_odbc.c | 29 | ||||
-rw-r--r-- | configs/cdr_adaptive_odbc.conf.sample | 17 |
2 files changed, 41 insertions, 5 deletions
diff --git a/cdr/cdr_adaptive_odbc.c b/cdr/cdr_adaptive_odbc.c index 67c6043c3..1f04ef8d5 100644 --- a/cdr/cdr_adaptive_odbc.c +++ b/cdr/cdr_adaptive_odbc.c @@ -69,6 +69,7 @@ struct columns { struct tables { char *connection; char *table; + unsigned int usegmtime:1; AST_LIST_HEAD_NOLOCK(odbc_columns, columns) columns; AST_RWLIST_ENTRY(tables) list; }; @@ -86,7 +87,7 @@ static int load_config(void) char columnname[80]; char connection[40]; char table[40]; - int lenconnection, lentable; + int lenconnection, lentable, usegmtime; SQLLEN sqlptr; int res = 0; SQLHSTMT stmt = NULL; @@ -110,6 +111,10 @@ static int load_config(void) ast_copy_string(connection, tmp, sizeof(connection)); lenconnection = strlen(connection); + if (!ast_strlen_zero(tmp = ast_variable_retrieve(cfg, catg, "usegmtime"))) { + usegmtime = ast_true(tmp); + } + /* When loading, we want to be sure we can connect. */ obj = ast_odbc_request_obj(connection, 1); if (!obj) { @@ -146,6 +151,7 @@ static int load_config(void) break; } + tableptr->usegmtime = usegmtime; tableptr->connection = (char *)tableptr + sizeof(*tableptr); tableptr->table = (char *)tableptr + sizeof(*tableptr) + lenconnection + 1; ast_copy_string(tableptr->connection, connection, lenconnection + 1); @@ -354,11 +360,24 @@ static int odbc_log(struct ast_cdr *cdr) } AST_LIST_TRAVERSE(&(tableptr->columns), entry, list) { + int datefield = 0; + if (strcasecmp(entry->cdrname, "start") == 0) { + datefield = 1; + } else if (strcasecmp(entry->cdrname, "answer") == 0) { + datefield = 2; + } else if (strcasecmp(entry->cdrname, "end") == 0) { + datefield = 3; + } + /* Check if we have a similarly named variable */ - ast_cdr_getvar(cdr, entry->cdrname, &colptr, colbuf, sizeof(colbuf), 0, - (strcasecmp(entry->cdrname, "start") == 0 || - strcasecmp(entry->cdrname, "answer") == 0 || - strcasecmp(entry->cdrname, "end") == 0) ? 0 : 1); + if (datefield && tableptr->usegmtime) { + struct timeval tv = (datefield == 1) ? cdr->start : (datefield == 2) ? cdr->answer : cdr->end; + struct ast_tm tm = { 0, }; + ast_localtime(&tv, &tm, "UTC"); + ast_strftime(colbuf, sizeof(colbuf), "%Y-%m-%d %H:%M:%S", &tm); + } else { + ast_cdr_getvar(cdr, entry->cdrname, &colptr, colbuf, sizeof(colbuf), 0, datefield ? 0 : 1); + } if (colptr) { /* Check first if the column filters this entry. Note that this diff --git a/configs/cdr_adaptive_odbc.conf.sample b/configs/cdr_adaptive_odbc.conf.sample index a16626e58..d450dea68 100644 --- a/configs/cdr_adaptive_odbc.conf.sample +++ b/configs/cdr_adaptive_odbc.conf.sample @@ -28,6 +28,7 @@ ;[third] ;connection=sqlserver ;table=AsteriskCDR +;usegmtime=yes ; defaults to no ;alias src => source ;alias channel => source_channel ;alias dst => dest @@ -38,3 +39,19 @@ ;filter src => 123 +; On Wednesday 10 September 2008 21:11:16 Tilghman Lesher wrote: +; +; I thought that the sample cdr_adaptive_odbc.conf was rather clear, but +; apparently not. The point of this module is to allow you log whatever you +; like in terms of the CDR variables. Do you want to log uniqueid? Then simply +; ensure that your table has that column. If you don't want the column, ensure +; that it does not exist in the table structure. If you'd like to call uniqueid +; something else in your table, simply provide an alias in the configuration +; file that maps the standard CDR field name (uniqueid) to whatever column +; name you like. Perhaps you'd like some extra CDR values logged that aren't +; in the standard repertoire of CDR variables (some that come to mind are +; certain values used for LCR: route, per_minute_cost, and per_minute_price). +; Simply set those CDR variables in your dialplan, i.e. Set(CDR(route)=27), +; ensure that a corresponding column exists in your table, and cdr_adaptive_odbc +; will do the rest. + |