From 26d232437e43ed35bfddfd4c2d7ce68c0ccf6e13 Mon Sep 17 00:00:00 2001 From: Rene Krenn Date: Thu, 27 Jul 2017 22:27:14 +0200 Subject: [PATCH] TT#18755 load full fraud event collection Change-Id: I4d977e582ee2a201938dd26ab212c2982beec519 --- bin/ngcp-fraud-auto-lock | 19 +++++++++++++------ bin/ngcp-fraud-daily-lock | 19 +++++++++++++------ lib/NGCP/API/Client.pm | 4 ++-- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/bin/ngcp-fraud-auto-lock b/bin/ngcp-fraud-auto-lock index ee9cd23..a5c7b9f 100755 --- a/bin/ngcp-fraud-auto-lock +++ b/bin/ngcp-fraud-auto-lock @@ -60,12 +60,19 @@ sub get_data { my ($uri, $link) = @_; my $client = new NGCP::API::Client; $client->set_verbose($opts->{verbose}); - my $res = $client->request("GET", $uri); - die $res->result unless $res->is_success; - my $res_hash = $res->as_hash; - return [] unless $res_hash->{total_count} && $res_hash->{total_count} > 0; - my $data = $res_hash->{_embedded}{'ngcp:'.$link}; - return ref $data eq 'ARRAY' ? $data : [ $data ]; + $client->set_page_rows(10); + my @result = (); + while (my $res = $client->next_page($uri)) { + die $res->result unless $res->is_success; + my $res_hash = $res->as_hash; + my $data = $res_hash->{_embedded}{'ngcp:'.$link}; + if ('ARRAY' eq ref $data) { + push(@result,@$data); + } elsif ($data) { + push(@result,$data); + } + } + return \@result; } sub get_email_template { diff --git a/bin/ngcp-fraud-daily-lock b/bin/ngcp-fraud-daily-lock index 58be631..bb2aa14 100755 --- a/bin/ngcp-fraud-daily-lock +++ b/bin/ngcp-fraud-daily-lock @@ -60,12 +60,19 @@ sub get_data { my ($uri, $link) = @_; my $client = new NGCP::API::Client; $client->set_verbose($opts->{verbose}); - my $res = $client->request("GET", $uri); - die $res->result unless $res->is_success; - my $res_hash = $res->as_hash; - return [] unless $res_hash->{total_count} && $res_hash->{total_count} > 0; - my $data = $res_hash->{_embedded}{'ngcp:'.$link}; - return ref $data eq 'ARRAY' ? $data : [ $data ]; + $client->set_page_rows(10); + my @result = (); + while (my $res = $client->next_page($uri)) { + die $res->result unless $res->is_success; + my $res_hash = $res->as_hash; + my $data = $res_hash->{_embedded}{'ngcp:'.$link}; + if ('ARRAY' eq ref $data) { + push(@result,@$data); + } elsif ($data) { + push(@result,$data); + } + } + return \@result; } sub get_email_template { diff --git a/lib/NGCP/API/Client.pm b/lib/NGCP/API/Client.pm index 698ae29..1ad78c6 100644 --- a/lib/NGCP/API/Client.pm +++ b/lib/NGCP/API/Client.pm @@ -52,7 +52,7 @@ sub _create_ua { my $urlbase = sprintf "%s:%s", @{opts}{qw(host port)}; - $ua->credentials($urlbase, 'api_admin_system', + $ua->credentials($urlbase, 'api_admin_system', #'api_admin_http' @{opts}{qw(auth_user auth_pass)}); if($opts{verbose}) { @@ -74,7 +74,7 @@ sub _create_req { $req->header('Content-Type' => 'application/json'); } $req->header('Prefer' => 'return=representation'); - $req->header('NGCP-UserAgent' => 'NGCP::API::Client'); + $req->header('NGCP-UserAgent' => 'NGCP::API::Client'); #remove for 'api_admin_http' return $req; }