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
use strict;
use warnings;
use Email::Sender::Simple qw(sendmail);
use XML::Simple;
use Sipwise::DB;
use Sipwise::Provisioning::Config;
my $CONF = '/etc/ngcp-ossbss/provisioning.conf';
my $MAIL = '/usr/sbin/sendmail -oi -t';
my $MTA = '/usr/sbin/sendmail -oi -t';
sub main;
@ -13,9 +16,9 @@ main;
sub main {
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} );
$$conf{credit_warnings} = [ $$conf{credit_warnings} ]
if defined eval { %{$$conf{credit_warnings}} };
@ -34,19 +37,25 @@ sub main {
AND a.cash_balance < ?
GROUP BY contract_id
", $$domcfg{domain}, $$domcfg{threshold});
if(@$contracts) {
$$domcfg{recipients} = [ $$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 .= "account_id\tcash_balance\tcash_balance_interval\tsubscribers\n";
for(@$contracts) {
$mailtxt .= "$$_{contract_id}\t$$_{cash_balance}\t$$_{cash_balance_interval}\t$$_{subscribers}\n";
}
open MAIL, "|$MAIL" or die $!;
print MAIL $mailtxt;
close MAIL;
sendmail ( Email::Simple->create(
header => [
To => join(', ', @{$$domcfg{recipients}}),
From => $$conf{adminmail},
Subject => 'Sipwise NGCP credit threshold notification',
],
body => $mailtxt,
));
}
}
}

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

Loading…
Cancel
Save