* updated to version 0.2

* new config file /etc/cdr-exporter.conf
* Remove etc/default and init.d script file
* The script now reads the configuration by itself
trunk@3605
Jon Bonilla 16 years ago
parent 14353f95ee
commit 0c62eccd15

@ -0,0 +1,10 @@
DBHOST=127.0.0.1
DBUSER=exporter
DBPASS=1exportTheCDRs!
DBDB=accounting
CDRDIR=/home/cdr
PREFIX=sipwise
VERSION=001

@ -7,43 +7,37 @@ use DBI;
use Getopt::Long;
use Digest::MD5;
my %CONF;
{
my $res = GetOptions(
"help" => \$CONF{help},
"h=s" => \$CONF{host},
"P=i" => \$CONF{port},
"u=s" => \$CONF{user},
"p=s" => \$CONF{pass},
"d=s" => \$CONF{db},
"t=s" => \$CONF{target},
"f=s" => \$CONF{prefix},
"v=s" => \$CONF{version},
);
if (!$res || $CONF{help}) {
print("Usage: $0 { --help | [-h HOSTNAME] [-P PORT] [-u USERNAME] [-p PASSWORD]\n");
print(" -d DATABASE -t TARGETPATH -f PREFIX -v VERSION }\n");
print("Example: $0 -d accounting -t /tmp/acc.$$ -f sipwise -v 001\n");
exit($res ? 0 : 1);
}
for my $k (qw(db target prefix version)) {
if (!defined($CONF{$k})) {
print("Missing argument \"$k\", see $0 --help\n");
exit(1);
}
}
our $DBHOST;
our $DBUSER;
our $DBPASS;
our $DBDB;
our $CDRDIR;
our $PREFIX;
our $VERSION;
my $config_file = "/etc/cdr-exporter.conf";
open CONFIG, "$config_file" or die "Program stopping, couldn't open the configuration file '$config_file'.\n";
while (<CONFIG>) {
chomp; # no newline
s/#.*//; # no comments
s/^\s+//; # no leading white
s/\s+$//; # no trailing white
next unless length; # anything left?
my ($var, $value) = split(/\s*=\s*/, $_, 2);
no strict 'refs';
$$var = $value;
}
close CONFIG;
-d $CONF{target} or die("Target directory $CONF{target} doesn't exist, stop");
$0 = "$0"; # hide command line with password
my $DBH = DBI->connect("dbi:mysql:$CONF{db}" . ($CONF{host} ? ";host=$CONF{host}" : ""), $CONF{user} || $ENV{USER} || undef, $CONF{pass}) or die("DB connect failed, stop");
my $DBH = DBI->connect("dbi:mysql:$DBDB;host=$DBHOST", $DBUSER, $DBPASS);
print("+++ Start run with DB " . ($CONF{user} || "(undef)") . "\@$CONF{db} to $CONF{prefix}\n");
$DBH or return 0;
print("+++ Start run with DB " . ($DBUSER || "(undef)") . "\@$DBDB to $PREFIX\n");
my $COLLID = "exporter";
my %MARKS; # last id etc
@ -111,8 +105,8 @@ my @NOW = localtime($NOW);
unshift(@F, sprintf('%04i', $num));
$MARKS{lastseq}++;
my $fn = sprintf('%s/%s_%s_%s_%010i.cdr', $CONF{target}, $CONF{prefix}, $CONF{version}, $ts, $MARKS{lastseq});
my $tfn = sprintf('%s/%s_%s_%s_%010i.cdr.'.$$, $CONF{target}, $CONF{prefix}, $CONF{version}, $ts, $MARKS{lastseq});
my $fn = sprintf('%s/%s_%s_%s_%010i.cdr', $CDRDIR, $PREFIX, $VERSION, $ts, $MARKS{lastseq});
my $tfn = sprintf('%s/%s_%s_%s_%010i.cdr.'.$$, $CDRDIR, $PREFIX, $VERSION, $ts, $MARKS{lastseq});
my $fd;
open($fd, ">", $tfn) or die("failed to open tmp-file $tfn ($!), stop");
my $ctx = Digest::MD5->new;

@ -1,11 +0,0 @@
DBHOST="127.0.0.1"
DBPORT="3306"
DBUSER="exporter"
DBPASS="1exportTheCDRs!"
DBDB="accounting"
CDRDIR="/tmp/cdr"
PREFIX="sipwise"
VERSION="001"

@ -1,21 +0,0 @@
#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
case $(dirname $0) in
/*) FULLPATH=$(dirname $0);;
*) FULLPATH=$(pwd)/$(dirname $0);;
esac
DAEMON=/usr/sbin/cdr-exporter
DEFAULTS=/etc/default/cdr-exporter
test -f $DAEMON || exit 0
# Load startup options if available
if [ -f $DEFAULTS ]; then
. $DEFAULTS || true
fi
$DAEMON -h $DBHOST -P $DBPORT -u $DBUSER -p $DBPASS -d $DBDB \
-t $CDRDIR -f $PREFIX -v $VERSION

7
debian/changelog vendored

@ -1,3 +1,10 @@
sipwise-cdr-exporter (0.2.0) unstable; urgency=low
* Read the configuration from the script itself
* Remove init script and etc/default file
-- Jon Bonilla <jbonilla@sipwise.com> Fri, 16 Apr 2010 12:03:01 +0200
sipwise-cdr-exporter (0.1.0) unstable; urgency=low
* Initial release.

5
debian/rules vendored

@ -27,11 +27,12 @@ install: build
dh_testdir
dh_testroot
dh_clean -k
dh_installdirs usr/sbin etc/cron.d
dh_installdirs usr/sbin etc/cron.d etc
install -m 755 cdr-exporter.pl debian/sipwise-cdr-exporter/usr/sbin/cdr-exporter
install -m 755 cdr-md5.sh debian/sipwise-cdr-exporter/usr/sbin/cdr-md5
install -m 644 cdr-exporter.cron debian/sipwise-cdr-exporter/etc/cron.d/cdr-exporter
install -m 644 cdr-exporter.conf debian/sipwise-cdr-exporter/etc/cdr-exporter.conf
# Build architecture-dependent files here.
binary-arch: build install
@ -45,7 +46,7 @@ binary-indep: build install
dh_installdocs
dh_installexamples
#dh_installman docs/rate-o-mat.8
dh_installinit --name=cdr-exporter
# dh_installinit --name=cdr-exporter
dh_link
dh_strip
dh_compress

Loading…
Cancel
Save