From 326330fe4a2170b22f790e898c6a2ec910752bc2 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 17 Dec 2015 12:37:10 -0500 Subject: [PATCH] MT#15613 amend get_cdr_export_fields to accommodate event-exporter Change-Id: I9b7be06b6acce9ae6049fe96bb22e5e808f5b536 --- lib/get_cdr_export_fields | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/get_cdr_export_fields b/lib/get_cdr_export_fields index 59c82e7f..56b53700 100644 --- a/lib/get_cdr_export_fields +++ b/lib/get_cdr_export_fields @@ -2,6 +2,7 @@ # Iterates YAML config lists and translates them into strings suitable for the # cdr-exporter config file. # + # @param argv.type one of 'cdr' (default), 'events' # @param argv.admin_export_fields # @param argv.reseller_export_fields # @param argv.export_joins @@ -18,22 +19,28 @@ # presets that map directly into accounting.cdr.X columns - X_cdr_id_list = [ 'call_code', 'call_id', 'call_status', 'call_type', 'destination_account_id', 'destination_carrier_cost', 'destination_carrier_free_time', 'destination_customer_cost', 'destination_customer_free_time', 'destination_domain', 'destination_domain_in', 'destination_external_contract_id', 'destination_external_subscriber_id', 'destination_provider_id', 'destination_reseller_cost', 'destination_reseller_free_time', 'destination_user', 'destination_user_dialed', 'destination_user_id', 'destination_user_in', 'duration', 'peer_auth_realm', 'peer_auth_user', 'rated_at', 'rating_status', 'source_account_id', 'source_carrier_cost', 'source_carrier_free_time', 'source_cli', 'source_clir', 'source_customer_cost', 'source_customer_free_time', 'source_domain', 'source_external_contract_id', 'source_external_subscriber_id', 'source_ip', 'source_provider_id', 'source_reseller_cost', 'source_reseller_free_time', 'source_user', 'source_user_id', 'update_time' ]; + X_cdr_id_list = [ 'call_code', 'call_id', 'call_status', 'call_type', 'destination_account_id', 'destination_carrier_cost', 'destination_carrier_free_time', 'destination_customer_cost', 'destination_customer_free_time', 'destination_domain', 'destination_domain_in', 'destination_external_contract_id', 'destination_external_subscriber_id', 'destination_provider_id', 'destination_reseller_cost', 'destination_reseller_free_time', 'destination_user', 'destination_user_dialed', 'destination_user_id', 'destination_user_in', 'duration', 'peer_auth_realm', 'peer_auth_user', 'rated_at', 'rating_status', 'source_account_id', 'source_carrier_cost', 'source_carrier_free_time', 'source_cli', 'source_clir', 'source_customer_cost', 'source_customer_free_time', 'source_domain', 'source_external_contract_id', 'source_external_subscriber_id', 'source_ip', 'source_provider_id', 'source_reseller_cost', 'source_reseller_free_time', 'source_user', 'source_user_id', 'update_time', 'type', 'reseller_id', 'old_status', 'new_status' ]; FOREACH X_num IN [ 0 .. 9 ]; X_cdr_id_list.push("source_gpp" _ X_num, "destination_gpp" _ X_num); END; + X_type = argv.type; + IF X_type.length == 0; + X_type = 'cdr'; + END; + X_cdr_id_map = { }; FOREACH X_col IN X_cdr_id_list; X_upc = X_col.upper; - X_cdr_id_map.$X_upc = "accounting.cdr." _ X_col; + X_cdr_id_map.$X_upc = "accounting." _ X_type _ "." _ X_col; END; # other presets X_cdr_id_map.CDR_ID = "accounting.cdr.id"; + X_cdr_id_map.EVENT_ID = "accounting.events.id"; X_cdr_id_map.SOURCE_SUBSCRIBER_ID = "source_voip_subscribers.id"; X_cdr_id_map.DESTINATION_SUBSCRIBER_ID = "destination_voip_subscribers.id"; @@ -51,6 +58,13 @@ X_cdr_id_map.SOURCE_RESELLER_DETAIL = "source_reseller_bbz.detail"; X_cdr_id_map.DESTINATION_RESELLER_ZONE = "destination_reseller_bbz.zone"; X_cdr_id_map.DESTINATION_RESELLER_DETAIL = "destination_reseller_bbz.detail"; + X_cdr_id_map.CONTRACT_EXTERNAL_ID = "billing.contracts.external_id"; + X_cdr_id_map.COMPANY = "billing.contacts.company"; + X_cdr_id_map.SUBSCRIBER_EXTERNAL_ID = "billing.voip_subscribers.external_id"; + X_cdr_id_map.PRIMARY_NUMBER = "(select username from provisioning.voip_dbaliases tmp where tmp.subscriber_id = provisioning.voip_subscribers.id order by is_primary, id limit 1)"; + X_cdr_id_map.OLD_PROFILE_NAME = "old_profile.name"; + X_cdr_id_map.NEW_PROFILE_NAME = "new_profile.name"; + X_cdr_id_map.TIMESTAMP = "from_unixtime(accounting.events.timestamp)"; # translate the fields @@ -76,7 +90,13 @@ out.joins = [ ]; FOREACH X_f IN argv.export_joins; - out.joins.push("{ '" _ X_f.table _ ' ' _ X_f.alias _ "' => { '" _ X_f.key_column _ "' => '" _ X_f.reference_column _ "' } }"); + IF X_f.alias.length > 0; + X_table_spec = X_f.table _ ' ' _ X_f.alias; + ELSE; + X_table_spec = X_f.table; + END; + + out.joins.push("{ '" _ X_table_spec _ "' => { '" _ X_f.key_column _ "' => '" _ X_f.reference_column _ "' } }"); END; out.conditions = [ ];