[freeside-users] Using FS::cdr

olima at SDF.ORG olima at SDF.ORG
Tue Aug 30 10:42:58 PDT 2016


> Hi,
>
> I'm using freeside 4.1 (4.1-20160805) installed via Debian's (jessie)
> packages, followed the documentation for the installation, so everything
> is supposed to be at the right place and pretty standard
> (perl v5.22.1, postgresql
> 9.4.9-0+deb8u1, libdbd-pg-perl 3.4.2-1
>
> So far, I'm really happy with my installation, I've finally managed to
> automatize the pulling of CDRs from the various SIP trunks I'm connected
> to,and pushing of the data into Freeside, finally getting invoices
> generated for our customers.
>
> The final hurdle I need to overcome is the handling of premium services
> numbers.
> In France, most of these numbers are behind the 08 prefix, thing is, every
> destination has more or less its own tarif therefore it is impossible to
> group them in the freeside.rate_prefix and freeside.rate_detail tables.
> Also, as a provider is forbidden to make a profit on this kind of calls, I
> only  need to pass the cost of the call directly to the customer,
> and, I happen to have it within my CDRs.
>
> I've looked at the code, and if I'm not wrong I can't use Freeside's
> importing function to have let's say the upstream price recorded as the
> rated_cost.
> For example, importing using the Simple2 format would only populate the
> upstream_price field.
> The only way to do it properly would be to inject these kind of CDRs using
> FS::cdr.
>
> Now, after breaking a CDR into a hash table, and trying to create a record
> object, I'm getting the following error:
>    Can't call method "table" on an undefined value at
>    /usr/share/perl5/FS/Record.pm line 3459.
>
> I've followed the documentation at
> http://www.freeside.biz/mediawiki/index.php/Freeside:3:Documentation:Developer/FS/cdr,
> can't manage to find what's wrong.
> Are there required fields in the hash table that represents the CDR ?
>

Right, I had a look at freeside-setup and randomly stumbled on
http://www.freeside.biz/mediawiki/index.php/Freeside:3:Documentation:Developer/FS#Notes
and realised I've been a silly sausage.

So, I've loaded the following modules:

    use FS::CurrentUser;
    use FS::Schema qw(dbdef dbdef_dist reload_dbdef );
    use FS::UID qw(adminsuidsetup datasrc checkeuid getsecrets);
    use FS::Conf;
    use FS::Pony;
    use FS::cdr;

Called getsecrets() then loaded the DbSchema at
/usr/local/etc/freeside/dbdef.DBI:Pg:dbname=freeside as following:
    $dbdef = reload_dbdef DBSCHEMA;
    $dbdef = dbdef;
    $dbdef_dist = dbdef_dist;

Created a record: my $record  = new FS::cdr {
            "acctid" => $acctid,
            "calldate" => $start,
            "clid" => $clid,
            "src" => $src,
            "dst" => $dst,
            "dcontext" => "Numero Special",
            "channel" => $dstchannel,
            "startdate" => $start,
            "answerdate" => $start,
            "enddate" => $end,
            "duration" => $duration,
            "billsec" => $duration,
            "disposition" => "ANSWER",
            "amaflags" => "BILL",
            "accountcode" => 0,
            "rated_price" => $price,
            "freesidestatus" => "rated" };

I end up with the following error: Can't call method "prepare" on an
undefined value at /usr/share/perl5/FS/Record.pm line 469.

Checking at $statement, I can see that a variable part of the Pg statement
is missing, related to FS::conf. That's where I will be needing more help.
>From the doc, I can see how to create a new object for this class, but I'm
not sure if that means I will have to rewrite stuff in database.

Quite frankly, I've sorted my issue by writing a CSV file using the
Simple2 format, take advantage of the upstream_price record, push that
thing to freeside and do several UPDATEs in freeside.cdr so everything is
fine and dandy.

Yet, I'd like to know how to do that thing the right way.

Cheers,
-- 
Asega



More information about the freeside-users mailing list