static void radius_log(struct ast_event *event) { int result = ERROR_RC; VALUE_PAIR *send = NULL; struct ast_cel_event_record record = { .version = AST_CEL_EVENT_RECORD_VERSION, }; if (ast_cel_fill_record(event, &record)) { return; } if (build_radius_record(&send, &record)) { ast_debug(1, "Unable to create RADIUS record. CEL not recorded!\n"); goto return_cleanup; } result = rc_acct(rh, 0, send); if (result != OK_RC) { ast_log(LOG_ERROR, "Failed to record Radius CEL record!\n"); } return_cleanup: if (send) { rc_avpair_free(send); } }
static void custom_log(struct ast_event *event) { CURL *curl; CURLcode res; struct ast_tm timeresult; struct curl_slist *headers = NULL; char start_time[80] = ""; struct ast_cel_event_record record = { .version = AST_CEL_EVENT_RECORD_VERSION, }; if (ast_cel_fill_record(event, &record)) { return; } ast_localtime(&record.event_time, &timeresult, NULL); ast_strftime(start_time, sizeof(start_time), DATE_FORMAT, &timeresult); curl = curl_easy_init(); if (curl) { headers = curl_slist_append(headers, "Content-Type: application/json"); curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.0.5:9200/asterisk/cel/"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); char *post_fields = malloc(sizeof(char) * 6048); sprintf(post_fields, "{\"EventName\": \"%s\", \"AccountCode\": \"%s\", \ \"CallerIDnum\": \"%s\", \"CallerIDname\": \"%s\", \ \"CallerIDani\": \"%s\", \"CallerIDrdnis\": \"%s\", \ \"CAllerIDdnid\": \"%s\", \"Exten\": \"%s\", \ \"Context\": \"%s\", \"Channel\": \"%s\", \ \"Application\": \"%s\", \"AppData\": \"%s\", \ \"EventTime\": \"%s\", \"AMAFlags\": \"%s\", \ \"UniqueID\": \"%s\", \"LinkedID\": \"%s\", \ \"Userfield\": \"%s\", \"Peer\": \"%s\", \ \"Peeraccount\": \"%s\", \"Extra\": \"%s\" }", record.event_name, record.account_code, record.caller_id_num, record.caller_id_name, record.caller_id_ani, record.caller_id_rdnis, record.caller_id_dnid, record.extension, record.context, record.channel_name, record.application_name, record.application_data, start_time, ast_channel_amaflags2string(record.amaflag), record.unique_id, record.linked_id, record.user_field, record.peer, record.peer_account, record.extra); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_fields); curl_easy_perform(curl); curl_slist_free_all(headers); curl_easy_cleanup(curl); free(post_fields); }
static void manager_log(const struct ast_event *event, void *userdata) { struct ast_tm timeresult; char start_time[80] = ""; struct ast_cel_event_record record = { .version = AST_CEL_EVENT_RECORD_VERSION, }; if (ast_cel_fill_record(event, &record)) { return; } if (!enablecel) { return; } ast_localtime(&record.event_time, &timeresult, NULL); ast_strftime(start_time, sizeof(start_time), DATE_FORMAT, &timeresult); manager_event(EVENT_FLAG_CALL, "CEL", "EventName: %s\r\n" "AccountCode: %s\r\n" "CallerIDnum: %s\r\n" "CallerIDname: %s\r\n" "CallerIDani: %s\r\n" "CallerIDrdnis: %s\r\n" "CallerIDdnid: %s\r\n" "Exten: %s\r\n" "Context: %s\r\n" "Channel: %s\r\n" "Application: %s\r\n" "AppData: %s\r\n" "EventTime: %s\r\n" "AMAFlags: %s\r\n" "UniqueID: %s\r\n" "LinkedID: %s\r\n" "Userfield: %s\r\n" "Peer: %s\r\n", record.event_name, record.account_code, record.caller_id_num, record.caller_id_name, record.caller_id_ani, record.caller_id_rdnis, record.caller_id_dnid, record.extension, record.context, record.channel_name, record.application_name, record.application_data, start_time, ast_cel_get_ama_flag_name(record.amaflag), record.unique_id, record.linked_id, record.user_field, record.peer); }
static void radius_log(struct ast_event *event) { int result = ERROR_RC; VALUE_PAIR *send = NULL; int ret = 0; char cdr_full_path[256]; struct ast_cel_event_record record = { .version = AST_CEL_EVENT_RECORD_VERSION, }; if (ast_cel_fill_record(event, &record)) { return; } if (build_radius_record(&send, &record)) { ast_debug(1, "Unable to create RADIUS record. CEL not recorded!\n"); goto return_cleanup; } result = rc_acct(rh, 0, send); if (result != OK_RC) { ast_log(LOG_ERROR, "Failed to record Radius CEL record! unique_id=%s\n", record.unique_id); /* file name */ if(record.unique_id && (!ast_strlen_zero(record.unique_id))){ snprintf(cdr_full_path,sizeof(cdr_full_path),"%s/%s",cdr_dir_tmp,record.unique_id); /* write cdr to file if rc_acct failed */ ret = save_avp_to_file(cdr_full_path,record.unique_id,send); if(!ret){ ast_log(LOG_ERROR,"Failed to write cdr to file! unique_id=%s\n", record.unique_id); } } goto return_cleanup; } return_cleanup: if (send) { rc_avpair_free(send); } }
static void manager_log(const struct ast_event *event, void *userdata) { struct ast_tm timeresult; char start_time[80] = ""; char user_defined_header[160]; const char *event_name; struct ast_cel_event_record record = { .version = AST_CEL_EVENT_RECORD_VERSION, }; if (!enablecel) { return; } if (ast_cel_fill_record(event, &record)) { return; } ast_localtime(&record.event_time, &timeresult, NULL); ast_strftime(start_time, sizeof(start_time), DATE_FORMAT, &timeresult); event_name = record.event_name; user_defined_header[0] = '\0'; if (record.event_type == AST_CEL_USER_DEFINED) { if (cel_show_user_def) { snprintf(user_defined_header, sizeof(user_defined_header), "UserDefType: %s\r\n", record.user_defined_name); } else { event_name = record.user_defined_name; } } manager_event(EVENT_FLAG_CALL, "CEL", "EventName: %s\r\n" "AccountCode: %s\r\n" "CallerIDnum: %s\r\n" "CallerIDname: %s\r\n" "CallerIDani: %s\r\n" "CallerIDrdnis: %s\r\n" "CallerIDdnid: %s\r\n" "Exten: %s\r\n" "Context: %s\r\n" "Channel: %s\r\n" "Application: %s\r\n" "AppData: %s\r\n" "EventTime: %s\r\n" "AMAFlags: %s\r\n" "UniqueID: %s\r\n" "LinkedID: %s\r\n" "Userfield: %s\r\n" "Peer: %s\r\n" "PeerAccount: %s\r\n" "%s" "Extra: %s\r\n", event_name, record.account_code, record.caller_id_num, record.caller_id_name, record.caller_id_ani, record.caller_id_rdnis, record.caller_id_dnid, record.extension, record.context, record.channel_name, record.application_name, record.application_data, start_time, ast_cel_get_ama_flag_name(record.amaflag), record.unique_id, record.linked_id, record.user_field, record.peer, record.peer_account, user_defined_header, record.extra); }
struct ast_channel *ast_cel_fabricate_channel_from_event(const struct ast_event *event) { struct varshead *headp; struct ast_var_t *newvariable; char timebuf[30]; struct ast_channel *tchan; struct ast_cel_event_record record = { .version = AST_CEL_EVENT_RECORD_VERSION, }; /* do not call ast_channel_alloc because this is not really a real channel */ if (!(tchan = ast_dummy_channel_alloc())) { return NULL; } headp = &tchan->varshead; /* first, get the variables from the event */ if (ast_cel_fill_record(event, &record)) { ast_channel_release(tchan); return NULL; } /* next, fill the channel with their data */ if ((newvariable = ast_var_assign("eventtype", record.event_name))) { AST_LIST_INSERT_HEAD(headp, newvariable, entries); } if (ast_strlen_zero(cel_dateformat)) { snprintf(timebuf, sizeof(timebuf), "%ld.%06ld", (long) record.event_time.tv_sec, (long) record.event_time.tv_usec); } else { struct ast_tm tm; ast_localtime(&record.event_time, &tm, NULL); ast_strftime(timebuf, sizeof(timebuf), cel_dateformat, &tm); } if ((newvariable = ast_var_assign("eventtime", timebuf))) { AST_LIST_INSERT_HEAD(headp, newvariable, entries); } if ((newvariable = ast_var_assign("eventextra", record.extra))) { AST_LIST_INSERT_HEAD(headp, newvariable, entries); } tchan->caller.id.name.valid = 1; tchan->caller.id.name.str = ast_strdup(record.caller_id_name); tchan->caller.id.number.valid = 1; tchan->caller.id.number.str = ast_strdup(record.caller_id_num); tchan->caller.ani.number.valid = 1; tchan->caller.ani.number.str = ast_strdup(record.caller_id_ani); tchan->redirecting.from.number.valid = 1; tchan->redirecting.from.number.str = ast_strdup(record.caller_id_rdnis); tchan->dialed.number.str = ast_strdup(record.caller_id_dnid); ast_copy_string(tchan->exten, record.extension, sizeof(tchan->exten)); ast_copy_string(tchan->context, record.context, sizeof(tchan->context)); ast_string_field_set(tchan, name, record.channel_name); ast_string_field_set(tchan, uniqueid, record.unique_id); ast_string_field_set(tchan, linkedid, record.linked_id); ast_string_field_set(tchan, accountcode, record.account_code); ast_string_field_set(tchan, peeraccount, record.peer_account); ast_string_field_set(tchan, userfield, record.user_field); pbx_builtin_setvar_helper(tchan, "BRIDGEPEER", record.peer); tchan->appl = ast_strdup(record.application_name); tchan->data = ast_strdup(record.application_data); tchan->amaflags = record.amaflag; return tchan; }
struct ast_channel *ast_cel_fabricate_channel_from_event(const struct ast_event *event) { struct varshead *headp; struct ast_var_t *newvariable; const char *mixed_name; char timebuf[30]; struct ast_channel *tchan; struct ast_cel_event_record record = { .version = AST_CEL_EVENT_RECORD_VERSION, }; /* do not call ast_channel_alloc because this is not really a real channel */ if (!(tchan = ast_dummy_channel_alloc())) { return NULL; } headp = ast_channel_varshead(tchan); /* first, get the variables from the event */ if (ast_cel_fill_record(event, &record)) { ast_channel_unref(tchan); return NULL; } /* next, fill the channel with their data */ mixed_name = (record.event_type == AST_CEL_USER_DEFINED) ? record.user_defined_name : record.event_name; if ((newvariable = ast_var_assign("eventtype", mixed_name))) { AST_LIST_INSERT_HEAD(headp, newvariable, entries); } if (ast_strlen_zero(cel_dateformat)) { snprintf(timebuf, sizeof(timebuf), "%ld.%06ld", (long) record.event_time.tv_sec, (long) record.event_time.tv_usec); } else { struct ast_tm tm; ast_localtime(&record.event_time, &tm, NULL); ast_strftime(timebuf, sizeof(timebuf), cel_dateformat, &tm); } if ((newvariable = ast_var_assign("eventtime", timebuf))) { AST_LIST_INSERT_HEAD(headp, newvariable, entries); } if ((newvariable = ast_var_assign("eventenum", record.event_name))) { AST_LIST_INSERT_HEAD(headp, newvariable, entries); } if ((newvariable = ast_var_assign("userdeftype", record.user_defined_name))) { AST_LIST_INSERT_HEAD(headp, newvariable, entries); } if ((newvariable = ast_var_assign("eventextra", record.extra))) { AST_LIST_INSERT_HEAD(headp, newvariable, entries); } ast_channel_caller(tchan)->id.name.valid = 1; ast_channel_caller(tchan)->id.name.str = ast_strdup(record.caller_id_name); ast_channel_caller(tchan)->id.number.valid = 1; ast_channel_caller(tchan)->id.number.str = ast_strdup(record.caller_id_num); ast_channel_caller(tchan)->ani.number.valid = 1; ast_channel_caller(tchan)->ani.number.str = ast_strdup(record.caller_id_ani); ast_channel_redirecting(tchan)->from.number.valid = 1; ast_channel_redirecting(tchan)->from.number.str = ast_strdup(record.caller_id_rdnis); ast_channel_dialed(tchan)->number.str = ast_strdup(record.caller_id_dnid); ast_channel_exten_set(tchan, record.extension); ast_channel_context_set(tchan, record.context); ast_channel_name_set(tchan, record.channel_name); ast_channel_uniqueid_set(tchan, record.unique_id); ast_channel_linkedid_set(tchan, record.linked_id); ast_channel_accountcode_set(tchan, record.account_code); ast_channel_peeraccount_set(tchan, record.peer_account); ast_channel_userfield_set(tchan, record.user_field); if ((newvariable = ast_var_assign("BRIDGEPEER", record.peer))) { AST_LIST_INSERT_HEAD(headp, newvariable, entries); } ast_channel_appl_set(tchan, ast_strdup(record.application_name)); ast_channel_data_set(tchan, ast_strdup(record.application_data)); ast_channel_amaflags_set(tchan, record.amaflag); return tchan; }
struct ast_channel *ast_cel_fabricate_channel_from_event(const struct ast_event *event) { struct varshead *headp; struct ast_var_t *newvariable; const char *mixed_name; char timebuf[30]; struct ast_channel *tchan; struct ast_cel_event_record record = { .version = AST_CEL_EVENT_RECORD_VERSION, }; struct ast_datastore *datastore; char *app_data; /* do not call ast_channel_alloc because this is not really a real channel */ if (!(tchan = ast_dummy_channel_alloc())) { return NULL; } headp = ast_channel_varshead(tchan); /* first, get the variables from the event */ if (ast_cel_fill_record(event, &record)) { ast_channel_unref(tchan); return NULL; } /* next, fill the channel with their data */ mixed_name = (record.event_type == AST_CEL_USER_DEFINED) ? record.user_defined_name : record.event_name; if ((newvariable = ast_var_assign("eventtype", mixed_name))) { AST_LIST_INSERT_HEAD(headp, newvariable, entries); } if (ast_strlen_zero(cel_dateformat)) { snprintf(timebuf, sizeof(timebuf), "%ld.%06ld", (long) record.event_time.tv_sec, (long) record.event_time.tv_usec); } else { struct ast_tm tm; ast_localtime(&record.event_time, &tm, NULL); ast_strftime(timebuf, sizeof(timebuf), cel_dateformat, &tm); } if ((newvariable = ast_var_assign("eventtime", timebuf))) { AST_LIST_INSERT_HEAD(headp, newvariable, entries); } if ((newvariable = ast_var_assign("eventenum", record.event_name))) { AST_LIST_INSERT_HEAD(headp, newvariable, entries); } if ((newvariable = ast_var_assign("userdeftype", record.user_defined_name))) { AST_LIST_INSERT_HEAD(headp, newvariable, entries); } if ((newvariable = ast_var_assign("eventextra", record.extra))) { AST_LIST_INSERT_HEAD(headp, newvariable, entries); } ast_channel_caller(tchan)->id.name.valid = 1; ast_channel_caller(tchan)->id.name.str = ast_strdup(record.caller_id_name); ast_channel_caller(tchan)->id.number.valid = 1; ast_channel_caller(tchan)->id.number.str = ast_strdup(record.caller_id_num); ast_channel_caller(tchan)->ani.number.valid = 1; ast_channel_caller(tchan)->ani.number.str = ast_strdup(record.caller_id_ani); ast_channel_redirecting(tchan)->from.number.valid = 1; ast_channel_redirecting(tchan)->from.number.str = ast_strdup(record.caller_id_rdnis); ast_channel_dialed(tchan)->number.str = ast_strdup(record.caller_id_dnid); ast_channel_exten_set(tchan, record.extension); ast_channel_context_set(tchan, record.context); ast_channel_name_set(tchan, record.channel_name); ast_channel_uniqueid_set(tchan, record.unique_id); ast_channel_linkedid_set(tchan, record.linked_id); ast_channel_accountcode_set(tchan, record.account_code); ast_channel_peeraccount_set(tchan, record.peer_account); ast_channel_userfield_set(tchan, record.user_field); if ((newvariable = ast_var_assign("BRIDGEPEER", record.peer))) { AST_LIST_INSERT_HEAD(headp, newvariable, entries); } ast_channel_amaflags_set(tchan, record.amaflag); /* We need to store an 'application name' and 'application * data' on the channel for logging purposes, but the channel * structure only provides a place to store pointers, and it * expects these pointers to be pointing to data that does not * need to be freed. This means that the channel's destructor * does not attempt to free any storage that these pointers * point to. However, we can't provide data in that form directly for * these structure members. In order to ensure that these data * elements have a lifetime that matches the channel's * lifetime, we'll put them in a datastore attached to the * channel, and set's the channel's pointers to point into the * datastore. The datastore will then be automatically destroyed * when the channel is destroyed. */ if (!(datastore = ast_datastore_alloc(&fabricated_channel_datastore, NULL))) { ast_channel_unref(tchan); return NULL; } if (!(app_data = ast_malloc(strlen(record.application_name) + strlen(record.application_data) + 2))) { ast_datastore_free(datastore); ast_channel_unref(tchan); return NULL; } ast_channel_appl_set(tchan, strcpy(app_data, record.application_name)); ast_channel_data_set(tchan, strcpy(app_data + strlen(record.application_name) + 1, record.application_data)); datastore->data = app_data; ast_channel_datastore_add(tchan, datastore); return tchan; }