|
|
@ -1,6 +1,8 @@
|
|
|
|
#!/usr/bin/perl
|
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
|
|
|
|
use English;
|
|
|
|
use English;
|
|
|
|
use Getopt::Long;
|
|
|
|
use Getopt::Long;
|
|
|
|
use Pod::Usage;
|
|
|
|
use Pod::Usage;
|
|
|
@ -48,19 +50,24 @@ sub DESTROY {
|
|
|
|
|
|
|
|
|
|
|
|
sub check_params {
|
|
|
|
sub check_params {
|
|
|
|
my @missing;
|
|
|
|
my @missing;
|
|
|
|
|
|
|
|
|
|
|
|
foreach my $param (@required) {
|
|
|
|
foreach my $param (@required) {
|
|
|
|
push @missing, $param unless $opts->{$param};
|
|
|
|
push @missing, $param unless $opts->{$param};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
usage(join(' ', @missing)) if scalar @missing;
|
|
|
|
usage(join(' ', @missing)) if scalar @missing;
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub usage {
|
|
|
|
sub usage {
|
|
|
|
my $missing = shift;
|
|
|
|
my $missing = shift;
|
|
|
|
pod2usage(-exitval => $missing ? 1 : 0,
|
|
|
|
|
|
|
|
|
|
|
|
pod2usage(
|
|
|
|
|
|
|
|
-exitval => $missing ? 1 : 0,
|
|
|
|
-verbose => 1,
|
|
|
|
-verbose => 1,
|
|
|
|
-message => $missing ? "Missing parameters: $missing" : '',
|
|
|
|
-message => $missing ? "Missing parameters: $missing" : '',
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -85,9 +92,9 @@ sub get_data {
|
|
|
|
my $res_hash = $res->as_hash;
|
|
|
|
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) {
|
|
|
|
if ('ARRAY' eq ref $data) {
|
|
|
|
push(@result,@$data);
|
|
|
|
push @result, @{$data};
|
|
|
|
} elsif ($data) {
|
|
|
|
} elsif ($data) {
|
|
|
|
push(@result,$data);
|
|
|
|
push @result, $data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (defined $code and 'CODE' eq ref $code) {
|
|
|
|
if (defined $code and 'CODE' eq ref $code) {
|
|
|
|
$code->(\@result);
|
|
|
|
$code->(\@result);
|
|
|
@ -99,6 +106,7 @@ sub get_data {
|
|
|
|
|
|
|
|
|
|
|
|
sub get_email_template {
|
|
|
|
sub get_email_template {
|
|
|
|
my $event = shift;
|
|
|
|
my $event = shift;
|
|
|
|
|
|
|
|
|
|
|
|
my $lock_type = $event->{interval_lock} ? 'lock' : 'warning';
|
|
|
|
my $lock_type = $event->{interval_lock} ? 'lock' : 'warning';
|
|
|
|
my $reseller_id = $event->{reseller_id};
|
|
|
|
my $reseller_id = $event->{reseller_id};
|
|
|
|
my @templates_data = ();
|
|
|
|
my @templates_data = ();
|
|
|
@ -130,7 +138,8 @@ sub send_email {
|
|
|
|
|
|
|
|
|
|
|
|
my $template = get_email_template($event);
|
|
|
|
my $template = get_email_template($event);
|
|
|
|
|
|
|
|
|
|
|
|
my $vars = { adminmail => $config->{adminmail},
|
|
|
|
my $vars = {
|
|
|
|
|
|
|
|
adminmail => $config->{adminmail},
|
|
|
|
customer_id => $event->{contract_id},
|
|
|
|
customer_id => $event->{contract_id},
|
|
|
|
interval => $event->{interval},
|
|
|
|
interval => $event->{interval},
|
|
|
|
interval_cost => sprintf('%.2f', $event->{interval_cost} / 100),
|
|
|
|
interval_cost => sprintf('%.2f', $event->{interval_cost} / 100),
|
|
|
@ -143,7 +152,8 @@ sub send_email {
|
|
|
|
$vars->{subscribers} .= sprintf "%s\@%s %s\n",
|
|
|
|
$vars->{subscribers} .= sprintf "%s\@%s %s\n",
|
|
|
|
@{$subscriber}{qw(username domain)},
|
|
|
|
@{$subscriber}{qw(username domain)},
|
|
|
|
$subscriber->{external_id}
|
|
|
|
$subscriber->{external_id}
|
|
|
|
? '('.$subscriber->{external_id}.')' : '';
|
|
|
|
? '(' . $subscriber->{external_id} . ')'
|
|
|
|
|
|
|
|
: '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
my $tt = Template->new();
|
|
|
|
my $tt = Template->new();
|
|
|
@ -184,19 +194,25 @@ sub update_notify_status {
|
|
|
|
|
|
|
|
|
|
|
|
my $now = strftime('%Y-%m-%d %H:%M:%S', localtime);
|
|
|
|
my $now = strftime('%Y-%m-%d %H:%M:%S', localtime);
|
|
|
|
my $uri = '/api/customerfraudevents/' . $event->{id};
|
|
|
|
my $uri = '/api/customerfraudevents/' . $event->{id};
|
|
|
|
my $data = [ { op => 'replace',
|
|
|
|
my $data = [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
op => 'replace',
|
|
|
|
path => '/notify_status',
|
|
|
|
path => '/notify_status',
|
|
|
|
value => 'notified' },
|
|
|
|
value => 'notified',
|
|
|
|
{ op => 'replace',
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
op => 'replace',
|
|
|
|
path => '/notified_at',
|
|
|
|
path => '/notified_at',
|
|
|
|
value => $now } ];
|
|
|
|
value => $now,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
my $res = $client->request('PATCH', $uri, $data);
|
|
|
|
my $res = $client->request('PATCH', $uri, $data);
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub main {
|
|
|
|
sub main {
|
|
|
|
|
|
|
|
|
|
|
|
if (my $num = $pf->running) {
|
|
|
|
if (my $num = $pf->running) {
|
|
|
|
print "$PROGRAM_BASE is already running.\n";
|
|
|
|
print "$PROGRAM_BASE is already running.\n";
|
|
|
|
$retcode = 1;
|
|
|
|
$retcode = 1;
|
|
|
@ -207,8 +223,11 @@ sub main {
|
|
|
|
|
|
|
|
|
|
|
|
check_params();
|
|
|
|
check_params();
|
|
|
|
load_config();
|
|
|
|
load_config();
|
|
|
|
|
|
|
|
|
|
|
|
get_data(
|
|
|
|
get_data(
|
|
|
|
sprintf('/api/customerfraudevents/?no_count=true¬ify_status=%s','new'),'customerfraudevents', sub {
|
|
|
|
sprintf('/api/customerfraudevents/?no_count=true¬ify_status=%s', 'new'),
|
|
|
|
|
|
|
|
'customerfraudevents',
|
|
|
|
|
|
|
|
sub {
|
|
|
|
my $events = shift;
|
|
|
|
my $events = shift;
|
|
|
|
foreach my $event (@{$events}) {
|
|
|
|
foreach my $event (@{$events}) {
|
|
|
|
if ($event->{interval_notify}) {
|
|
|
|
if ($event->{interval_notify}) {
|
|
|
@ -222,7 +241,8 @@ sub main {
|
|
|
|
print $EVAL_ERROR if $EVAL_ERROR;
|
|
|
|
print $EVAL_ERROR if $EVAL_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|