sipvoipopensips

How can do accounting manually in opensips


I am using Opensips 2.3 and already doing accounting. But I have a very different database, where I already configure to do missing/channel exceed CDRS manually using avp_db.

Is there a way to do accounting for a call established, as in automatic it is doing all accounting in acc table, but it is also doing established, missing and busy calls same way, but I want to do only established calls CDRS. For an automatic account, I am using following acc commands

loadmodule "acc.so"
modparam("acc", "early_media", 0)
modparam("acc", "report_cancels", 0) 
modparam("acc", "detect_direction",0)
modparam("acc", "extra_fields", "db: a->caller_id; b->callee_id") #Extra Data

and in routing section I have put following script

if (is_method("BYE")) {
    $acc_extra(a) = $fu;
    $acc_extra(b) = $tu;
    do_accounting("db","failed");

I just want that where call actually terminate, then I already have $avp(timestart) value so I can just deduct and calculate payments and use avp_db to insert CDRS


Solution

  • Using OpenSIPS 2.2+, you can enable accounting only for established calls (200 OK + (endpoint BYE, dialog expiry or forced ending)) by specifying the cdr option of do_accounting() upon receiving the initial INVITE:

    route {
    
        if (has_totag()) {
            ...
            exit;
        }
    
        ...
    
        if (is_method("INVITE"))
            do_accounting("db", "cdr");
    
        ...
    
        t_relay();
    }