some tweaks to make perlcritic happy; mantis:1579

changes/49/3949/1
Christian Veigl 13 years ago committed by Kirill Solomko
parent 72f52d497f
commit 24923afc9d

@ -1,11 +1,14 @@
#!/usr/bin/perl -w #!/usr/bin/perl -w
use strict; use strict;
use warnings;
use Email::Sender::Simple qw(sendmail);
use XML::Simple; use XML::Simple;
use Sipwise::DB; use Sipwise::DB;
use Sipwise::Provisioning::Config;
my $CONF = '/etc/ngcp-ossbss/provisioning.conf'; my $MTA = '/usr/sbin/sendmail -oi -t';
my $MAIL = '/usr/sbin/sendmail -oi -t';
sub main; sub main;
@ -13,9 +16,9 @@ main;
sub main { sub main {
my $xs = new XML::Simple; my $xs = new XML::Simple;
my $conf = $xs->XMLin( $CONF, ForceArray => 0 ); my $conf = Sipwise::Provisioning::Config->new()->get_config();
my $db = new Sipwise::DB ( $$conf{billingdb} ); my $db = new Sipwise::DB ( $$conf{billingdb} );
$$conf{credit_warnings} = [ $$conf{credit_warnings} ] $$conf{credit_warnings} = [ $$conf{credit_warnings} ]
if defined eval { %{$$conf{credit_warnings}} }; if defined eval { %{$$conf{credit_warnings}} };
@ -34,19 +37,25 @@ sub main {
AND a.cash_balance < ? AND a.cash_balance < ?
GROUP BY contract_id GROUP BY contract_id
", $$domcfg{domain}, $$domcfg{threshold}); ", $$domcfg{domain}, $$domcfg{threshold});
if(@$contracts) { if(@$contracts) {
$$domcfg{recipients} = [ $$domcfg{recipients} ] $$domcfg{recipients} = [ $$domcfg{recipients} ]
unless defined eval { @{$$domcfg{recipients}} }; unless defined eval { @{$$domcfg{recipients}} };
my $mailtxt = "To: ". join(', ', @{$$domcfg{recipients}}) ."\nSubject: Sipwise NGCP credit threshold notification\n\n";
my $mailtxt;
$mailtxt .= "Credit threshold warning for: $$domcfg{domain}\nThe following contracts are below the configured threshold of $$domcfg{threshold} cent:\n\n"; $mailtxt .= "Credit threshold warning for: $$domcfg{domain}\nThe following contracts are below the configured threshold of $$domcfg{threshold} cent:\n\n";
$mailtxt .= "account_id\tcash_balance\tcash_balance_interval\tsubscribers\n"; $mailtxt .= "account_id\tcash_balance\tcash_balance_interval\tsubscribers\n";
for(@$contracts) { for(@$contracts) {
$mailtxt .= "$$_{contract_id}\t$$_{cash_balance}\t$$_{cash_balance_interval}\t$$_{subscribers}\n"; $mailtxt .= "$$_{contract_id}\t$$_{cash_balance}\t$$_{cash_balance_interval}\t$$_{subscribers}\n";
} }
open MAIL, "|$MAIL" or die $!;
print MAIL $mailtxt; sendmail ( Email::Simple->create(
close MAIL; header => [
To => join(', ', @{$$domcfg{recipients}}),
From => $$conf{adminmail},
Subject => 'Sipwise NGCP credit threshold notification',
],
body => $mailtxt,
));
} }
} }
} }

@ -2,6 +2,8 @@
use strict; use strict;
use warnings; use warnings;
use Email::Sender::Simple qw(sendmail);
use Sipwise::Provisioning::Billing; use Sipwise::Provisioning::Billing;
my %LOCK = ( my %LOCK = (
@ -17,6 +19,8 @@ my %LOCK = (
4 => 'global', 4 => 'global',
); );
my $conf = Sipwise::Provisioning::Config->new()->get_config();
my $o = Sipwise::Provisioning::Billing->new(); my $o = Sipwise::Provisioning::Billing->new();
my $db = $o->{database}; my $db = $o->{database};
@ -58,38 +62,36 @@ for my $e (@$a) {
my $cur = sprintf('%.2f', $e->{cash_balance_interval} / 100); my $cur = sprintf('%.2f', $e->{cash_balance_interval} / 100);
my $max = sprintf('%.2f', $e->{fraud_interval_limit} / 100); my $max = sprintf('%.2f', $e->{fraud_interval_limit} / 100);
open(SM, '| sendmail -oi -t'); my $body;
my $text = $e->{fraud_interval_lock} ? << "!" if ($e->{fraud_interval_lock}) {
To: $e->{fraud_interval_notify} $body = "Account ID " . $e->{id} . " has been locked due to exceeding the configured" . "\n"
Subject: Account ID $e->{id} locked by fraud detection . "credit balance threshold ($cur >= $max ).\n\n";
}
Account ID $e->{id} has been locked due to exceeding the configured else {
credit balance threshold ($cur >= $max). $body = "Account ID " . $e->{id} . " is currently exceeding the configured credit balance" . "\n"
. "threshold ($cur >= $max), but has not been locked due to configuration.\n\n";
! }
: <<"!";
To: $e->{fraud_interval_notify}
Subject: Account ID $e->{id} exceeding fraud detection limit
Account ID $e->{id} is currently exceeding the configured credit balance
threshold ($cur >= $max), but has not been locked due to configuration.
!
print SM $text;
if (!$subs || !@$subs) { if (!$subs || !@$subs) {
print SM "There are no affected subscribers.\n"; $body .= "There are no affected subscribers.\n";
} }
else { else {
print SM "Affected subscribers:\n"; $body .= "Affected subscribers:\n";
for my $s (@$subs) { for my $s (@$subs) {
print SM "\t$s->{username}\@$s->{domain}". $body .= "\t$s->{username}\@$s->{domain}".
($s->{external_id} ? " (external ID '$s->{external_id}')" ($s->{external_id} ? " (external ID '$s->{external_id}')"
: '') . "\n"; : '') . "\n";
} }
} }
close(SM); sendmail ( Email::Simple->create(
header => [
To => $e->{fraud_interval_notify},
From => $$conf{adminmail},
Subject => 'Account ID ' . $e->{id} . 'locked by fraud detection',
],
body => $body,
));
} }
1; 1;

Loading…
Cancel
Save