From 2bf2473d50357e5eef472302b3f09c02a0ccef63 Mon Sep 17 00:00:00 2001 From: Andreas Granig Date: Mon, 3 Nov 2014 15:24:42 +0100 Subject: [PATCH] MT#7793 fix alias handling and merge updates Fix exports for multiple alias numbers. Implement update merging of events. --- event-exporter.conf | 9 ++++++--- event-exporter.pl | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/event-exporter.conf b/event-exporter.conf index cca854b..54177cb 100644 --- a/event-exporter.conf +++ b/event-exporter.conf @@ -12,22 +12,25 @@ MAX_ROWS_PER_FILE=5000 # if 1, don't export events which are switched on and off again # during an export interval FILTER_FLAPPING=1 +# if 1 and FILTER_FLAPPING=1, merge subsequent start/update events +# during an export interval into one start event +MERGE_UPDATE=1 PREFIX=sipwise VERSION=001 SUFFIX=edr # none if no remote transfer should be done -TRANSFER_TYPE=sftp +TRANSFER_TYPE=none TRANSFER_HOST=demo.sipwise.com TRANSFER_PORT=22 TRANSFER_USER=cdrexport TRANSFER_PASS=export!!! TRANSFER_REMOTE=/home/jail/home/cdrexport -EXPORT_FIELDS = 'accounting.events.id', 'accounting.events.type', 'billing.contracts.external_id', 'billing.contacts.company', 'billing.voip_subscribers.external_id', 'voip_numbers_tmp.username', #'accounting.events.old_status', 'old_profile.name', #'accounting.events.new_status', 'new_profile.name', 'from_unixtime(accounting.events.timestamp)' +EXPORT_FIELDS = 'accounting.events.id', 'accounting.events.type', 'billing.contracts.external_id', 'billing.contacts.company', 'billing.voip_subscribers.external_id', '(select username from provisioning.voip_dbaliases tmp where tmp.subscriber_id = provisioning.voip_subscribers.id order by is_primary, id limit 1)', #'accounting.events.old_status', 'old_profile.name', #'accounting.events.new_status', 'new_profile.name', 'from_unixtime(accounting.events.timestamp)' -EXPORT_JOINS = { 'billing.voip_subscribers' => { 'billing.voip_subscribers.id' => 'accounting.events.subscriber_id' } }, { 'provisioning.voip_subscribers' => { 'provisioning.voip_subscribers.uuid' => 'billing.voip_subscribers.uuid' } }, { 'billing.contracts' => { 'billing.contracts.id' => 'billing.voip_subscribers.contract_id' } }, { 'billing.contacts' => { 'billing.contacts.id' => 'billing.contracts.contact_id' } }, { '(select * from provisioning.voip_dbaliases order by is_primary asc, id asc) as voip_numbers_tmp' => { 'provisioning.voip_subscribers.id' => 'voip_numbers_tmp.subscriber_id' } }, { 'provisioning.voip_subscriber_profiles as old_profile' => { 'old_profile.id' => 'accounting.events.old_status' } }, { 'provisioning.voip_subscriber_profiles as new_profile' => { 'new_profile.id' => 'accounting.events.new_status' } } +EXPORT_JOINS = { 'billing.voip_subscribers' => { 'billing.voip_subscribers.id' => 'accounting.events.subscriber_id' } }, { 'billing.contracts' => { 'billing.contracts.id' => 'billing.voip_subscribers.contract_id' } }, { 'billing.contacts' => { 'billing.contacts.id' => 'billing.contracts.contact_id' } }, { 'provisioning.voip_subscribers' => { 'provisioning.voip_subscribers.uuid' => 'billing.voip_subscribers.uuid' } }, { 'provisioning.voip_subscriber_profiles as old_profile' => { 'old_profile.id' => 'accounting.events.old_status' } }, { 'provisioning.voip_subscriber_profiles as new_profile' => { 'new_profile.id' => 'accounting.events.new_status' } } # important last comma if there is just one EXPORT_CONDITIONS = { 'accounting.events.export_status' => { '=' => '"unexported"' } }, diff --git a/event-exporter.pl b/event-exporter.pl index aa1669f..ae0edd4 100755 --- a/event-exporter.pl +++ b/event-exporter.pl @@ -8,12 +8,14 @@ use File::Temp; use File::Copy; use NGCP::CDR::Export; use NGCP::CDR::Transfer; +use Data::Dumper; my $collid = "eventexporter"; my $debug = 0; # default config values my $config = { 'default.FILTER_FLAPPING' => 0, + 'default.MERGE_UPDATE' => 0, 'default.PREFIX' => 'sipwise', 'default.VERSION' => '001', 'default.SUFFIX' => 'edr', @@ -147,6 +149,7 @@ my %lines = (); my $rows = $sth->fetchall_arrayref(); my %filter = (); my @filter_ids = (); + while(my $row = shift @{ $rows }) { my @head = @{ $row }[0 .. 4]; my ($id, $sub_id, $type, $old, $new) = @head; @@ -164,6 +167,27 @@ while(my $row = shift @{ $rows }) { my $line = join ",", @fields; $lines{$id} = $line; $rec_idx++; + } elsif($config->{'default.MERGE_UPDATE'} && $type =~ /^update_(.+)$/) { + my $t = $1; + my $k = "$sub_id;$t;$old"; + my $ids = $filter{$k} // []; + if(@{ $ids }) { + my $old_id = pop @{ $ids }; + say "... id $id is an update event of id $old_id, merge"; + delete $lines{$old_id}; + push @filter_ids, $old_id; + my $line = join ",", @fields; + $line =~ s/\"update_/\"start_/; + $lines{$id} = $line; + delete $filter{$k}; + $k = "$sub_id;$t;$new"; + push @{ $ids }, ($old_id, $id); + $filter{$k} = $ids; + } else { + my $line = join ",", @fields; + $lines{$id} = $line; + $rec_idx++; + } } elsif($type =~ /^end_(.+)$/) { my $t = $1; my $k = "$sub_id;$t;$old";