TT#68401 Deprecate acc-cdi.git for mr8.1+

Change-Id: I4e45270ed336e4e82075e93b7388e1cd507bda44
changes/54/34254/1
Manuel Montecelo 6 years ago
parent 4ecbe82a36
commit bf3e12e9ec

@ -0,0 +1,4 @@
Repository discontinued
-----------------------
The repository is for historical purposes only and not in use anymore.

@ -1,5 +0,0 @@
NGCP_KAMCTL = /usr/sbin/ngcp-kamctl
NGCP_CHK_ACT = /usr/sbin/ngcp-check-active -p
LOG_FILE = /var/log/ngcp/acc-cdi.log
LOGGING = 1
DEBUG = 0

@ -1,377 +0,0 @@
#!/usr/bin/perl -w
# vim set sw=4 ts=4 et noai
#----------------------------------------------------------------------
# Sipwise Development Team <support@sipwise.com>
#----------------------------------------------------------------------
## no critic
use strict;
our $VERSION = 1.0;
use DBI;
use Time::HiRes qw(gettimeofday);
use Date::Format qw(time2str);
use Data::Dumper;
#----------------------------------------------------------------------
BEGIN {
$SIG{TERM} = \&release_term;
$SIG{INT} = \&release_int;
$SIG{__DIE__} = \&ERROR;
}
my %CONFIG = ();
my $pid_file = '/var/run/ngcp-acc-cdi.pid';
my $config_file = '/etc/ngcp-acc-cdi/acc-cdi.conf';
my $dbcredentials = '/etc/mysql/sipwise_extra.cnf';
my $dbh;
my $ch = {};
my $dsn = "DBI:mysql:database=accounting;host=localhost;mysql_read_default_file=${dbcredentials}";
my %cnt = qw(updated 0 cleaned 0 finished 0 skipped 0);
# Read config
#----------------------------------------------------------------------
sub read_config {
open (my $config_fh, $config_file)
|| die "Can't open config file: $!";
while (<$config_fh>) {
chomp $_;
$_ =~ /^\s*(\S*)\s*=\s*(.+)$/;
next unless $1 && $2;
$CONFIG{$1} = $2;
}
close $config_fh;
# redirect out/err to the log file
if ($CONFIG{LOGGING}) {
open (STDOUT, ">>" . $CONFIG{LOG_FILE})
|| die "Can't open logfile: $!";
open (STDERR, ">>" . $CONFIG{LOG_FILE})
|| die "Can't open logfile: $!";
}
}
# Logging
#----------------------------------------------------------------------
sub INFO {
my $msg = shift;
return unless $msg;
chomp $msg;
my $time_s = '[' . time2str('%Y-%m-%d %T', time).']';
print $time_s .' '.$msg."\n";
}
sub DEBUG {
return unless $CONFIG{DEBUG};
INFO shift;
}
sub ERROR {
INFO shift;
$dbh->rollback if $dbh;
$dbh->disconnect if $dbh;
exit 1;
}
# Init/release
#----------------------------------------------------------------------
sub init {
read_config();
# check/create lock
if (-f $pid_file) {
open(my $pf_fh, $pid_file) || die "Can't open file: $!";
my $old_pid = <$pf_fh> || 0;
chomp $old_pid;
if ($old_pid && kill 0, $old_pid) {
INFO "Already running.";
exit 0;
} else {
DEBUG "Releasing stale lock $old_pid";
unlink $pid_file || DEBUG "Can't release old lock: $!";
}
}
open(my $pf_fh, '>'.$pid_file) || die "Can't create lock: $!";
print $pf_fh $$."\n";
INFO "Started.";
}
sub release_int {
DEBUG "-- Interrupted --";
release();
exit 1;
}
sub release_term {
DEBUG "-- Terminated --";
release();
exit 1;
}
sub release {
$dbh->disconnect if $dbh;
INFO sprintf(<<MSG, @{\%cnt}{qw(updated cleaned finished skipped)});
Done, marks updated %d cleaned %d, acc records finished %d stale %d
MSG
DEBUG "Releasing lock $$";
unlink $pid_file || warn "Can't release lock: $!";
}
# Check if the node is active
#----------------------------------------------------------------------
sub check_active {
open (my $active, $CONFIG{NGCP_CHK_ACT}." |")
|| die "Can't run $CONFIG{NGCP_CHK_ACT} : $!";
my $rc = <$active>;
chomp($rc);
return $rc eq '!' ? 1 : 0;
}
# Get active calls from kamailio
#----------------------------------------------------------------------
sub get_active_calls {
open(my $calls, $CONFIG{NGCP_KAMCTL}." proxy fifo dlg.list |")
|| die "Can't open kamctl: $!";
my @active_calls;;
while (<$calls>) {
chomp $_;
if ($_ =~ /call-id:\s+(\S+)$/) {
push @active_calls, $1;
}
}
close $calls;
return \@active_calls;
}
# Get start acc records (single INVITES with sip_reason = OK)
#----------------------------------------------------------------------
sub get_start_acc {
my $ch = $dbh->prepare(<<SQL)
SELECT a.method, a.from_tag, a.to_tag, a.callid,
a.sip_code, a.sip_reason,
a.time, a.time_hires,
a.dst_ouser, a.dst_domain, a.src_domain,
c.mark
FROM kamailio.acc a
LEFT JOIN acc_cdi c ON c.callid = a.callid
WHERE a.method = 'INVITE'
AND a.sip_reason = 'OK'
AND a.callid NOT IN
(SELECT b.callid
FROM kamailio.acc b
WHERE a.callid = b.callid
AND b.method != 'INVITE')
SQL
|| die "Can't prepare query: ".$DBI::errstr;
my $rc = $ch->execute() || die "Can't execute query: ".$DBI::errstr;
INFO sprintf("Fetched %d start acc records.", $rc);
my %start_acc = ();
while (my $row = $ch->fetchrow_hashref) {
$start_acc{$row->{callid}} = $row;
}
$ch->finish();
$dbh->commit;
die "Can't commit transaction: ".$DBI::errstr if $DBI::err;
return \%start_acc;
}
# Prepare sql statements that will be called repeatedly
#----------------------------------------------------------------------
sub prepare_statements {
$ch->{insert_mark} = $dbh->prepare(<<SQL)
INSERT INTO acc_cdi
(callid, mark)
VALUES
(?, ?)
SQL
|| die "Can't prepare query: ".$DBI::errstr;
$ch->{update_mark} = $dbh->prepare(<<SQL)
UPDATE acc_cdi
SET mark = ?
WHERE callid = ?
SQL
|| die "Can't prepare query: ".$DBI::errstr;
$ch->{delete_mark} = $dbh->prepare(<<SQL)
DELETE FROM acc_cdi
WHERE callid = ?
SQL
|| die "Can't prepare query: ".$DBI::errstr;
$ch->{finish_acc} = $dbh->prepare(<<SQL)
INSERT INTO kamailio.acc
(method, from_tag, to_tag, callid,
sip_code, sip_reason,
time, time_hires,
src_leg, dst_leg,
dst_ouser, dst_domain, src_domain)
VALUES
(?, ?, ?, ?, ?, '', '', ?, NOW(), ?, ?, ?, ?)
SQL
|| die "Can't prepare query: ".$DBI::errstr;
}
# Update marks in accounting.acc_cdi
#----------------------------------------------------------------------
sub update_mark {
my $acc = shift;
die "No acc passed into update_mark" unless ref $acc;
eval {
my $time_hires = scalar gettimeofday();
my $duration = $time_hires - $acc->{time_hires};
# already have the mark, update it
if ($acc->{mark}) {
DEBUG sprintf("Updating mark for callid: %s with duration: %d",
$acc->{callid}, $duration);
$ch->{update_mark}->execute($acc->{callid}, $time_hires)
|| die "Can't execute query: ".$DBI::errstr;
# insert a new intermediate mark record
} else {
DEBUG sprintf("Inserting mark for callid: %s with duration: %d",
$acc->{callid}, $duration);
$ch->{insert_mark}->execute($acc->{callid}, $time_hires)
|| die "Can't execute query: ".$DBI::errstr;
}
};
if ($@) {
ERROR $@;
}
$dbh->commit;
die "Can't commit transaction: ".$DBI::errstr if $DBI::err;
$cnt{updated}++;
}
# Finish acc records (create BYE for INVITES with marks but not active)
#----------------------------------------------------------------------
sub finish_acc {
my $acc = shift;
die "No acc passed into fisnih_acc" unless ref $acc;
my $duration = $acc->{mark} - $acc->{time_hires};
DEBUG sprintf("Finishing callid: %s with duration: %d",
$acc->{callid}, $duration);
eval {
$acc->{method} = 'BYE';
$acc->{sip_reason} = 'Interrupted';
$acc->{src_domain} = '127.0.0.1';
# create the BYE (mediator will do the rest)
$ch->{finish_acc}->execute(@{$acc}{qw(method from_tag to_tag
callid
sip_code sip_reason
mark
dst_ouser dst_domain
src_domain)
})
|| die "Can't execute query: ".$DBI::errstr;
# cleanup the related mark
$ch->{delete_mark}->execute($acc->{callid})
|| die "Can't execute query: ".$DBI::errstr;
};
if ($@) {
ERROR $@;
}
$dbh->commit;
die "Can't commit transaction: ".$DBI::errstr if $DBI::err;
$cnt{finished}++;
}
# Clean up marks for already normally completed calls
#----------------------------------------------------------------------
sub cleanup_marks {
eval {
$cnt{cleaned} = int $dbh->do(<<SQL);
DELETE FROM acc_cdi
WHERE callid NOT IN
(SELECT callid
FROM kamailio.acc)
SQL
die "Can't execute: ".$DBI::errstr if $DBI::err;
};
if ($@) {
ERROR $@;
}
$dbh->commit;
die "Can't commit transaction: ".$DBI::errstr if $DBI::err;
}
# Main (start) entry
#----------------------------------------------------------------------
sub main {
# only run on the active node
unless (check_active()) {
DEBUG "The node is not active... stopping.";
exit 0;
}
# db connect, with tx support for inserts/updates
$dbh = DBI->connect($dsn, "", "", { AutoCommit => 0 });
die "Can't connect to mysql: ".$DBI::errstr if $DBI::err;
# fetch start acc records, active calls for processing
my $start_acc = get_start_acc();
my $active_calls = get_active_calls();
prepare_statements();
#print Data::Dumper->Dumpxs([$start_acc]),"\n";
foreach my $callid (keys %$start_acc) {
# active call
if (grep /^$callid$/, @$active_calls) {
update_mark($start_acc->{$callid});
# inactive call but with a mark record
} elsif ($start_acc->{$callid}{mark}) {
finish_acc($start_acc->{$callid});
# inactive call w/o mark record = stale
} else {
$cnt{skipped}++;
}
}
# records in acc_cdi w/o any related acc records in kamailio.acc
# =normally finished calls by kamailio/mediator
cleanup_marks();
}
#----------------------------------------------------------------------
init();
main();
release();
exit 0;
# vim set sw=4 ts=4 et noai
__END__
NOTE: accounting.acc_cdi table is required for the script to operate properly.
normally covered by ngcp db schema.
CREATE TABLE `acc_cdi` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`callid` varchar(255) NOT NULL,
`mark` decimal(13,3) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `callid` (`callid`),
KEY `callid_idx` (`callid`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8

7
debian/.gitignore vendored

@ -1,7 +0,0 @@
*.debhelper
*.log
*.substvars
/.debhelper/
/debhelper-build-stamp
/files
/ngcp-acc-cdi/

241
debian/changelog vendored

@ -1,241 +0,0 @@
ngcp-acc-cdi (8.1.0.0+0~mr8.1.0.0) unstable; urgency=medium
* New release.
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Tue, 08 Oct 2019 09:04:44 +0200
ngcp-acc-cdi (8.0.0.0+0~mr8.0.0.0) unstable; urgency=medium
[ Guillem Jover ]
* [cdaadf5] TT#61954 Update copyright years
* [75ace01] TT#61954 Namespace debhelper fragment files
* [89c9854] TT#61954 Set debhelper compat level in Build-Depends instead of debian/compat
[ Sipwise Jenkins Builder ]
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Mon, 05 Aug 2019 20:51:26 +0200
ngcp-acc-cdi (7.5.0.0+0~mr7.5.0.0) unstable; urgency=medium
* New release.
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Mon, 17 Jun 2019 14:33:32 +0200
ngcp-acc-cdi (7.4.0.0+0~mr7.4.0.0) unstable; urgency=medium
* New release.
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Thu, 25 Apr 2019 14:25:18 +0200
ngcp-acc-cdi (7.3.0.0+0~mr7.3.0.0) unstable; urgency=medium
* New release.
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Mon, 25 Feb 2019 22:50:06 +0100
ngcp-acc-cdi (7.2.0.0+0~mr7.2.0.0) unstable; urgency=medium
* New release.
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Wed, 09 Jan 2019 21:53:56 +0100
ngcp-acc-cdi (7.1.0.0+0~mr7.1.0.0) unstable; urgency=medium
* New release.
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Mon, 12 Nov 2018 22:31:59 +0100
ngcp-acc-cdi (7.0.0.0+0~mr7.0.0.0) unstable; urgency=medium
* New release.
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Mon, 24 Sep 2018 18:50:53 +0200
ngcp-acc-cdi (6.5.0.0+0~mr6.5.0.0) unstable; urgency=medium
* New release.
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Tue, 24 Jul 2018 13:31:45 +0200
ngcp-acc-cdi (6.4.0.0+0~mr6.4.0.0) unstable; urgency=medium
[ Guillem Jover ]
* [5910752] TT#36351 Use modern ngcp-check-active
[ Sipwise Jenkins Builder ]
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Tue, 29 May 2018 10:01:14 +0200
ngcp-acc-cdi (6.3.0.0+0~mr6.3.0.0) unstable; urgency=medium
[ Marco Capetta ]
* [df6156d] TT#33867 Update ngcp-kamctl format to the one used in kamailio 5.1.2
[ Alexander Lutay ]
* [ff8c5ce] TT#33867 Perform 'wrap-and-sort -sat'
[ Sipwise Jenkins Builder ]
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Tue, 03 Apr 2018 22:25:16 +0200
ngcp-acc-cdi (6.2.0.0+0~mr6.2.0.0) unstable; urgency=medium
* New release.
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Mon, 29 Jan 2018 21:51:04 +0100
ngcp-acc-cdi (6.1.0.0+0~mr6.1.0.0) unstable; urgency=medium
[ Guillem Jover ]
* [be87bb0] TT#22072 Update packaging
* [34b58ef] TT#22072 Update packaging
[ Sipwise Jenkins Builder ]
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Tue, 05 Dec 2017 23:58:46 +0100
ngcp-acc-cdi (6.0.0.0+0~mr6.0.0.0) unstable; urgency=medium
* New release.
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Mon, 02 Oct 2017 23:35:47 +0200
ngcp-acc-cdi (5.5.0.0+0~mr5.5.0.0) unstable; urgency=medium
* New release.
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Mon, 17 Jul 2017 22:40:58 +0200
ngcp-acc-cdi (5.4.0.0+0~mr5.4.0.0) unstable; urgency=medium
[ Guillem Jover ]
* [8a3f5f2] TT#5420 Update packaging
[ Sipwise Jenkins Builder ]
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Tue, 16 May 2017 21:29:22 +0200
ngcp-acc-cdi (5.3.0.0+0~mr5.3.0.0) unstable; urgency=medium
* New release.
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Wed, 22 Mar 2017 10:45:20 +0100
ngcp-acc-cdi (5.2.0.0+0~mr5.2.0.0) unstable; urgency=medium
* New release.
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Fri, 03 Feb 2017 00:26:25 +0100
ngcp-acc-cdi (5.1.0.0+0~mr5.1.0.0) unstable; urgency=medium
* New release.
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Thu, 17 Nov 2016 23:07:24 +0100
ngcp-acc-cdi (5.0.0.0+0~mr5.0.0.0) unstable; urgency=medium
[ Guillem Jover ]
* [9aec03b] MT#20479 Fix dependencies
-- Alexander Lutay <alutay@sipwise.com> Fri, 21 Oct 2016 14:13:55 +0200
ngcp-acc-cdi (1.12.0.0+0~mr4.5.0.0) unstable; urgency=medium
* New release.
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Mon, 23 May 2016 18:35:13 +0200
ngcp-acc-cdi (1.11.0.0+0~mr4.4.0.0) unstable; urgency=medium
[ Guillem Jover ]
* [3925b71] MT#16473 Convert debian/copyright to machine-readable format
[ Michael Prokop ]
* [a6a1be0] MT#17699 Bump Standards-Version to 3.9.7
[ Sipwise Jenkins Builder ]
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Mon, 21 Mar 2016 22:04:48 +0100
ngcp-acc-cdi (1.10.0.0+0~mr4.3.0.0) unstable; urgency=medium
* New release.
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Wed, 16 Dec 2015 08:59:51 +0100
ngcp-acc-cdi (1.9.0.0+0~mr4.2.0.0) unstable; urgency=medium
* New release.
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Mon, 12 Oct 2015 15:13:46 +0200
ngcp-acc-cdi (1.8.0.0+0~mr4.1.0.0) unstable; urgency=low
[ Kirill Solomko ]
* [9be16fc] perl no critic
[ Michael Prokop ]
* [fe2a9c1] MT#7505 Add .gitreview file for acc-cdi
[ Sipwise Jenkins Builder ]
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Mon, 13 Jul 2015 15:00:08 +0200
ngcp-acc-cdi (1.7.0.0+0~mr4.0.0.0) unstable; urgency=low
[ Michael Prokop ]
* [4d1a621] MT#9127 Bump Standards-Version to 3.9.6
[ Sipwise Jenkins Builder ]
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Wed, 18 Mar 2015 13:40:42 +0100
ngcp-acc-cdi (1.6.0.0+0~mr3.8.0.0) unstable; urgency=low
* New release.
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Wed, 07 Jan 2015 21:14:14 +0100
ngcp-acc-cdi (1.5.0.0+0~mr3.7.0.0) unstable; urgency=low
* New release.
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Thu, 30 Oct 2014 17:10:06 +0100
ngcp-acc-cdi (1.4.0.0+0~mr3.6.0.0) unstable; urgency=low
* New release.
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Thu, 09 Oct 2014 16:15:58 +0200
ngcp-acc-cdi (1.3.0.0+0~mr3.5.0.0) unstable; urgency=low
* New release.
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Thu, 10 Jul 2014 15:15:46 +0200
ngcp-acc-cdi (1.2.0.0+0~mr3.4.0.0) unstable; urgency=low
[ Alexander Lutay ]
* [6258386] MT#6191 Fixed building warning extended-description-is-empty
[ Michael Prokop ]
* [8f164da] MT#6511 Bump Standards-Version to 3.9.5
[ Sipwise Jenkins Builder ]
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Mon, 26 May 2014 15:32:42 +0200
ngcp-acc-cdi (1.1.0.0+0~mr3.3.0.0) unstable; urgency=low
* New release.
-- Sipwise Jenkins Builder <jenkins@sipwise.com> Fri, 21 Mar 2014 13:07:05 +0100
ngcp-acc-cdi (1.0.0) unstable; urgency=low
* Initial release.
-- Kirill Solomko <ksolomko@sipwise.com> Fri, 07 Mar 2014 13:31:01 +0100

20
debian/control vendored

@ -1,20 +0,0 @@
Source: ngcp-acc-cdi
Section: utils
Priority: optional
Maintainer: Sipwise Development Team <support@sipwise.com>
Build-Depends:
debhelper-compat (= 12),
Standards-Version: 3.9.8
Homepage: https://www.sipwise.com/
Package: ngcp-acc-cdi
Architecture: all
Depends:
libclass-dbi-mysql-perl,
${misc:Depends},
${perl:Depends},
Description: NGCP component to reduce amount of "lost" calls
A component for NGCP that provides a failsafe mechanism to reduce amount
of "lost" calls in case of unexpected system crashes. Creates intermediate
records for ongoing calls based on acc start (INVITE) records and fixes
"lost" calls based on last intermediate time.

23
debian/copyright vendored

@ -1,23 +0,0 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Source: https://www.sipwise.com/
Upstream-Contact: Sipwise Development Team <support@sipwise.com>
Files: *
Copyright:
Copyright © 2007-2019 Sipwise GmbH, Austria
License: GPL-3+
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Comment:
On Debian systems, the full text of the GNU General Public License
version 3 can be found in the file '/usr/share/common-licenses/GPL-3'.

@ -1 +0,0 @@
* * * * * root /usr/sbin/ngcp-acc-cdi >/dev/null

@ -1 +0,0 @@
usr/sbin

@ -1 +0,0 @@
acc-cdi.conf etc/ngcp-acc-cdi/

15
debian/rules vendored

@ -1,15 +0,0 @@
#!/usr/bin/make -f
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
D = debian/ngcp-acc-cdi
%:
dh $@
override_dh_install:
install -m 755 acc-cdi.pl $(D)/usr/sbin/ngcp-acc-cdi
dh_install
.PHONY: override_dh_install

@ -1 +0,0 @@
3.0 (native)
Loading…
Cancel
Save