TT#68300 Fix coding style, indentation and spacing

Change-Id: I380ca0cffc1b163ff7af914dcd069b79891cf634
changes/50/34750/2
Guillem Jover 6 years ago
parent 82af7f6424
commit f69d3e8bc2

@ -1,6 +1,8 @@
#!/usr/bin/perl
use strict;
use warnings;
use English;
use Getopt::Long;
use NGCP::API::Client;
@ -13,26 +15,31 @@ my $opts = {
verbose => 0,
};
GetOptions( $opts,
GetOptions($opts,
'help|h' => sub { usage() },
'verbose',
) or usage();
sub check_params {
my @missing;
foreach my $param (@required) {
push @missing, $param unless $opts->{$param};
}
usage(join(' ', @missing)) if scalar @missing;
return;
}
sub usage {
my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
-verbose => 1,
-message => $missing ? "Missing parameters: $missing" : '',
);
pod2usage(
-exitval => $missing ? 1 : 0,
-verbose => 1,
-message => $missing ? "Missing parameters: $missing" : '',
);
return;
}

@ -1,6 +1,8 @@
#!/usr/bin/perl
use strict;
use warnings;
use English;
use Getopt::Long;
use Pod::Usage;
@ -15,7 +17,7 @@ my $opts = {
verbose => 0,
};
GetOptions( $opts,
GetOptions($opts,
'help|h' => sub { usage() },
'billing_profile_id=i',
'contact_id=i',
@ -25,20 +27,25 @@ GetOptions( $opts,
sub check_params {
my @missing;
foreach my $param (@required) {
push @missing, $param unless $opts->{$param};
}
usage(join(' ', @missing)) if scalar @missing;
return;
}
sub usage {
my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
-verbose => 99,
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '',
);
pod2usage(
-exitval => $missing ? 1 : 0,
-verbose => 99,
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '',
);
return;
}
@ -48,10 +55,11 @@ sub main {
my $client = NGCP::API::Client->new(verbose => $opts->{verbose});
my $uri = '/api/customers/';
my %data = map { $_ => $opts->{$_} }
qw(billing_profile_id contact_id type status);
my %data = map {
$_ => $opts->{$_}
} qw(billing_profile_id contact_id type status);
my $res = $client->request('POST', $uri, \%data);
print $res->result."\n";
print $res->result . "\n";
return !$res->is_success;
}

@ -1,6 +1,8 @@
#!/usr/bin/perl
use strict;
use warnings;
use English;
use Getopt::Long;
use Pod::Usage;
@ -16,7 +18,7 @@ my $opts = {
verbose => 0,
};
GetOptions( $opts,
GetOptions($opts,
'help|h' => sub { usage() },
'domain=s',
'reseller_id=i',
@ -27,6 +29,7 @@ GetOptions( $opts,
sub check_params {
my @missing;
foreach my $arg (@ARGV) {
if ($arg =~ /^[^-]/) {
$opts->{domain} = $arg;
@ -37,16 +40,20 @@ sub check_params {
push @missing, $param unless $opts->{$param};
}
usage(join(' ', @missing)) if scalar @missing;
return;
}
sub usage {
my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
-verbose => 99,
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '',
);
pod2usage(
-exitval => $missing ? 1 : 0,
-verbose => 99,
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '',
);
return;
}
@ -61,7 +68,7 @@ sub main {
$data{'_' . $elem . '_reload'} = $opts->{$elem};
}
my $res = $client->request('POST', $uri, \%data);
print $res->result."\n";
print $res->result . "\n";
return !$res->is_success;
}

@ -1,6 +1,8 @@
#!/usr/bin/perl
use strict;
use warnings;
use English;
use Getopt::Long;
use Pod::Usage;
@ -14,7 +16,7 @@ my $opts = {
verbose => 0,
};
GetOptions( $opts,
GetOptions($opts,
'help|h' => sub { usage() },
'customer_id=i',
'username|u=s',
@ -30,20 +32,25 @@ GetOptions( $opts,
sub check_params {
my @missing;
foreach my $param (@required) {
push @missing, $param unless $opts->{$param};
}
usage(join(' ', @missing)) if scalar @missing;
return;
}
sub usage {
my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
-verbose => 99,
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '',
);
pod2usage(
-exitval => $missing ? 1 : 0,
-verbose => 99,
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '',
);
return;
}
@ -59,8 +66,9 @@ sub main {
}
my $uri = '/api/subscribers/';
my %data = map { $_ => $opts->{$_} }
qw(customer_id username password webpassword);
my %data = map {
$_ => $opts->{$_}
} qw(customer_id username password webpassword);
$data{primary_number} = { map { $_ => $opts->{$_} } qw(cc ac sn) };
$data{administrative} = $opts->{admin};
my $tmp = $dom->as_hash->{_embedded}->{'ngcp:domains'};
@ -70,7 +78,7 @@ sub main {
$data{domain_id} = $tmp->{id};
}
my $res = $client->request('POST', $uri, \%data);
print $res->result."\n";
print $res->result . "\n";
return !$res->is_success;
}

@ -1,6 +1,8 @@
#!/usr/bin/perl
use strict;
use warnings;
use English;
use Getopt::Long;
use Pod::Usage;
@ -24,32 +26,40 @@ my $opts = {
my $config;
GetOptions( $opts,
GetOptions($opts,
'help|h' => sub { usage() },
'verbose',
) or usage();
sub check_params {
my @missing;
foreach my $param (@required) {
push @missing, $param unless $opts->{$param};
}
usage(join(' ', @missing)) if scalar @missing;
return;
}
sub usage {
my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
-verbose => 1,
-message => $missing ? "Missing parameters: $missing" : '',
);
pod2usage(
-exitval => $missing ? 1 : 0,
-verbose => 1,
-message => $missing ? "Missing parameters: $missing" : '',
);
return;
}
sub load_config {
$config = XML::Simple->new()->XMLin($config_file, ForceArray => [ 'credit_warnings' ])
or die "Cannot load config: $config_file: $ERRNO\n";
$config = XML::Simple->new()->XMLin(
$config_file,
ForceArray => [ 'credit_warnings' ],
) or die "Cannot load config: $config_file: $ERRNO\n";
return;
}
@ -58,9 +68,11 @@ sub send_email {
my $template = get_email_template() || return;
my $vars = { domain => $cwarning->{domain},
threshold => $cwarning->{threshold},
adminmail => $config->{adminmail} };
my $vars = {
domain => $cwarning->{domain},
threshold => $cwarning->{threshold},
adminmail => $config->{adminmail},
};
foreach my $data (@{$contracts}) {
if (exists $data->{threshold}) {
@ -85,8 +97,8 @@ EOF
my $email = Email::Simple->create(
header => [
To => ref $cwarning->{recipients} eq 'ARRAY'
? join(', ', @{$cwarning->{recipients}})
: $cwarning->{recipients},
? join(', ', @{$cwarning->{recipients}})
: $cwarning->{recipients},
From => $template->{from_email},
Subject => $template->{subject},
],
@ -108,18 +120,19 @@ sub get_data {
verbose => $opts->{verbose},
page_rows => $page_size,
);
my @result = ();
while (my $res = $client->next_page($uri)) {
die "$res->result\n" unless $res->is_success;
my $res_hash = $res->as_hash;
my $data = $res_hash->{_embedded}{'ngcp:'.$link};
my $data = $res_hash->{_embedded}{'ngcp:' . $link};
if ('ARRAY' eq ref $data) {
unless ($process_code->($data)) {
push(@result,@$data);
push @result, @{$data};
}
} elsif ($data) {
unless ($process_code->([ $data ])) {
push(@result,$data);
push @result, $data;
}
}
}
@ -138,6 +151,7 @@ sub get_email_template {
sub main {
check_params();
load_config();
my $cwarnings = ref $config->{credit_warnings} eq 'ARRAY'
? $config->{credit_warnings}
: [ $config->{credit_warnings} ];
@ -158,9 +172,11 @@ sub main {
my $ratio = $balance->{ratio} // 1.0;
my $threshold = $cwarning->{threshold} * $ratio;
next if $balance->{cash_balance} >= $threshold;
my $data = { map { $_ => $balance->{$_} } qw(id cash_balance) };
my $data = {
map { $_ => $balance->{$_} } qw(id cash_balance)
};
$data->{threshold} = $threshold if $ratio < 1.0;
push @contracts,$data;
push @contracts, $data;
}
return 1;
}
@ -172,6 +188,7 @@ sub main {
print $EVAL_ERROR if $EVAL_ERROR;
}
}
return 0;
}

@ -1,6 +1,8 @@
#!/usr/bin/perl
use strict;
use warnings;
use English;
use Getopt::Long;
use Pod::Usage;
@ -16,7 +18,7 @@ my $opts = {
verbose => 0,
};
GetOptions( $opts,
GetOptions($opts,
'help|h' => sub { usage() },
'domain=s',
'skip_xmpp',
@ -26,20 +28,25 @@ GetOptions( $opts,
sub check_params {
my @missing;
foreach my $param (@required) {
push @missing, $param unless $opts->{$param};
}
usage(join(' ', @missing)) if scalar @missing;
return;
}
sub usage {
my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
-verbose => 99,
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '',
);
pod2usage(
-exitval => $missing ? 1 : 0,
-verbose => 99,
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '',
);
return;
}
@ -49,13 +56,15 @@ sub main {
my $client = NGCP::API::Client->new(verbose => $opts->{verbose});
# domain_id
my $dom = $client->request('GET', '/api/domains/?domain='.$opts->{domain});
my $dom = $client->request('GET', '/api/domains/?domain=' . $opts->{domain});
if ($dom->as_hash->{total_count} != 1) {
die "Domain $opts->{domain} not found\n";
}
my $uri = '/api/domains/';
my %data = map { '_'.$_.'_reload' => $opts->{$_} } qw(skip_xmpp skip_sip);
my %data = map {
'_' . $_ . '_reload' => $opts->{$_}
} qw(skip_xmpp skip_sip);
my $dom_id;
my $tmp = $dom->as_hash->{_embedded}->{'ngcp:domains'};
if (ref $tmp eq 'ARRAY') {
@ -66,7 +75,7 @@ sub main {
die "Domain $opts->{domain} not found\n" unless $dom_id;
$uri .= $dom_id;
my $res = $client->request('DELETE', $uri, \%data);
print $res->result."\n";
print $res->result . "\n";
return !$res->is_success;
}

@ -1,6 +1,8 @@
#!/usr/bin/perl
use strict;
use warnings;
use English;
use Getopt::Long;
use Pod::Usage;
@ -22,7 +24,7 @@ my $PROGRAM_BASE = 'ngcp-fraud-notifier';
my $retcode = 0;
my $piddir = '/run/ngcp-fraud-notifier';
my $pidfile = "$piddir/ngcp-fraud-notifier.pid";
my $pf = File::Pid->new({ file => $pidfile });
my $pf = File::Pid->new({ file => $pidfile });
local $PROGRAM_NAME = $PROGRAM_BASE;
local $OUTPUT_AUTOFLUSH = 1;
@ -37,7 +39,7 @@ my $opts = {
my $config;
GetOptions( $opts,
GetOptions($opts,
'help|h' => sub { usage() },
'verbose',
) or usage();
@ -48,19 +50,24 @@ sub DESTROY {
sub check_params {
my @missing;
foreach my $param (@required) {
push @missing, $param unless $opts->{$param};
}
usage(join(' ', @missing)) if scalar @missing;
return;
}
sub usage {
my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
-verbose => 1,
-message => $missing ? "Missing parameters: $missing" : '',
);
pod2usage(
-exitval => $missing ? 1 : 0,
-verbose => 1,
-message => $missing ? "Missing parameters: $missing" : '',
);
return;
}
@ -83,11 +90,11 @@ sub get_data {
while (my $res = $client->next_page($uri)) {
die "$res->result\n" unless $res->is_success;
my $res_hash = $res->as_hash;
my $data = $res_hash->{_embedded}{'ngcp:'.$link};
my $data = $res_hash->{_embedded}{'ngcp:' . $link};
if ('ARRAY' eq ref $data) {
push(@result,@$data);
push @result, @{$data};
} elsif ($data) {
push(@result,$data);
push @result, $data;
}
if (defined $code and 'CODE' eq ref $code) {
$code->(\@result);
@ -99,6 +106,7 @@ sub get_data {
sub get_email_template {
my $event = shift;
my $lock_type = $event->{interval_lock} ? 'lock' : 'warning';
my $reseller_id = $event->{reseller_id};
my @templates_data = ();
@ -110,8 +118,8 @@ sub get_email_template {
}
my $selected_template;
foreach my $template (@templates_data) {
next if $template->{name} ne 'customer_fraud_'.$lock_type.'_default_email'
&& $template->{name} ne 'customer_fraud_'.$lock_type.'_email';
next if $template->{name} ne 'customer_fraud_' . $lock_type . '_default_email'
&& $template->{name} ne 'customer_fraud_' . $lock_type . '_email';
next if $template->{reseller_id} && $template->{reseller_id} != $reseller_id;
$selected_template = $template;
last if $template->{reseller_id};
@ -130,20 +138,22 @@ sub send_email {
my $template = get_email_template($event);
my $vars = { adminmail => $config->{adminmail},
customer_id => $event->{contract_id},
interval => $event->{interval},
interval_cost => sprintf('%.2f', $event->{interval_cost}/100),
interval_limit => sprintf('%.2f', $event->{interval_limit}/100),
type => $event->{type} eq 'profile_limit'
? 'billing profile' : 'customer',
};
my $vars = {
adminmail => $config->{adminmail},
customer_id => $event->{contract_id},
interval => $event->{interval},
interval_cost => sprintf('%.2f', $event->{interval_cost} / 100),
interval_limit => sprintf('%.2f', $event->{interval_limit} / 100),
type => $event->{type} eq 'profile_limit'
? 'billing profile' : 'customer',
};
foreach my $subscriber (@{$subscribers}) {
$vars->{subscribers} .= sprintf "%s\@%s %s\n",
@{$subscriber}{qw(username domain)},
$subscriber->{external_id}
? '('.$subscriber->{external_id}.')' : '';
? '(' . $subscriber->{external_id} . ')'
: '';
}
my $tt = Template->new();
@ -183,20 +193,26 @@ sub update_notify_status {
my $client = NGCP::API::Client->new(verbose => $opts->{verbose});
my $now = strftime('%Y-%m-%d %H:%M:%S', localtime);
my $uri = '/api/customerfraudevents/'.$event->{id};
my $data = [ { op => 'replace',
path => '/notify_status',
value => 'notified' },
{ op => 'replace',
path => '/notified_at',
value => $now } ];
my $uri = '/api/customerfraudevents/' . $event->{id};
my $data = [
{
op => 'replace',
path => '/notify_status',
value => 'notified',
},
{
op => 'replace',
path => '/notified_at',
value => $now,
},
];
my $res = $client->request('PATCH', $uri, $data);
return;
}
sub main {
if (my $num = $pf->running) {
print "$PROGRAM_BASE is already running.\n";
$retcode = 1;
@ -207,22 +223,26 @@ sub main {
check_params();
load_config();
get_data(
sprintf('/api/customerfraudevents/?no_count=true&notify_status=%s','new'),'customerfraudevents', sub {
my $events = shift;
foreach my $event (@{$events}) {
if ($event->{interval_notify}) {
my $subscribers = get_data(sprintf('/api/subscribers/?customer_id=%d',
$event->{contract_id}),
'subscribers');
next unless scalar @$subscribers;
eval {
send_email($event, $subscribers);
};
print $EVAL_ERROR if $EVAL_ERROR;
sprintf('/api/customerfraudevents/?no_count=true&notify_status=%s', 'new'),
'customerfraudevents',
sub {
my $events = shift;
foreach my $event (@{$events}) {
if ($event->{interval_notify}) {
my $subscribers = get_data(sprintf('/api/subscribers/?customer_id=%d',
$event->{contract_id}),
'subscribers');
next unless scalar @$subscribers;
eval {
send_email($event, $subscribers);
};
print $EVAL_ERROR if $EVAL_ERROR;
}
}
}
});
);
return;
}

@ -1,6 +1,8 @@
#!/usr/bin/perl
use strict;
use warnings;
use English;
use Getopt::Long;
use Pod::Usage;
@ -13,7 +15,7 @@ my $opts = {
verbose => 0,
};
GetOptions( $opts,
GetOptions($opts,
'help|h' => sub { usage() },
'customer_id=i',
'verbose',
@ -21,20 +23,25 @@ GetOptions( $opts,
sub check_params {
my @missing;
foreach my $param (@required) {
push @missing, $param unless $opts->{$param};
}
usage(join(' ', @missing)) if scalar @missing;
return;
}
sub usage {
my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
-verbose => 99,
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '',
);
pod2usage(
-exitval => $missing ? 1 : 0,
-verbose => 99,
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '',
);
return;
}
@ -46,8 +53,8 @@ sub main {
my $uri = '/api/customers/';
$uri .= $opts->{customer_id} ? $opts->{customer_id} : '';
my $res = $client->request('GET', $uri);
$res->is_success ? print $res->decoded_content."\n"
: print $res->result."\n";
$res->is_success ? print $res->decoded_content . "\n"
: print $res->result . "\n";
return !$res->is_success;
}

@ -1,6 +1,8 @@
#!/usr/bin/perl
use strict;
use warnings;
use English;
use Getopt::Long;
use Pod::Usage;
@ -13,7 +15,7 @@ my $opts = {
verbose => 0,
};
GetOptions( $opts,
GetOptions($opts,
'help|h' => sub { usage() },
'id=i',
'verbose',
@ -21,20 +23,25 @@ GetOptions( $opts,
sub check_params {
my @missing;
foreach my $param (@required) {
push @missing, $param unless $opts->{$param};
}
usage(join(' ', @missing)) if scalar @missing;
return;
}
sub usage {
my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
-verbose => 99,
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '',
);
pod2usage(
-exitval => $missing ? 1 : 0,
-verbose => 99,
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '',
);
return;
}
@ -46,8 +53,8 @@ sub main {
my $uri = '/api/soundsets/';
$uri .= $opts->{id} ? $opts->{id} : '';
my $res = $client->request('GET', $uri);
$res->is_success ? print $res->content."\n"
: print $res->result."\n";
$res->is_success ? print $res->content . "\n"
: print $res->result . "\n";
return !$res->is_success;
}

@ -1,6 +1,8 @@
#!/usr/bin/perl
use strict;
use warnings;
use English;
use Getopt::Long;
use Pod::Usage;
@ -13,7 +15,7 @@ my $opts = {
verbose => 0,
};
GetOptions( $opts,
GetOptions($opts,
'help|h' => sub { usage() },
'customer_id=i',
'verbose',
@ -21,20 +23,25 @@ GetOptions( $opts,
sub check_params {
my @missing;
foreach my $param (@required) {
push @missing, $param unless $opts->{$param};
}
usage(join(' ', @missing)) if scalar @missing;
return;
}
sub usage {
my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
-verbose => 99,
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '',
);
pod2usage(
-exitval => $missing ? 1 : 0,
-verbose => 99,
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '',
);
return;
}
@ -43,12 +50,16 @@ sub main {
my $client = NGCP::API::Client->new(verbose => $opts->{verbose});
my $uri = '/api/customers/'.$opts->{customer_id};
my $data = [ { op => 'replace',
path => '/status',
value => 'terminated' } ];
my $uri = '/api/customers/' . $opts->{customer_id};
my $data = [
{
op => 'replace',
path => '/status',
value => 'terminated',
},
];
my $res = $client->request('PATCH', $uri, $data);
print $res->result."\n";
print $res->result . "\n";
return !$res->is_success;
}

@ -1,6 +1,8 @@
#!/usr/bin/perl
use strict;
use warnings;
use English;
use Getopt::Long;
use Pod::Usage;
@ -13,7 +15,7 @@ my $opts = {
verbose => 0,
};
GetOptions( $opts,
GetOptions($opts,
'help|h' => sub { usage() },
'username=s',
'domain=s',
@ -22,20 +24,25 @@ GetOptions( $opts,
sub check_params {
my @missing;
foreach my $param (@required) {
push @missing, $param unless $opts->{$param};
}
usage(join(' ', @missing)) if scalar @missing;
return;
}
sub usage {
my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
-verbose => 99,
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '',
);
pod2usage(
-exitval => $missing ? 1 : 0,
-verbose => 99,
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '',
);
return;
}
@ -51,6 +58,7 @@ sub main {
my $sub_id;
if ($sub->as_hash->{total_count} == 1) {
my $tmp = $sub->as_hash->{_embedded}->{'ngcp:subscribers'};
if (ref $tmp eq 'ARRAY') {
$sub_id = @{$tmp}[0]->{id};
} else {
@ -60,12 +68,16 @@ sub main {
} else {
die "Subscriber $opts->{username}\@$opts->{domain} not found\n";
}
$uri = '/api/subscribers/'.$sub_id;
my $data = [ { op => 'replace',
path => '/status',
value => 'terminated' } ];
$uri = '/api/subscribers/' . $sub_id;
my $data = [
{
op => 'replace',
path => '/status',
value => 'terminated',
},
];
my $res = $client->request('PATCH', $uri, $data);
print $res->result."\n";
print $res->result . "\n";
return !$res->is_success;
}

Loading…
Cancel
Save